【问题标题】:How to implement turn-based game in Orleans?如何在奥尔良实现回合制游戏?
【发布时间】:2021-07-23 06:31:33
【问题描述】:

我正在尝试实现一个简单的回合制游戏,在游戏开始前 N 名玩家可以加入游戏。游戏开始后,在每一轮中,每个玩家轮流掷一对骰子,以便他们加入游戏。比赛共有三轮。游戏结束时,每位玩家都会获得积分。

例如,假设玩家 P1、P2、P3、P4 以该顺序加入游戏,那么他们将按照相同的顺序滚动这对骰子。三轮后,假设结果为

P1: (3,5), (4,1), (2,3)
P2: (5,5), (4,3), (1,3)
P3: (3,3), (4,4), (2,1)

对于游戏,我的想法是:

public interface IGameBase : IGrainWithGuidKey
{
    Task<bool> IsActive();
    Task Join(IPlayerBase player);
    Task Leave(IPlayerBase player);
}
public interface IGame<TState, in TRequest> : IGameBase
{
    Task<TState> State();
    Task<TState> Play(IPlayerBase player, TRequest request);
}

public interface IPlayerBase : IGrainWithGuidCompoundKey
{
    Task<IPlayerInfo> Info();

    Task<IEnumerable<Guid>> Games();
    
    Task Subscribe(IGameBase game);

    Task Unsubscribe(IGameBase game);
}

我应该如何实现让玩家知道该轮到他们玩了?

【问题讨论】:

    标签: orleans


    【解决方案1】:

    我能够通过使用streams 实现它来解决这个问题。基本上用游戏 id 和玩家 id 向流发送一条播放消息,玩家收听这些消息。轮到的人会向游戏颗粒发送一个游戏动作。

    代码在这里https://github.com/sheeri185adidam/orleanedgames

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-06
      • 1970-01-01
      相关资源
      最近更新 更多