Пример #1
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            if (Intersection == null)
            {
                _InvalidMessage = "Intersection can't be null";
                return false;
            }
            if (game.GetPlayer(Sender).Ships.Contains(Intersection))
            {
                _InvalidMessage = "location is already taken";
                return false;
            }

            GamePlayer player = game.GetPlayer(base.Sender);

            if (game.Phase.GetType() != typeof(PlacementGamePhase))
            {
                if (!player.CanBuildShip(game, game.Board))
                {
                    _InvalidMessage = "Player cannot build the ship";
                    return false;
                }

                if (!player.CanPayShip)
                {
                    _Message = "Player cannot pay for the ship";
                    return false;
                }
            }

            return true;
        }
Пример #2
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            _Message = String.Format("{0} said: {1}", xmlGame.GetPlayer(Sender), ChatMessage);
            //xmlGame.GameChat.

            base.PerformTurnAction(xmlGame);
        }
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer player = xmlGame.GetPlayer(Sender);

            // Old owner looses route
            if (xmlGame.LongestRouteOwner != null)
            {
                xmlGame.LongestRouteOwner.LongestRoute = null;
            }

            // New owner gets route
            player.LongestRoute = Route;

            if (Route == null)
            {
                _Message = String.Format("No one gets a new route!");
            }
            else
            {
                _Message = String.Format("{0} has the longest route of length {1}",
                    player.XmlPlayer.Name, Route.Count);
            }

            base.PerformTurnAction(xmlGame);
        }
Пример #4
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            if (DevCard == null)
            {
                _InvalidMessage = "Devcard cannot be null";
                return false;
            }

            GamePlayer player = game.GetPlayer(Sender);
            if (!DevCard.IsPlayable)
            {
                _InvalidMessage = "You already played a non-victorypoint devcard this turn, or your devcards are bought this turn";
                return false;
            }

            if (!DevCard.IsPlayable)
            {
                _InvalidMessage = "Development card is not playable. Wait one turn";
            }

            if (!DevCard.IsValid(game))
            {
                _InvalidMessage = "Development card is not valid";
                return false;
            }

            return true;
        }
Пример #5
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            gamePlayer.Resources.SubtractCards(ResourcesLost);
            xmlGame.Bank.AddCards(ResourcesLost);

            _Message = String.Format("{0} lost {1}",
                gamePlayer.XmlPlayer.Name, ResourcesLost.ToString());
        }
Пример #6
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            xmlGame.Phase = xmlGame.Phase.Next(xmlGame);
            xmlGame.WinnerID = Sender;
            GamePlayer player = xmlGame.GetPlayer(Sender);
            _Message = String.Format("{0} successfully claimed victory and won the game!",
                player.XmlPlayer.Name);

            base.PerformTurnAction(xmlGame);
        }
Пример #7
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            _Message = String.Format("{0} offered to trade {1} for {2}",
                gamePlayer.XmlPlayer.Name, OfferedCards.ToString(),
                WantedCards.ToString());

            base.PerformTurnAction(xmlGame);
        }
Пример #8
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;
            // we need at least an instance of the new place
            if (Location == null)
            {
                _InvalidMessage = "Location cannot be null";
                return false;
            }

            //
            if (game.AllTownsCities().Contains(Location))
            {
                _InvalidMessage = "The spot and its neighbours is already used by anyone";
                return false;
            }

            // player should have a ship or road at some neighbour
            GamePlayer player = game.GetPlayer(base.Sender);
            if (game.Phase.GetType() == typeof(PlayTurnsGamePhase))
            {
                List<HexSide> roadsShips = player.GetRoadsShips();
                List<HexSide> neighbours = Location.GetNeighbourSides;

                if (!roadsShips.Contains(neighbours[0]) &&
                    !roadsShips.Contains(neighbours[1]) &&
                    !roadsShips.Contains(neighbours[2]))
                {
                    _InvalidMessage = "No ship or road found at neighbouring  location";
                    return false;
                }

                if (!player.CanPayTown)
                {
                    _Message = "Player cannot pay for the town";
                    return false;
                }

                if (!player.CanBuildTown(game, game.Board))
                {
                    _InvalidMessage = "Player cannot build the town";
                    return false;
                }
            }

            // check if location is suitable (hexpoint neighbours can't be
            // already built on)

            // check if location is a valid one to built on
            // (contains at least a landhex)

            // couldnt find a neighbour, assume invalid state
            return true;
        }
