Ejemplo n.º 1
0
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            if (AllowedAction(action, game))
            {
                action.PerformTurnAction(game);

                EndTurnAction endTurn = action as EndTurnAction;
                if (endTurn != null)
                {
                    return new BeforeDiceRollTurnPhase();
                }

                return this;
            }
            else
            {
                // Check if we are allowed to trade
                TradeOfferAction tradeOffer = action as TradeOfferAction;
                if (tradeOffer != null)
                {
                    // Only when game setting allows it
                    if (game.Settings.TradingAfterBuilding)
                    {
                        return _TradingPhase;
                    }
                    return null;
                }
                return null;
            }
        }
Ejemplo n.º 2
0
 public override void ProcessAction(InGameAction inGameAction, XmlGame game)
 {
     /*
     HostStartsGameAction hostStarts = inGameAction as HostStartsGameAction;
     if (hostStarts != null)
     {
         game.ActionsQueue.Enqueue(new DetermineFirstPlayerGamePhase() { Sender = 0 });
     }
      */
     inGameAction.PerformTurnAction(game);
 }
Ejemplo n.º 3
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            inGameAction.PerformTurnAction(game);

            if (game.ActionsQueue.Count == 0)
            {
                // Notify we want to start the placement phase
                game.ActionsQueue.Enqueue(new PortsPlacedAction() { Sender = 0 });
            }
            else
            {
                // Move to the next player
                game.PlayerOnTurn = game.NextPlayer;
            }
        }
Ejemplo n.º 4
0
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            RollDiceAction rollDice = action as RollDiceAction;
            if (rollDice != null)
            {
                return new RollDiceTurnPhase();
            }
            if (AllowedAction(action, game))
            {

                action.PerformTurnAction(game);
                return this;
            }
            else
            {
                return null;
            }
        }
Ejemplo n.º 5
0
 public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
 {
     // If the action is allowed to be executed in this phase, do it
     if (AllowedAction(action, game))
     {
         action.PerformTurnAction(game);
         return this;
     }
     else
     // If action is not allowed to execute, check if buildphase allows it. If so, move to
     // buildphase
     {
         if (_BuildPhase.AllowedAction(action, game))
         {
             return _BuildPhase;
         }
         throw new Exception("whoa");
     }
 }
