无法理解为什么游戏状态在游戏中没有改变
我是编码初学者,目前正在参加哈佛大学的 GD50 课程。我无法弄清楚我的代码有什么问题。我想做的是按下回车键时更新游戏状态。我实现了一个基本菜单,如果您按一个,您将被发送到开始状态,这工作正常,但我不知道如何将其与按不同的键结合起来实际开始游戏(更新到服务状态)等等)。希望我的解释很清楚。任何帮助将不胜感激。这是我的代码(请说如果我需要发布更多):
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
elseif key == 'm' then
gameState = 'menu'
elseif key == '1' then
if gameState == 'menu' then
gameState = 'start'
end
elseif key == 'enter' then
if gameState == 'start' then
gameState = 'serve'
elseif gameState == 'serve' then
gameState = 'play'
elseif gameState == 'done' then
gameState = 'serve'
ball:reset()
player1Score = 0
player2Score = 0
if winningPlayer == 1 then
servingPlayer = 2
else
servingPlayer = 1
end
end
end
end
I'm a beginner at coding and I am currently doing GD50 by Harvard. I cannot figure out what is wrong with my code here. What i'm trying to do is update the game state when enter is pressed. I implemented a basic menu where if you press one, you are sent to the start state, which is working fine, but i can't figure out how to combine this with pressing a different key to actually start the game(updating to serve state and so on). Hope i was clear with the explanation. Any help would be appreciated. Here's my code(pls say if i need to post more):
function love.keypressed(key)
if key == 'escape' then
love.event.quit()
elseif key == 'm' then
gameState = 'menu'
elseif key == '1' then
if gameState == 'menu' then
gameState = 'start'
end
elseif key == 'enter' then
if gameState == 'start' then
gameState = 'serve'
elseif gameState == 'serve' then
gameState = 'play'
elseif gameState == 'done' then
gameState = 'serve'
ball:reset()
player1Score = 0
player2Score = 0
if winningPlayer == 1 then
servingPlayer = 2
else
servingPlayer = 1
end
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论