Пример #9
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);
            // TODO: set trading player
            //GamePlayer tradePlayer = xmlGame.GetPlayer(AcceptedPlayerID);

            _Message = String.Format("{0} traded {1} for {2} with {3}",
                gamePlayer.XmlPlayer.Name, Trade.OfferedCards.ToString(),
                Trade.WantedCards.ToString(),"");// tradePlayer.XmlPlayer.Name);

            base.PerformTurnAction(xmlGame);
        }
Пример #10
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            gamePlayer.Ships.Remove(OldLocation);
            gamePlayer.Ships.Add(NewLocation);

            _Message = String.Format("{0} moved a ship from {1} to {2}",
                gamePlayer.XmlPlayer.Name, OldLocation.ToString(), NewLocation.ToString());

            base.PerformTurnAction(xmlGame);
        }
Пример #11
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            gamePlayer.Resources.AddCards(Resources);
            xmlGame.Bank.SubtractCards(Resources);

            _Message = String.Format("{0} gained {1} from his {2} gold resources",
                gamePlayer.XmlPlayer.Name, Resources.ToString(), Amount);

            base.PerformTurnAction(xmlGame);
        }
        /// Reorder players in consecutive order. First player becomes index 0, 
        /// players after that follow up by index number
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            // Check if we need to reorder the list
            if (xmlGame.Players[0] != xmlGame.GetPlayer(PlayerID))
            {
                // Make a new list
                List<GamePlayer> newList = new List<GamePlayer>();

                // Get index of winner
                int winnerIndex = xmlGame.Players.IndexOf(xmlGame.GetPlayer(PlayerID));

                for (int i = 0; i < xmlGame.Players.Count; i++)
                {
                    // Create index for the consecutive player
                    int followup = i + winnerIndex;

                    // compute remainder in case we overflow the index of the players list
                    followup %= xmlGame.Players.Count;

                    newList.Add(xmlGame.Players[followup]);
                }

                // Set the new players list reflecting the new order
                xmlGame.Players = newList;
            }

            GamePlayer player = xmlGame.GetPlayer(PlayerID);

            // First player will start the game
            xmlGame.PlayerOnTurn = xmlGame.Players[0];

            _Message = String.Format("{0} rolled {1}, so he is highroller",
                player.XmlPlayer.Name, DiceRoll);

            base.PerformTurnAction(xmlGame);
        }
Пример #13
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid()) return false;

            if (ResourcesLost == null)
            {
                _InvalidMessage = "ResourcesLost object cannot be null";
                return false;
            }

            if (ResourcesLost.CountAllExceptDiscovery == 0)
            {
                _InvalidMessage = "We cannot loose 0 cards";
                return false;
            }

            GamePlayer player = game.GetPlayer(base.Sender);
            int numResources = player.Resources.CountAllExceptDiscovery;

            // we should have more cards in hand than the maximum allowed
            if (numResources <= game.Settings.MaximumCardsInHandWhenSeven)
            {
                _InvalidMessage = "You should have more than the maximum allowed cards";
                return false;
            }

            // Player should have the resources he is trying to get rid off
            if (!player.Resources.HasAtLeast(ResourcesLost))
            {
                _InvalidMessage = String.Format("{0} does not have the specified resources ({1}) to loose",
                    player.XmlPlayer.Name, ResourcesLost.ToString());
                return false;
            }

            // player must ditch half of his cards, rounded down
            int half = (numResources % 2 == 0 ?
                numResources / 2 : (numResources - 1) / 2);

            if (ResourcesLost.CountAllExceptDiscovery != half)
            {
                _InvalidMessage = String.Format("You should get rid of {0} cards, not {1} cards",
                    half, ResourcesLost.CountAllExceptDiscovery);
                return false;
            }

            return true;
        }
