/// <summary>
        /// 实现 PlayCard 方法,令玩家出牌
        /// </summary>
        /// <param name="round">当前回合事件</param>
        /// <param name="token">取消标识</param>
        /// <returns>返回一个 Task 对象,用于等待玩家出牌完毕</returns>
        protected override async Task PlayCard(PlayerRoundEvent round, CancellationToken token)
        {
            while (ActionPoint > 0)
            {
                var card = await CherryCard(token);

                if (card == null)
                {
                    throw new TimeoutException();
                }


                CardCollection.RemoveCard(card);
                try
                {
                    await card.Play(this, token);

                    ActionPoint -= card.ActionPoint;
                }
                catch
                {
                    CardCollection.AddCard(card);
                    throw;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 玩家进行该回合的操作
        /// </summary>
        /// <param name="token">取消标识</param>
        /// <returns>获取一个用于等待玩家处理完成的 Task</returns>
        public virtual async Task Play(GameRoundEvent roundEvent, CancellationToken token)
        {
            Game.AnnounceMessage("轮到 {0} 出牌", PlayerName);

            var round = new PlayerRoundEvent(roundEvent, this);

            await OnGameEvent(round);

            await OnBeforePlayCard(round, token);

            try
            {
                await PlayCard(round, token);
            }
            catch (TimeoutException)
            {
                await OnTimeout();
            }

            await OnAfterPlayCard(round, token);
        }
Esempio n. 3
0
 protected virtual Task OnAfterPlayCard(PlayerRoundEvent round, CancellationToken token)
 {
     return(Task.CompletedTask);
 }
Esempio n. 4
0
 protected abstract Task PlayCard(PlayerRoundEvent round, CancellationToken token);