我正在为我的最后一年项目制作一个教育游戏,当我的玩家框与另一个项目框发生冲突时,当涉及到递增一个值时,我遇到了一点bug。当我的播放器死了,然后重置,第一项收集正常,然后程序似乎跳过下一个if语句,提取第三项而不是第二项,错误就出现了。
我已经添加了我认为问题所在的代码。
LevelManager.cs
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
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;
}任何可以给予的帮助都将非常感谢干杯
发布于 2015-03-11 21:03:35
我在你提供的代码片段中看不到bug。我只能说,您可以在行上设置断点
player.Hint++;(或在提示属性的setter中更好的事件),并查看何时以及为什么将其更改为3。
https://stackoverflow.com/questions/28986718
复制相似问题