Пример #14
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer player = xmlGame.GetPlayer(Sender);
            Chit chit = ((ResourceHex)xmlGame.Board.Hexes[OldLocation]).XmlChit;

            //remove old chit number
            ((ResourceHex)xmlGame.Board.Hexes[OldLocation]).XmlChit = null;

            //put chitnumber on new location
            ((ResourceHex)xmlGame.Board.Hexes[NewLocation]).XmlChit = chit;

            _Message = String.Format("{0} swapped a number chit from {1} to {2}",
                player.XmlPlayer.Name, OldLocation.ToString(xmlGame.Board),
                NewLocation.ToString(xmlGame.Board));

            base.PerformTurnAction(xmlGame);
        }
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            // set new owner of largest army
            GamePlayer player = xmlGame.GetPlayer(Sender);
            _GamePlayer = player;

            // reset old owner of largest army
            player.HasLargestArmy = true;
            foreach (GamePlayer p in xmlGame.Players)
                if (p != player && p.HasLargestArmy)
                    p.HasLargestArmy = false;

            _Message = String.Format("{0} is the mightiest of all players and gets largest army using {1} soldiers",
                player.XmlPlayer.Name, player.PlayedSoldierCount.ToString());

            base.PerformTurnAction(xmlGame);
        }
Пример #16
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            RolledSamePlayers = xmlGame.RolledSame(xmlGame.GameLog.GetCurrentRoundRolls(xmlGame), HighRoll);
            int i = 0;
            StringBuilder sb = new StringBuilder();

            // Create message
            foreach (int playedID in RolledSamePlayers)
            {
                i++;
                sb.Append(xmlGame.GetPlayer(playedID).XmlPlayer.Name);
                string divider = i == RolledSamePlayers.Count ? " and " : ", ";
                sb.Append(divider);
            }

            _Message = String.Format("{0} rolled a {1}, so they have to roll again",
                sb.ToString(), HighRoll.ToString());
        }
Пример #17
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            // we need at least an instance of the new place
            if (Location == null)
            {
                _InvalidMessage = "Location cant be null";
                return false;
            }

            // player should have a ship or road at some neighbour
            GamePlayer player = game.GetPlayer(base.Sender);

            //foreach (HexSide neighbour in Location.GetNeighbourSides)
            //    if (player.Ships.Contains(neighbour))
            //    {
            //        _InvalidMessage = "No neighbouring ship or road found";
            //        return false;
            //    }

            if (!(player.Towns.Contains(Location)))
            {
                _InvalidMessage = "No town found to replace with a city";
                return false;
            }
            if (game.Phase.GetType() == typeof(PlayTurnsGamePhase))
            {
                if (!player.CanBuildCity())
                {
                    _InvalidMessage = "Player cannot build the city";
                    return false;
                }

                if (!player.CanPayCity)
                {
                    _Message = "Player cannot pay for the city";
                    return false;
                }
            }

            // couldnt find a neighbour, assume invalid state
            return true;
        }
Пример #18
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            if (OfferedCards == null ||
                WantedCards == null)
            {
                _InvalidMessage = "Offered- or WantedCards can't be null";
                return false;
            }

            if (OfferedCards.CountAllExceptDiscovery < 1 ||
                WantedCards.CountAllExceptDiscovery < 1)
            {
                _InvalidMessage = "We must have something to offer and want";
                return false;
            }

            if (OfferedCards.Discoveries > 0 ||
                WantedCards.Discoveries > 0)
            {
                _InvalidMessage = "We cant trade discoveries";
                return false;
            }

            GamePlayer player = game.GetPlayer(Sender);

            if (!player.Resources.HasAtLeast(OfferedCards))
            {
                _InvalidMessage="player should have the resources in hand";
                return false;
            }

            if (game.GameLog.OfType<TradeOfferAction>()
                    .Where(to => to.TurnID == game.CurrentTurn)
                    .Count() >= game.Settings.MaximumTradesPerTurn)
            {
                _InvalidMessage = String.Format("Player has already offered {0} trades",
                    game.Settings.MaximumTradesPerTurn);
            }

            // we can't think of more exceptions here
            return true;
        }
