Beispiel #1
0
 private IList <int> GetValidActionIdList(string playerId)
 {
     if (GameStage == null)
     {
         return(new List <int>());
     }
     return(GameStage.GetValidActionIdList(playerId));
 }
Beispiel #2
0
        private CardPile GetPlayerHand(GameStage gameStage, string playerId)
        {
            var playerHandDictionary = GameStage?.CurrentGameRound?.PlayerHandDictionary;
            var hand = playerHandDictionary != null && playerHandDictionary.ContainsKey(playerId)
                ? playerHandDictionary[playerId]
                : null;

            return(hand);
        }
Beispiel #3
0
        public bool ProcessAction(ActionBase action)
        {
            if (GameStage == null)
            {
                return(false);
            }
            if (!CheckAndSetBusy())
            {
                return(false);
            }

            try {
                var validPlayerActions = GetValidActionIdList(action.PlayerInfo.PlayerId);
                if (!validPlayerActions.Contains(action.GetActionId()))
                {
                    return(false);
                }
            }
            catch (Exception e)
            {
                Log.Error($"Exception in GetValidActionIdList of ProcessAction: {e.Message}", e);
                throw;
            }

            RunBusyAction(() =>
            {
                try {
                    GameStage.ProcessAction(action);
                }
                catch (Exception e)
                {
                    Log.Error($"Exception in ProcessAction: {e}", e);
                    throw;
                }
                try {
                    UpdatePlayers();
                }
                catch (Exception e)
                {
                    Log.Error($"Exception in UpdatePlayers: {e.Message}", e);
                    throw;
                }
            });
            return(true);
        }
Beispiel #4
0
        public bool StartGame()
        {
            if (GameStage != null)
            {
                return(false);
            }
            if (PlayerGroupInfo.GetPlayerList().Count != 4)
            {
                return(false);
            }
            if (!CheckAndSetBusy())
            {
                return(false);
            }

            RunBusyAction(() =>
            {
                try {
                    GameStage = new GameStage(GameInfo.Rules, PlayerGroupInfo, ConfirmAction);
                }
                catch (Exception e)
                {
                    Log.Error($"Exception in StartGame: {e.Message}", e);
                    throw;
                }
                try {
                    UpdatePlayers();
                }
                catch (Exception e)
                {
                    Log.Error($"Exception in UpdatePlayers: {e.Message}", e);
                    throw;
                }
            });
            return(true);
        }