0

当我试图移动到一个列表中的不同项目时,它会更改不同列表中的项目,但无法弄清楚。当我让它移动第一个列表时,然后当我尝试单击 Enter 以尝试让它切换列表时,它什么也不做。这是代码:

    public void Update(GameTime gameTime, Game1 game)
    {
        keyboard = Keyboard.GetState();
        mouse = Mouse.GetState();
        //Checks if the up arrow has been pressed and released
        if (CheckKeyboard(Keys.Up))
        {
            if (Selected.Equals("None"))
            {
                if (selected > 0) selected--;
                else selected = (buttonList.Count - 1);
            }
            else if (Selected.Equals("Play"))
            {

            }
            else if (Selected.Equals("LevelSelect"))
            {
                //This is what is meant to happen while sChapter1 = 0 but the error is it is
                //moving one of the other lists
                if (sChapter1 == 0)
                {
                    if (sChapter > 0) sChapter--;
                    else sChapter = (chapterList.Count - 1);
                }
                //This is what should happen when enter is pressed on the first chapter
                else if (sChapter1 == 1)
                {
                    if (sC1Level > 0) sC1Level--;
                    else sC1Level = (c1LevelList.Count - 1);
                }
                //This is what should happen when enter is pressed on the second chapter
                else if (sChapter1 == 2)
                {
                    if (sC2Level > 0) sC2Level--;
                    else sC2Level = (c2LevelList.Count - 1);
                }
                //This is what should happen when enter is pressed on the third chapter
                else if (sChapter1 == 3)
                {
                    if (sC3Level > 0) sC3Level--;
                    else sC3Level = (c3LevelList.Count - 1);
                }
            }
        }

        //Checks if the down arrow is pressed and released
        if (CheckKeyboard(Keys.Down))
        {
            if (Selected.Equals("None"))
            {
                if (selected < buttonList.Count - 1) selected++;
                else selected = 0;
            }
            else if (Selected.Equals("Play"))
            {

            }
            else if (Selected.Equals("LevelSelect"))
            {
                //This is what is meant to happen while sChapter1 = 0 but the error is it is
                //moving one of the other lists
                if (sChapter1 == 0)
                {
                    if (sChapter < chapterList.Count - 1) sChapter++;
                    else sChapter = 0;
                }
                //This is what should happen when enter is pressed on the first chapter key
                else if (sChapter1 == 1)
                {
                    if (sC1Level < c1LevelList.Count - 1) sC1Level++;
                    else sC1Level = 0;
                }
                //This is what should happen when enter is pressed on the second chapter
                else if (sChapter1 == 2)
                {
                    if (sC2Level < c2LevelList.Count - 1) sC2Level++;
                    else sC2Level = 0;
                }
                //This is what should happen when enter is pressed on the third chapter
                else if (sChapter1 == 3)
                {
                    if (sC3Level < c3LevelList.Count - 1) sC3Level++;
                    else sC3Level = 0;
                }
            }
        }
        if (CheckKeyboard(Keys.Enter))
        {
            //Checks if the selected item is a certain one in the list to
            //cause something to happen.
            if (selected == buttonList.Count - 1) Game1.GameState = "Menu";
            //Sets it to draw the LevelSelect portion of the menu
            if (selected == buttonList.Count - 2) Selected = "LevelSelect";
            if (selected == buttonList.Count - 3) Selected = "Play";

            //Checks what chapter of the games it is on so that it can choose levels within the
            //chapter. This should only effect when a chapter is selected and enter is pressed
            //but it is effecting whether the chapterlist is being scrolled thru or if the
            //levellists are.
            if (sChapter == chapterList.Count - 1) sChapter1 = 3;
            if (sChapter == chapterList.Count - 2) sChapter1 = 2;
            if (sChapter == chapterList.Count - 3) sChapter1 = 1;
        }
        if (CheckKeyboard(Keys.Back))
        {
            //Ignore this, it hasn't been used yet
        }

        prevMouse = mouse;
        prevKeyboard = keyboard;
    }

    public bool CheckKeyboard(Keys key)
    {
        //Checks if the key has been pressed and released
        return (keyboard.IsKeyUp(key) && prevKeyboard.IsKeyDown(key));
    }

注意:我弄清楚问题是什么,在我的 CheckKeyboard(Keys.Enter) 中它同时在做这两个。所以它跳过了一个列表,我试过让线程进入睡眠状态,但它仍然在做,有什么建议吗?

4

0 回答 0