Пример #19
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            // we need resources
            if (Resources == null) return false;

            // ...and to devcard too.
            if (game.DevCards.Count == 0)
            {
                _InvalidMessage = "Development cards are all gone!";
                return false;
            }

            // we need just three resources
            if (Resources.CountAll != 3) return false;

            // three or more discoveries is OK
            if (Resources.Discoveries > 2) return true;

            GamePlayer player = game.GetPlayer(base.Sender);

            if (!player.CanBuildRoad(game, game.Board))
            {
                _InvalidMessage = "Player cannot build the road";
                return false;
            }

            if (!player.Resources.HasAtLeast(Resources))
            {
                _InvalidMessage = "Player does not have given resources";
                return false;
            }

            if (!player.CanPayDevcard)
            {
                _InvalidMessage = "Player is not able to pay for development card";
                return false;
            }

            return true;
        }
Пример #20
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);
            if (DevCard is Soldier)
            {
                xmlGame.ActionsQueue.Enqueue(new PlaceRobberPirateAction()
                {
                    GamePlayer = gamePlayer
                });
            }

            DevelopmentCard devCardToRemove=null;

            //remove devcard from players hand
            foreach (DevelopmentCard devcard in gamePlayer.DevCards)
            {
                Type t = this.DevCard.GetType();
                if (devcard.ID == DevCard.ID)
                {
                    devCardToRemove = devcard;
                    break;
                }
            }

            gamePlayer.PlayedDevcards.Add(devCardToRemove);
            gamePlayer.DevCards.Remove(devCardToRemove);

            // Execute devcard
            devCardToRemove.Execute(xmlGame, gamePlayer);

            // Mark all other cards needing to wait one turn as unplayable, if we play a non-unique dvcard
            if (devCardToRemove.WaitOneTurn)
            {
                foreach (DevelopmentCard dc in gamePlayer.DevCards)
                    dc.IsPlayable = !dc.WaitOneTurn;
            }

            _Message = DevCard.Message;

            base.PerformTurnAction(xmlGame);
        }
Пример #21
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            // Set the turnID before we end the turn
            int currentTurn = xmlGame.CurrentTurn;

            GamePlayer player = xmlGame.GetPlayer(Sender);

            // Reset ability to play devcards
            foreach (DevelopmentCard dc in player.DevCards)
                dc.IsPlayable = true;

            xmlGame.PlayerOnTurn = xmlGame.NextPlayer;

            xmlGame.EndTurn();

            // Set the message
            _Message = String.Format("{0} ended turn.", player.XmlPlayer.Name);

            base.PerformTurnAction(xmlGame);

            _TurnID = currentTurn;
        }
Пример #22
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            bool usingRoadbuildingToken = false;
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            // in Ingame phase, player should pay for ship somehow
            if (xmlGame.Phase.GetType() == typeof(PlayTurnsGamePhase))
            {
                // Default on using a RoadBuilding development card token
                if (gamePlayer.DevRoadShips > 0)
                {
                    gamePlayer.DevRoadShips--;
                }
                else
                {
                    gamePlayer.Resources.SubtractCards(ResourceList.Ship);
                    xmlGame.Bank.AddCards(ResourceList.Ship);
                }

                // Check if the LR should be updated
                xmlGame.CalculateLongestRoad(gamePlayer);
            }
            else
            {
                // when in placement phase, ship is free
            }

            gamePlayer.StockShips--;
            gamePlayer.Ships.Add(Intersection);

            _Message = String.Format("{0} built a ship",
                xmlGame.GetPlayer(Sender).XmlPlayer.Name);

            if (usingRoadbuildingToken)
                _Message += ", using his Roadbuilding development card";

            base.PerformTurnAction(xmlGame);
        }
