/// <summary>
        /// Winner of the diceroll contest starts placing a port
        /// </summary>
        /// <param name="game"></param>
        /// <returns>First player to place a port</returns>
        public override void Start(XmlGame game)
        {
            int portCount = 0;

            foreach (Territory t in game.Board.Territories)
            {
                foreach (EPortType port in t.PortList)
                {
                    game.ActionsQueue.Enqueue(new PlacePortAction()
                    {
                        // Placing ports goes chronologically starting with the winner.
                        // The first player always has the advantage:
                        // - For example with 5 ports and 4 players, first player may place twice
                        //   while the rest only once.
                        // - First player may plac first, conveniently placing port alongside
                        // - Since port stack is open, first player placing last port is 100% certain
                        //   known port
                        GamePlayer = game.Players[portCount % game.Players.Count],
                        // pass territoryID such that player knows to expect possible port locations
                        TerritoryID = t.ID
                    });

                    portCount++;
                }
            }
        }
Example #2
0
        public override void Execute(XmlGame game, GamePlayer player)
        {
            _Message = String.Format("{0} played a Victory Point card"
                , player.XmlPlayer.ID);

            base.Execute(game, player);
        }
Example #3
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;
            }
        }
Example #4
0
        public override void Execute(XmlGame game, GamePlayer player)
        {
            player.DevRoadShips += 2;
            _Message = String.Format("{0} played a road building card", player.XmlPlayer.Name);

            base.Execute(game, player);
        }
Example #5
0
        public override void Execute(XmlGame game, GamePlayer player)
        {
            StringBuilder msg = new StringBuilder();
            msg.Append(String.Format("{0} stole ", player.XmlPlayer.Name));

            foreach (GamePlayer gamePlayer in game.Players)
            {
                //steal only form opponents
                if (!gamePlayer.XmlPlayer.Equals(player.XmlPlayer.ID))
                {
                    // and only if he has the type of resource
                    if (gamePlayer.Resources[Resource, true] > 0)
                    {
                        // add resources by the development card owner
                        player.Resources[Resource, true] += gamePlayer.Resources[Resource, true];

                        msg.Append(String.Format("{0} {1} from {2}, ",
                            gamePlayer.Resources[Resource, true], Resource.ToString(), gamePlayer.XmlPlayer.Name));

                        // remove resources at victims
                        gamePlayer.Resources[Resource, true] = 0;
                    }
                }
            }

            // remove the trailing ","
            _Message = msg.ToString().Substring(0, msg.ToString().Length - 2);

            base.Execute(game, player);
        }
Example #6
0
        /// <summary>
        /// Constructs based on XML game.
        /// </summary>
        /// <param name="xmlGame">Parsed game from PinballX XML database</param>
        public AggregatedGame([NotNull] PinballXGame xmlGame) : this(Locator.Current)
        {
            Update(xmlGame);
            FileId = Path.Combine(xmlGame.System.TablePath, xmlGame.FileName);

            // Unlink local file when table path changes.
            XmlGame.WhenAnyValue(g => g.System.TablePath).Subscribe(newPath => ClearLocalFile());
        }
Example #7
0
        public override void Execute(XmlGame game, GamePlayer player)
        {
            // Update largest army
            game.CalculateLargestArmy(player);

            _Message = String.Format("{0} played a soldier", player.XmlPlayer.Name);

            base.Execute(game, player);
        }
Example #8
0
        public override void Execute(XmlGame game, GamePlayer player)
        {
            _Message = String.Format("{0} gained {1} by playing a Year of Plenty card",
                player.XmlPlayer.Name, Resources.ToString());

            // give player the resources
            player.Resources.AddCards(Resources);

            base.Execute(game, player);
        }
Example #9
0
 public virtual bool AllowedAction(InGameAction inGameAction, XmlGame game)
 {
     if (_AllowedActions.Contains(inGameAction.GetType()))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Example #10
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);
 }
Example #11
0
 /// <summary>
 /// Updates XML game.
 /// </summary>
 /// <param name="xmlGame">Parsed game from PinballX XML database</param>
 /// <returns>This instance</returns>
 public AggregatedGame Update(PinballXGame xmlGame)
 {
     if (XmlGame == null)
     {
         XmlGame = xmlGame;
     }
     else
     {
         XmlGame.Update(xmlGame);
     }
     return(this);
 }
Example #12
0
        public override bool AllowedAction(InGameAction inGameAction, XmlGame game)
        {
            if (!base.AllowedAction(inGameAction, game))
                return false;

            // Check if we are allowed to trade
            TradeOfferAction tradeOffer = inGameAction as TradeOfferAction;
            if (tradeOffer != null && !game.Settings.TradingAfterBuilding)
                return false;

            // Default on returning true
            return true;
        }
Example #13
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;
            }
        }
Example #14
0
        public override bool IsAllowed(InGameAction inGameAction, XmlGame game)
        {
            if (!base.IsAllowed(inGameAction, game)) return false;

            // When a placeport action is preformed, the action should be originating
            // from the expected player on the actionsqueue
            PlacePortAction placePort = inGameAction as PlacePortAction;
            if (placePort != null)
            {
                if (placePort.Sender != game.ActionsQueue.Peek().Sender)
                {
                    return false;
                }
            }

            return true;
        }
        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;
            }
        }
Example #16
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");
     }
 }
