Пример #1
0
        /// <summary>
        /// do an action as a specific player
        /// </summary>
        private void DoAction(int gameId, Guid owner, Action.Type actionType, string text = null)
        {
            var action = new Action(owner, actionType, text);
            action.GameId = gameId;

            var game = GetGame(gameId);
            var previousState = game.GameState;
            game.DoAction(action);

            _simpleDb.AddAction(action);

            var computersPlayersInGame = game.Players.Where(p => p.PlayerType != Core.Player.Type.Human);
            if (game.GameState != Game.State.Lobby)
            {
                while (computersPlayersInGame.Any(c => game.AvailableActions(game.Players.First(p => p.Guid == c.Guid)).Any(a => a.ActionType != Action.Type.Message)))
                {
                    foreach (var computerPlayer in computersPlayersInGame)
                    {
                        var computerActions = Core.ComputerPlayers.ComputerPlayer.Factory(computerPlayer.PlayerType, computerPlayer.Guid).DoSomething(game);
                        if (computerActions != null)
                        {
                            foreach (var computerAction in computerActions)
                            {
                                computerAction.GameId = gameId;
                                game.DoAction(computerAction);
                                _simpleDb.AddAction(computerAction);
                            }
                        }
                    }
                }
            }

            if (game.GameState != previousState)
            {
                SendMessagesAsAppropriate(game, gameId);
            }

            Update();
        }
Пример #2
0
 /// <summary>
 /// do an action as the logged on user
 /// </summary>
 private void DoAction(int gameId, Action.Type actionType, string text = null)
 {
     DoAction(gameId, PlayerGuid, actionType, text);
 }