在 Spring 应用程序中维护状态?

发布于 2024-11-19 01:29:19 字数 250 浏览 2 评论 0原文

只是寻找一些有关在 Spring 应用程序中维护某些内容的状态的理论。

例如,想象一下作为 Web 应用程序运行的扑克游戏。有很多事情需要考虑。例如维护玩家一手牌中的筹码数量、参与一手牌的人、每个玩家的牌值以及共享的公共牌。下注金额、底池总额等。

其他需要考虑的因素是玩家在被弃牌之前必须采取行动的时间分配。

无论执行游戏循环的逻辑如何,使用 spring 跟踪一手扑克以及完整的扑克游戏状态的最佳方法是什么。

提前致谢。

Just looking for a bit if theory regarding maintaining state of something in a spring application.

For example imagine a game of poker running as a web app. There are a number of things to consider. Such as maintaining the amount of poker chips a player has in a hand, who is involved in a hand, the card values per player as well as the shared community cards. The amounts bet, pot totals etc.

Other things to consider are the time allocations a player has to act before being folded.

Regardless of the logic for performing the game loop, what would be the best way to keep track of the state of a hand of poker and also a complete game of poker using spring.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

却一份温柔 2024-11-26 01:29:19

与跟踪网络应用程序中的任何数据的方式相同;编写一个 DAO 接口,然后创建一个实现。例如;

public class PokerHand {
  //just a POJO
}

public interface PokerHandDAO {
  public PokerHand getPokerHand(long id);
  public void updatePokerHand(PokerHand hand);
}

public class InMenoryPokerHandDAO implements PokerHandDAO {
  private static Map<Long,PokerHand> hands = new HashMap<Long,PokerHand>();

  @Override
  public PokerHand getPokerHand(long id) {
    return hands.get(id);
  }

  @Override
  public void updatePokerHand(PokerHand hand) {
    hands.put(hand.getId(), hand);
  }
}

每当玩家采取更改操作时,他们都会向网络应用程序发出请求。您将必须跟踪几件事的状态,并且显然您将不得不担心玩家之间的状态同步。

Same way as you keep track of any data in a web app; write a DAO interface then create an implementation. For example;

public class PokerHand {
  //just a POJO
}

public interface PokerHandDAO {
  public PokerHand getPokerHand(long id);
  public void updatePokerHand(PokerHand hand);
}

public class InMenoryPokerHandDAO implements PokerHandDAO {
  private static Map<Long,PokerHand> hands = new HashMap<Long,PokerHand>();

  @Override
  public PokerHand getPokerHand(long id) {
    return hands.get(id);
  }

  @Override
  public void updatePokerHand(PokerHand hand) {
    hands.put(hand.getId(), hand);
  }
}

Whenever a player takes an action to change they make a request to the web app. You're going to have to keep track of the state of several things, and you're obviously going to have to worry about syncronising the state amongst players.

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