【发布时间】:2020-10-06 21:52:57
【问题描述】:
所以我正在尝试制作一个计时器,它会在单人游戏中从 30 秒计时到 0,但我不明白我该怎么做。我对编程很陌生。我正在尝试将其放入我的枚举中,因此当计时器达到 0 时,它会将状态从播放更改为游戏结束。
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
switch (currentGameState)
{
case Gamestate.Start:
timeSinceLastFrame += gameTime.ElapsedGameTime.TotalSeconds;
if (timeSinceLastFrame >= timeBetweenFrame)
{
timeSinceLastFrame -= timeBetweenFrame;
currentFrame.X++;
if(currentFrame.X >= sheetSize.X)
{
currentFrame.X = 0;
currentFrame.Y++;
if (currentFrame.Y>=sheetSize.Y)
{
currentFrame.Y = 0;
}
}
}
posStone.Y = posStone.Y + 1;
if (Keyboard.GetState().IsKeyDown(Keys.Enter))
{
currentGameState = Gamestate.Play;
}
break;
case Gamestate.Play:
break;
case Gamestate.GameOver:
break;
}
}
【问题讨论】:
-
“我正在尝试将它放入我的枚举中,因此当计时器达到 0 时,它会将状态从播放更改为游戏结束” - 将什么放入什么枚举中?在上面的代码中,您试图将游戏状态更改回
GameOver?您的问题不清楚,并且没有提供您迄今为止尝试过的证据。请改进它。 -
可能是指 switch 语句,当它被说 * 我试图把它放入我的枚举 * 但是是的,这个问题需要澄清。