Пример #23
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            GamePlayer player = game.GetPlayer(base.Sender);

            if (OldLocation == null || NewLocation == null)
            {
                _Message = "OldLocation or NewLocation is null";
                return false;
            }

            if (!player.Ships.Contains(OldLocation))
            {
                _Message = String.Format("Cannot find a ship matching the OldLocation given at player {0}", player.XmlPlayer.Name);
                return false;
            }

            // we cannot move the ship to a spot an opponent owns
            if (game.AllRoadsShips().Contains(NewLocation))
            {
                _Message = String.Format("Some opponent already has a ship at location {0}", NewLocation.ToString());
                return false;
            }

               /*
            // new location either should have a town or a city
            if (townsCities.Contains(NewLocation.Hex1) ||
                townsCities.Contains(NewLocation.Hex2))
                return true;
            */

            //another ship is also OK as suitable location
            foreach (HexSide neighbour in NewLocation.GetNeighbours())
                if (player.Ships.Contains(neighbour)) return true;

            return false;
        }
Пример #24
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;
            if (Intersection == null)
            {
                _InvalidMessage = "Intersection cannot be null";
                return false;
            }

            // the spot must be free still
            if (game.AllRoadsShips().Contains(Intersection))
            {
                _InvalidMessage = "Already built on the given location";
                return false;
            }

            GamePlayer player = game.GetPlayer(base.Sender);

            if (game.Phase.GetType() == typeof(PlacementGamePhase))
            {
                if (!player.CanBuildRoad(game, game.Board))
                {
                    _InvalidMessage = "Player cannot build the road";
                    return false;
                }

                /*
                if (!player.CanPayRoad)
                {
                    _Message = "Player cannot pay for the road";
                    return false;
                }
                 */
            }

            return true;
        }
Пример #25
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game))
                return false;

            GamePlayer robbedPlayer = null;

            if (PlayerID != null)
            {
                robbedPlayer = game.GetPlayer((int)PlayerID);
            }

            if (PlayerID == 0)
            {
                _InvalidMessage = "We can't rob the server!";
                return false;
            }

            // .
            if (robbedPlayer == null &&
                PlayerID != null)
            {
                _InvalidMessage = "Either we should rob no one, or we should rob someone";
                return false;
            }
            // TODO: check if the robbed player has a town or city on one
            // of the 6 points

            //
            if (robbedPlayer != null)
            {
                _InvalidMessage = "The player should have something to be robbed";
                if (robbedPlayer.Resources.CountAllExceptDiscovery == 0) return false;
            }

            return true;
        }
Пример #26
0
        /// <summary>
        /// Determines the winner of the TradeRoute
        /// </summary>
        /// <param name="game"></param>
        /// <returns></returns>
        public GamePlayer Winner(XmlGame game, GamePlayer player)
        {
            int playerCount = this.Where(rn => rn.PlayerID == player.XmlPlayer.ID).Count();
            var opponentIDs = this.Where(rn => rn.PlayerID !=player.XmlPlayer.ID);
            int opponentID=0;
            if (opponentIDs.Count() >0)
                opponentID=opponentIDs.First().PlayerID;
            if (opponentID != 0)
            {
                int ships = GetShipCount(player.XmlPlayer.ID);
                int opponentShips=GetShipCount(opponentID);

                if (ships > opponentShips)
                    return player;

                if (ships < opponentShips)
                    return game.GetPlayer(opponentID);
                else
                // we have equal amount of ships, decide on earliest route
                {
                    return null;
                    //TODO: lookup the trade route
                }
            }
            else
            // no opponents, return current player
            {
                return player;
            }
        }
