1

好的,我正在处理一个菜单,它的工作原理是每 3 秒出现一个新选项,但我正在努力做到这一点,以便在 3 秒内我可以按下按钮来激活某些东西,现在看这里:

dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");
if (Key_Down(0, 0x02)) {
  dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");
  Sleep(1000);
  dvar(-1, 0, "c \"^43\"");
  Sleep(1000);
  dvar(-1, 0, "c \"2\"");
  Sleep(1000);
  dvar(-1, 0, "c \"^41\"");
  Sleep(1000);
}
Sleep(3000);

上面的问题是在“Set prestige one”之后它跳到下一个 Sleep(3000) 和下一个选项,现在我需要找到一种方法,以便能够在 3 秒内仍然使用该 if 语句女巫是一个按钮,而不是它休眠线程并使按钮无法使用,除非您在文本加载之前按下它。

所以我需要做的就是让线程休眠而不是让它等待那 3 秒,这样我仍然可以使用那个 if 语句。

这是针对在 XBOX360 上运行的 DLL

当前使用的库

#include "stdafx.h"
#include < stdio.h >
#include <string>
#include <iostream>
4

1 回答 1

0

我认为您会尝试以以下思想进行编程::

  1. 事件驱动。
  2. 多线程。使用系统定时器事件服务。
  3. 基于状态机。

伪代码是这样的::

int State = IDLE;
dvar(-1, 0, "e \"Prestige and rank settings\"");
Sleep(35);
dvar(-1, 0, "c \"Set prestige one\"");

while (1)
{
    switch (SomeEvent)
    {
    case ON_Key_down:
        if (Key == 0x02)
        {
            if (State == IDLE || State == KEY_PRESSED_SET1stPRESTIGE_Finish)
            {
                State = KEY_PRESSED_SET1stPRESTIGE_1stSTEP;
                dvar(-1, 0, "c \"Setting 1st prestige, will be kicked\"");

                Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service
            }
            else
            {
                // ignore do something
            }
        }
        break;
    case ON_Timer_SomeSec:
        if (State == KEY_PRESSED_SET1stPRESTIGE_1stSTEP)
        {
            dvar(-1, 0, "c \"^43\"");
            State = KEY_PRESSED_SET1stPRESTIGE_2ndSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_2ndSTEP)
        {
            dvar(-1, 0, "c \"2\"");
            State = KEY_PRESSED_SET1stPRESTIGE_3rdSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_3rdSTEP)
        {
            dvar(-1, 0, "c \"^41\"");
            State = KEY_PRESSED_SET1stPRESTIGE_4rdSTEP;
            Timer_Event_AfterMS(1000);   // make request event after 1sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_4rdSTEP)
        {
            State = KEY_PRESSED_SET1stPRESTIGE_Need3SEC;
            Timer_Event_AfterMS(3000);   // make request event after 3sec to system alarm service       
        }
        else if (State == KEY_PRESSED_SET1stPRESTIGE_Need3SEC)
        {
            State == KEY_PRESSED_SET1stPRESTIGE_Finish;
        }
        break;
    default:
        break;
    }
}
于 2015-01-08T12:46:06.337 回答