Beispiel #1
0
        /// <summary>
        /// 玩家出牌
        /// </summary>
        /// <param name="player">轮到出牌的玩家</param>
        /// <param name="token">取消标识</param>
        /// <returns>获取一个 Task,用于等待这个玩家处理结束</returns>
        protected virtual async Task PlayerPlay(GameRoundEvent roundEvnet, CardGamePlayer player, CancellationToken token)
        {
            await OnBeforePlay(roundEvnet, player, token);

            await player.Play(roundEvnet, token);

            await OnAfterPlay(roundEvnet, player, token);
        }
Beispiel #2
0
        /// <summary>
        /// 确保指定的玩家已经准备好
        /// </summary>
        /// <param name="player">要确认准备状态的玩家</param>
        /// <param name="token">取消标识</param>
        /// <returns>获取一个 Task 用于等待玩家确认准备状态</returns>
        private async Task EnsureAlready(CardGamePlayer player, CancellationToken token)
        {
            player.PlayerHost.WriteSystemMessage("游戏即将开始,在游戏进行中请不要关闭客户端或浏览器。");
            var option = await player.PlayerHost.Console.Choose(null, new[] { new Option("准备好了", "准备好可以进行游戏"), new Option("退出游戏", "退出这个游戏") }, token);

            if (option.Name == "准备好了")
            {
                AnnounceSystemMessage("{0} 已经准备好", player.PlayerName);
            }

            else if (option.Name == "退出游戏")
            {
                player.QuitGame();
            }
        }
        /// <summary>
        /// 重写 PlayerPlay 方法,在每个玩家操作完毕后,检查所有玩家是否都还活着
        /// </summary>
        /// <param name="player">正在执行操作的玩家</param>
        /// <param name="token">取消标识</param>
        /// <returns>获取一个 Task 用于等待操作完成</returns>
        protected override async Task PlayerPlay(GameRoundEvent roundEvent, CardGamePlayer player, CancellationToken token)
        {
            await base.PlayerPlay(roundEvent, player, token);

            await EnsurePlayersAlive();
        }
Beispiel #4
0
 /// <summary>
 /// 创建 PlayerRoundEvent 对象
 /// </summary>
 /// <param name="player">当前出牌的玩家</param>
 public PlayerRoundEvent(GameRoundEvent roundEvent, CardGamePlayer player)
 {
     Player     = player;
     RoundEvent = roundEvent;
 }
Beispiel #5
0
 protected virtual Task OnAfterPlay(GameRoundEvent roundEvent, CardGamePlayer player, CancellationToken token)
 {
     return(Task.CompletedTask);
 }
Beispiel #6
0
 /// <summary>
 /// 使用一张卡牌
 /// </summary>
 /// <param name="initiatePlayer">发起玩家</param>
 /// <param name="target">目标对象</param>
 /// <returns>获取用于等待处理卡牌使用过程的 Task</returns>
 public abstract Task Play(CardGamePlayer initiatePlayer, CancellationToken token);