Пример #27
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            _playersResources = new Dictionary<Gaming.GamePlayer, ResourceList>();
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            if (xmlGame.Phase is PlayTurnsGamePhase)
            {
                if (Dice != 7)
                {
                    // gather all resource hexes without the robber
                    IEnumerable<ResourceHex> rolledHexes =
                        from h in xmlGame.Board.Hexes.OfType<ResourceHex>()
                        where h.XmlChit != null &&
                            // we need a chit with the same number as rolled dice
                        h.XmlChit.ChitNumber == Chit.GetChitNumber(Dice)
                        select h;

                    bool volcanoRolled = false;

                    // Iterate over all hexes with resources
                    foreach (ResourceHex hex in rolledHexes)
                    {
                        if (!volcanoRolled && hex is VolcanoHex)
                        {
                            volcanoRolled = true;
                        }
                        // For normal resources, the location of the robber is omitted.
                        if (!hex.Location.Equals(xmlGame.Robber))
                        {
                            foreach (GamePlayer player in xmlGame.Players)
                            {
                                // make a list of cities
                                IEnumerable<HexPoint> citiesOnHex =
                                    from city in player.Cities
                                    where city.HasLocation(hex.Location)
                                    select city;

                                IEnumerable<HexPoint> townsOnHex =
                                    from town in player.Towns
                                    where town.HasLocation(hex.Location)
                                    select town;

                                ResourceList gainedResources = new ResourceList();
                                gainedResources.AddResources(
                                    hex.Resource, (citiesOnHex.Count() * 2) + townsOnHex.Count());

                                //update gamestate
                                player.Resources.AddCards(gainedResources);
                                xmlGame.Bank.SubtractCards(gainedResources);
                                if (!_playersResources.Keys.Contains(player))
                                {
                                    //add new entry when no resources registered yet
                                    _playersResources.Add(player, gainedResources);
                                }
                                else
                                {
                                    // we already gained resources, add resources from current hex
                                    _playersResources[player].AddCards(gainedResources);
                                }
                            } // Robber
                        } // Foreach hex

                        _HexesAffected.Add(hex);
                    }

                    // Remove gold from resourcesGained, add PickGoldAction for each player with gold
                    foreach (KeyValuePair<GamePlayer, ResourceList> kvp in _playersResources)
                    {
                        if (kvp.Value.Gold > 0)
                        {
                            xmlGame.ActionsQueue.Enqueue(new PickGoldAction()
                            {
                                GamePlayer = kvp.Key,
                                Amount = kvp.Value.Gold
                            });
                        }
                        kvp.Key.Resources.Gold = 0;
                    }

                    // If there is a volcano producing stuff, expect player to roll for the volcano number
                    if (volcanoRolled)
                    {
                        xmlGame.ActionsQueue.Enqueue(new RollVolcanoDiceAction()
                        {
                            GamePlayer = _GamePlayer
                        });
                    }

                    _Message = String.Format("{0} rolled {1} ({2} + {3})",
                        gamePlayer.XmlPlayer.Name, Dice, Dice1, Dice2);
                }
                else
                {
                    // Rolled a 7, create list of players to loose cards
                    string playerList = string.Empty;

                    foreach (GamePlayer p in xmlGame.Players)
                    {
                        if (p.Resources.Count > xmlGame.Settings.MaximumCardsInHandWhenSeven)
                        {
                            _LooserPlayers.Add(p.XmlPlayer.ID);
                            // Add comma and playername to message
                            playerList += _LooserPlayers.Count > 0 ?
                                ", " + p.XmlPlayer.Name : p.XmlPlayer.Name;
                        }
                    }

                    _Message = String.Format("{0} rolled a 7.", playerList);

                    if (_LooserPlayers.Count > 0)
                    {
                        _Message = String.Format("{0}{1} loose half of their resources", _Message, playerList);
                    }
                }
            }

            _User = gamePlayer.XmlPlayer;
            base.PerformTurnAction(xmlGame);
        }