Ejemplo n.º 6
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            // If we build a town or a city, make sure the next action (buildroad)
            // has OriginatingTownOrCity set. This is ignored for the third road
            // as required by Tournament Starting Rules.
            BuildTownAction buildTown = inGameAction as BuildTownAction;
            if (buildTown != null)
            {
                BuildRoadAction buildRoad3 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad3.OriginatingTownOrCity = buildTown.Location;
            }
            BuildCityAction buildCity = inGameAction as BuildCityAction;
            if (buildCity != null)
            {
                BuildRoadAction buildRoad2 = game.ActionsQueue.Peek() as BuildRoadAction;
                buildRoad2.OriginatingTownOrCity = buildCity.Location;
            }

            inGameAction.PerformTurnAction(game);

            // If the last road or ship has been built, add new gamephase action on the queue
            BuildRoadAction buildRoad = inGameAction as BuildRoadAction;
            BuildShipAction buildShip = inGameAction as BuildShipAction;
            if (buildRoad != null || buildShip != null)
            {
                if (game.ActionsQueue.Count == 0)
                {
                    game.ActionsQueue.Enqueue(new PlacementDoneAction() { Sender = 0 });
                }
                else
                {
                    // Next player is the player of the first action on the queue
                    game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue.Peek().Sender);
                }

            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="action"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public override TurnPhase ProcessAction(InGameAction action, XmlGame game)
        {
            if (AllowedAction(action, game))
            {
                RollDiceAction rollDice = action as RollDiceAction;
                if (rollDice != null)
                {
                    rollDice.PerformTurnAction(game);

                    // When a volcano is rolled, expect player to roll dice for volcano
                    /*
                    if (rollDice.HexesAffected.OfType<VolcanoHex>().Count() > 0)
                    {
                        game.ActionsQueue.Enqueue(new RollVolcanoDiceAction()
                        {
                            GamePlayer = rollDice.GamePlayer,
                            VolcanosRolled = rollDice.HexesAffected.OfType<VolcanoHex>().ToList<VolcanoHex>()
                        });

                        // We expect another action, return current phase
                        return this;
                    }
                     */

                    // When a 7 is rolled, enqueue every player required to loose cards to do so
                    if (rollDice.Dice == 7)
                    {
                        // Add each player required to loose cards to the queue
                        foreach (int i in rollDice.LooserPlayers)
                        {
                            game.ActionsQueue.Enqueue(new LooseCardsAction()
                            {
                                GamePlayer = game.GetPlayer(i)
                            });
                        }

                        // Expect player to place robber/pirate and rob a player
                        game.ActionsQueue.Enqueue(new PlaceRobberPirateAction() { GamePlayer = action.GamePlayer });
                        game.ActionsQueue.Enqueue(new RobPlayerAction() { GamePlayer = action.GamePlayer });

                        // We have actions to be done, we should stay in this phase
                        return this;
                    }

                    // Any other number has been rolled.
                    // Proceed to trading phase
                    if (game.ActionsQueue.Count == 0)
                    {
                        return new TradingTurnPhase();
                    }
                    else
                    {
                        return this;
                    }
                }

                RobPlayerAction robPlayer = action as RobPlayerAction;
                if (robPlayer != null)
                {
                    robPlayer.PerformTurnAction(game);

                    // When finished robbing, advance phase to trading
                    return this;
                }
                // perform the action
                action.PerformTurnAction(game);
                EndTurnAction endTurn = action as EndTurnAction;
                if (endTurn != null)
                {
                    return new BuildTurnPhase(null);
                }

                // Return current state
                return this;
            }
            else
            // Action is not allowed in rollDice phase. Check if it is allowed in subsequent phases,
            // then return that phase
            {
                TradingTurnPhase trading = new TradingTurnPhase();
                BuildTurnPhase building = new BuildTurnPhase(trading);
                if (trading.AllowedAction(action, game))
                {
                    return trading;
                }
                if (building.AllowedAction(action, game))
                {
                    return building;
                }
                return null;
            }
        }
        /// <summary>
        /// Creates gamequeue for each player
        /// </summary>
        /// <param name="inGameAction"></param>
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            inGameAction.PerformTurnAction(game);

            RollDiceAction rollDice = inGameAction as RollDiceAction;
            if (rollDice != null)
            {
                // Check if a phase has ended. If the queue is empty, every player has rolled the dice.
                if (game.ActionsQueue.Count() == 0)
                {
                    // Make a list of rolls in this round
                    List<RollDiceAction> rolledDices = game.GameLog.GetCurrentRoundRolls(game);

                    // highroll dice number
                    int highRoll = (from rd in rolledDices select rd.Dice).Max();

                    // When starting player is not determined yet, repeat dice roll between winners until
                    // winner is detemined
                    if (game.GameLog.FirstPlayerIsDetermined(game))
                    {
                        // We have a starting player
                        int winnerID = rolledDices.Where(rd => rd.Dice == highRoll)
                                                                          .First()
                                                                          .Sender;

                        game.ActionsQueue.Enqueue(new StartingPlayerDeterminedAction()
                        {
                            // The starter of the placement/portplacement/turnactionsgamephase
                            PlayerID = winnerID,
                            // winning dice
                            DiceRoll = highRoll,
                            // Server will send this message
                            Sender = 0
                        });
                        return;
                    }
                    else
                    {
                        // Starting player is not determined. Notify players and update Game object
                        game.ActionsQueue.Enqueue(new RolledSameAction()
                        {
                            // Pass on the highest diceroll
                            HighRoll = highRoll,
                            // Server says dice rolled the same
                            Sender = 0
                        });

                        // Enqueue each highroller
                        foreach (RollDiceAction sameRoll in rolledDices.Where(rd => rd.Dice == highRoll))
                        {
                            game.ActionsQueue.Enqueue(new RollDiceAction() { GamePlayer = sameRoll.GamePlayer });
                        }

                        // First player is on turn
                        game.PlayerOnTurn = game.ActionsQueue.ElementAt(1).GamePlayer;
                        return;
                    }
                }

                // Next player should be the player next on the queue
                game.PlayerOnTurn = game.GetPlayer(game.ActionsQueue
                    .OfType<RollDiceAction>()
                    .First()
                    .Sender);

            }
        }
Ejemplo n.º 9
0
        public GameAction ExecuteAction(InGameAction action)
        {
            if (action.IsValid(_Game))
            {
                //Execute the game action if the action is valid
                action.PerformTurnAction(_Game);

                // Send action back to sender for confirmation

                //Send action to all other players and spectators

                //Add action to the gamelog
                _Game.GameLog.Add(action);
                return action;
            }
            else
            // we received an illegal ingameaction.
            // This should only happen when a user deliberately tampers with data
            {
                MessageFromServerAction message = new MessageFromServerAction();
                message.Message = String.Format(
                    "The game action does not seem to be valid. The reason: action object says \"{0}\"",
                    action.InvalidMessage);
                return message;
            }
        }