Java Card 游戏服务器,无法弄清楚如何在没有 goto 的情况下从头开始
我不知道如何在不使用 goto 的情况下做到这一点。
我正在制作一个具有 .. 状态的网卡读取游戏,等待至少 2 个玩家。 2 个玩家进入后,它会执行一个 while 循环,游戏结束后,它将重复。在这个循环中,还有 3 个循环用于洗牌、翻牌看牌。如果在 3 个循环中的任何一个中,玩家退出并且只剩下 1 个玩家或没有玩家,我怎样才能让它转到等待 2 个玩家循环的代码顶部
Do{
// waiting for two player???
….......
} while less then 2 players
while(true)
{
shuffle cards
wait for all players to see cards
****** if players quit how can it go to waiting state
do{
turn card over
****** if players quit how can it go to waiting state
wait for all players to see card
Look at the card blown up
} while turn over cards<12)
} // true reloop game
I dont know how to do this without using a goto.
I'm making a network card reading game that has .. states, waiting for at least 2 players After 2 players have entered it does a while loop, where after game is finshed it will repeat. Within this loop, there are 3 more loops for shuffle, turn card over look at card. If in any of the 3 loops, players quit and there is only 1 or no players left, how can I make it go to the top of the code where the waiting for 2 player loop is
Do{
// waiting for two player???
….......
} while less then 2 players
while(true)
{
shuffle cards
wait for all players to see cards
****** if players quit how can it go to waiting state
do{
turn card over
****** if players quit how can it go to waiting state
wait for all players to see card
Look at the card blown up
} while turn over cards<12)
} // true reloop game
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您正在寻找标签。如果有嵌套循环,则可以
继续
外层循环(如果它有标签):通过将整个代码包装在 while 循环中,当您需要“退出”时,只需继续外层循环即可开始从头开始。
I think you're looking for labels. If you have nested loops, you can
continue
the outer loop if it has a label:By wrapping your whole code in a while loop, when you need to "quit", just continue the outer loop to start back from the start.
尝试将所有这些循环包装在另一个
while(true)
中。这样,当游戏循环退出时,它会返回到开头并等待更多玩家,然后继续再次玩游戏。Try wrapping all of those loops around in another
while(true)
. That way when the game loop exits, it goes back to the beginning and waits for more players, then continues to play the game again.