首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使变量正确递增的问题

使变量正确递增的问题
EN

Stack Overflow用户
提问于 2015-03-11 20:32:25
回答 1查看 51关注 0票数 0

我正在为我的最后一年项目制作一个教育游戏,当我的玩家框与另一个项目框发生冲突时,当涉及到递增一个值时,我遇到了一点bug。当我的播放器死了,然后重置,第一项收集正常,然后程序似乎跳过下一个if语句,提取第三项而不是第二项,错误就出现了。

我已经添加了我认为问题所在的代码。

LevelManager.cs

代码语言:javascript
复制
                for (int x = hints.Count - 1; x >= 0; x--)
            {
                hints[x].Update(gameTime);
                if (player.CollisionRectangle.Intersects(
                    hints[x].CollisionRectangle))
                {
                    hints.RemoveAt(x);
                    player.Hint++;
                }
            }

Game1.cs

代码语言:javascript
复制
 if ((gameState == GameState.Playing) ||
            (gameState == GameState.PlayerDead) ||
            (gameState == GameState.GameOver))
        {
            spriteBatch.Begin(
          SpriteSortMode.BackToFront,
          BlendState.AlphaBlend);

            TileMap.Draw(spriteBatch);
            player.Draw(spriteBatch);
            LevelManager.Draw(spriteBatch);
            spriteBatch.DrawString(
                pericles8,
                "Score: " + player.Score.ToString(),
                scorePosition,
                Color.White);
            spriteBatch.DrawString(
                pericles8,
                "Lives Remaining: " + player.LivesRemaining.ToString(),
                livesPosition,
                Color.White);

            if (player.Hint == 1)
            {
                spriteBatch.DrawString(
                    pericles8,
                    "Hint: " + "Antivirus is needed to protect your PC",
                    HintLocation,
                    Color.Black);
            }

            if (player.Hint == 2)
            {
                spriteBatch.DrawString(
                    pericles8,
                    "Hint: " + "When the first virus was created, it changed the name of floppy disks that were infected",
                    HintLocation,
                    Color.Black);
            }

            if (player.Hint == 3)
            {
                spriteBatch.DrawString(
                    pericles8,
                    "Hint: " + "Blue Whale is NOT the name of a virus and also whilst adware is annoying, it is not considered a virus",
                    HintLocation,
                    Color.Black);
            }

            if (player.Hint == 4)
            {
                spriteBatch.DrawString(
                    pericles8,
                    "Hint: " + "By having a firewall up, you lock all backdoors into your PC." + "\n" + "Also by staying clear of sites you dont know, you lower the chance of viruses getting into your PC" + "\n"
                    + "However you should install relevant protection to increase your chance of not getting viruses",
                    HintLocation,
                    Color.Black);
            }
            spriteBatch.End();
        }

        if (gameState == GameState.PlayerDead)
        {
            player.Hint = 0;
        }

任何可以给予的帮助都将非常感谢干杯

EN

回答 1

Stack Overflow用户

发布于 2015-03-11 21:03:35

我在你提供的代码片段中看不到bug。我只能说,您可以在行上设置断点

代码语言:javascript
复制
player.Hint++;

(或在提示属性的setter中更好的事件),并查看何时以及为什么将其更改为3。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28986718

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档