Пример #28
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            if (PlayerID == null)
            {
                _Message = String.Format("{0} stole nothing! How refreshing", xmlGame.GetPlayer(Sender).XmlPlayer.Name);
            }
            else
            {
                // Rob the player
                GamePlayer robbedPlayer = xmlGame.GetPlayer((int)PlayerID);
                robbedPlayer.Resources.RemoveResource(StolenResource);

                // Give card to robbing player
                GamePlayer player = xmlGame.GetPlayer(Sender);
                player.Resources.AddResource(StolenResource);

                _Message = String.Format("{0} stole 1 {1} from {2}",
                    player.XmlPlayer.Name, StolenResource.ToString(), robbedPlayer.XmlPlayer.Name);
            }

            base.PerformTurnAction(xmlGame);
        }
Пример #29
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            GamePlayer gamePlayer = xmlGame.GetPlayer(Sender);

            // Perform  resources administration
            gamePlayer.Resources.SubtractCards(Resources);
            xmlGame.Bank.AddCards(Resources);

            // Player should wait a turn before able to play new devcard
            DevCard.IsPlayable = !DevCard.WaitOneTurn;
            DevCard.TurnBought = xmlGame.CurrentTurn;

            // Administer devcards
            gamePlayer.DevCards.Add(DevCard);
            xmlGame.DevCards.Remove(DevCard);

            _Message = String.Format("{0} bought a development card",
                gamePlayer.XmlPlayer.Name);

            base.PerformTurnAction(xmlGame);
        }
Пример #30
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;
            if (OfferedCards == null || WantedCards == null)
            {
                _InvalidMessage = "OfferedCards or WantedCards cannot be null";
                return false;
            }

            if (OfferedCards.CountAllExceptDiscovery < 2)
            {
                _InvalidMessage = "We need at least two cards to offer the bank";
                return false;
            }

            // we need at least one card to want from the bank
            if (WantedCards.CountAllExceptDiscovery < 1)
            {
                _InvalidMessage = "We need at least one card to want from the bank";
                return false;
            }

            GamePlayer player = game.GetPlayer(base.Sender);

            // check if the player has the offered cards in hand
            if (!player.Resources.HasAtLeast(OfferedCards)) return false;

            int portDivider = 4;
            // check if the offer is valid
            if (OfferedCards.Timber > 0)
            {
                portDivider = 4;
                if (player.Ports.ThreeToOne > 0) portDivider = 3;
                if (player.Ports.Timber > 0) portDivider = 2;

                // return invalid state if the trade isnt even
                if (OfferedCards.Timber % portDivider != 0)
                {
                    _InvalidMessage = String.Format("We need {0} timber resources to trade", portDivider);
                    return false;
                }
            }
            if (OfferedCards.Wheat > 0)
            {
                portDivider = 4;
                if (player.Ports.ThreeToOne > 0) portDivider = 3;
                if (player.Ports.Wheat > 0) portDivider = 2;
                if (OfferedCards.Wheat % portDivider != 0)
                {
                    _InvalidMessage = String.Format("We need {0} wheat resources to trade", portDivider);
                    return false;
                }
            }
            if (OfferedCards.Ore > 0)
            {
                portDivider = 4;
                if (player.Ports.ThreeToOne > 0) portDivider = 3;
                if (player.Ports.Ore > 0) portDivider = 2;
                if (OfferedCards.Ore % portDivider != 0)
                {
                    _InvalidMessage = String.Format("We need {0} ore resources to trade", portDivider);
                    return false;
                }
            }
            if (OfferedCards.Clay > 0)
            {
                portDivider = 4;
                if (player.Ports.ThreeToOne > 0) portDivider = 3;
                if (player.Ports.Clay > 0) portDivider = 2;
                if (OfferedCards.Clay % portDivider != 0)
                {
                    _InvalidMessage = String.Format("We need {0} clay resources to trade", portDivider);
                    return false;
                }
            }
            if (OfferedCards.Sheep > 0)
            {
                portDivider = 4;
                if (player.Ports.ThreeToOne > 0) portDivider = 3;
                if (player.Ports.Sheep > 0) portDivider = 2;
                if (OfferedCards.Sheep % portDivider != 0)
                {
                    _InvalidMessage = String.Format("We need {0} sheep resources to trade", portDivider);
                    return false;
                }
            }

            return true;
        }