Example #17
0
        public override void ProcessAction(InGameAction inGameAction, XmlGame game)
        {
            ClaimVictoryAction claimVictory = inGameAction as ClaimVictoryAction;
            if (claimVictory != null)
            {
                _TurnPhase.ProcessAction(inGameAction, game);
                return;
            }

            PlacementDoneAction placementDone = inGameAction as PlacementDoneAction;
            if (placementDone != null)
            {
                _TurnPhase.ProcessAction(inGameAction, game);
                return;
            }
            EndTurnAction endTurn = inGameAction as EndTurnAction;
            if (endTurn != null)
            {
                _TurnPhase = new BeforeDiceRollTurnPhase();
                endTurn.PerformTurnAction(game);
                return;
            }
            // Process the actual in the current turnphase
            TurnPhase next = _TurnPhase.ProcessAction(inGameAction, game);

            // If return phase does not match current phase, we have to switch phases and process the action
            // again
            if (_TurnPhase != next)
            {
                _TurnPhase = next;
                _TurnPhase = _TurnPhase.ProcessAction(inGameAction, game);
            }

            // When the incoming action is not valid, check if it's valid in the next phase.
            // If so, switch phases
            if (!_TurnPhase.AllowedAction(inGameAction, game))
            {
                if (_TurnPhase.Next().AllowedAction(inGameAction, game))
                {
                    _TurnPhase = _TurnPhase.Next();
                }
            }
        }
Example #18
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            if (Resource == EResource.Volcano)
            {
                _InvalidMessage = "Cannot monopoly on volcano resource";
                return false;
            }
            if (Resource == EResource.Gold)
            {
                _InvalidMessage = "Cannot monopoly gold resource";
                return false;
            }
            if (Resource == EResource.Discovery)
            {
                _InvalidMessage = "Cannot monopoly discovery resource";
            }

            return true;
        }
Example #19
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);
                }

            }
        }
 public override GamePhase Next(XmlGame game)
 {
     // Determine if we should skip placing ports
     // randomports are assigned at start using the port lists on each territory.
     // The remaining ports are placed in the placement phase
     List<EPortType> allPorts = new List<EPortType>();
     foreach (Territory t in game.Board.Territories)
     {
         foreach (EPortType p in t.PortList)
         {
             allPorts.Add(p);
         }
     }
     if (allPorts.Count == 0)
     {
         // We do not have any ports to set, skip to placement phase
         return new PlacementGamePhase();
     }
     else
     {
         // players should place ports
         return new PlacePortGamePhase();
     }
 }
Example #21
0
 public override void Start(XmlGame game)
 {
     game.ActionsQueue.Enqueue(new PlacementDoneAction()
     {
         Sender = 0
     });
 }
Example #22
0
 public virtual void ProcessAction(InGameAction inGameAction, XmlGame game)
 {
     // base class should implement
     throw new NotImplementedException();
 }
Example #23
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            return true;
        }
Example #24
0
 public virtual void Start(XmlGame game)
 {
     throw new NotImplementedException();
 }
Example #25
0
 /// <summary>
 /// Checks if the XML game is equal, i.e. the data is equal (to
 /// check if it should be updated).
 /// </summary>
 /// <param name="xmlGame">XML game to compare</param>
 /// <returns>True if equal, false otherwise</returns>
 public bool EqualsXmlGame(PinballXGame xmlGame)
 {
     return(XmlGame != null && XmlGame.Equals(xmlGame));
 }
 public override bool AllowedAction(InGameAction inGameAction, XmlGame game)
 {
     return base.AllowedAction(inGameAction, game);
 }
Example #27
0
 public virtual TurnPhase ProcessAction(InGameAction action, XmlGame game)
 {
     throw new NotImplementedException();
 }
Example #28
0
 public override GamePhase Next(XmlGame game)
 {
     return new PlacementGamePhase();
 }
Example #29
0
        // Each player should place a town+road
        public override void Start(XmlGame game)
        {
            // Expect each player to place town/road - town/road
            int i = 0;
            bool back = false;

            // A loop going backward. Each index should be hit twice.
            // Example with 4 players: p1 - p2 - p3 - p4 - p4 - p3 - p2 - p1
            while (i > -1)
            {
                // If tournament starting rules are set, second building should be a city
                if (back && game.Settings.TournamentStart)
                {
                    // Tournamanet starting rules, add a city
                    game.ActionsQueue.Enqueue(new BuildCityAction()
                    {
                        GamePlayer = game.Players[i]
                    });
                }
                else
                {
                    // Normal starting rules, add two towns
                    game.ActionsQueue.Enqueue(new BuildTownAction()
                    {
                        GamePlayer = game.Players[i]
                    });
                }

                // This action actually might be a BuildShipAction too.
                // TODO: implement this somewhere
                game.ActionsQueue.Enqueue(new BuildRoadAction()
                {
                    GamePlayer = game.Players[i]
                });

                // if the "back" flag is set, we should decrease the counter
                if (back)
                {
                    i--;
                }
                else
                {
                    i++;
                }

                // flip the flag when counter reaches maximum value
                // (maximum value equals amount of players)
                if (i == game.Players.Count)
                {
                    // next loop is walked with same maximum value
                    i--;

                    // switch flag
                    back = true;
                }
            }

            // When in tournament phase, very player may build a third road
            if (game.Settings.TournamentStart)
            {
                for (int j = 0; j < game.Players.Count; j++)
                {
                    game.ActionsQueue.Enqueue(new BuildRoadAction()
                    {
                        GamePlayer = game.Players[j]
                    });
                }
            }
        }
Example #30
0
 public override GamePhase Next(XmlGame game)
 {
     return new PlayTurnsGamePhase();
 }
Example #31
0
 public override GamePhase Next(XmlGame game)
 {
     return new EndedGamePhase();
 }
Example #32
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;
            }
        }
Example #33
0
 public override bool IsAllowed(InGameAction inGameAction, XmlGame game)
 {
     return _TurnPhase.AllowedAction(inGameAction, game);
 }