Java Card 游戏服务器,无法弄清楚如何在没有 goto 的情况下从头开始

发布于 2025-01-03 15:46:32 字数 655 浏览 0 评论 0原文

我不知道如何在不使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

×纯※雪 2025-01-10 15:46:32

我认为您正在寻找标签。如果有嵌套循环,则可以继续外层循环(如果它有标签):

outer:
while(x){
   // ...

   while(y){

      // someone quit
      continue outer;

   }

   // ...
}

通过将整个代码包装在 while 循环中,当您需要“退出”时,只需继续外层循环即可开始从头开始。

I think you're looking for labels. If you have nested loops, you can continue the outer loop if it has a label:

outer:
while(x){
   // ...

   while(y){

      // someone quit
      continue outer;

   }

   // ...
}

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.

夏了南城 2025-01-10 15:46:32

尝试将所有这些循环包装在另一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文