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

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

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

            // we can't contain ourself for now, not needed yet
            if (Actions.OfType<InGameActionsAction>().Count() > 0)
            {
                _InvalidMessage = "We cannot contain another list ourselves";
                return false;
            }

            // all containing turns must be valid also
            XmlGame gameCopy = game.Copy();
            foreach (InGameAction action in Actions)
            {
                if (!action.IsValid(game))
                {
                    _InvalidMessage = String.Format("A game in the list of games failed to validate:/r/n{0}",
                        action.InvalidMessage);
                    return false;
                }
                // perform the action so the state of the game gets updated for
                // the next action
                action.PerformTurnAction(gameCopy);
            }

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

            if (Trade == null)
            {
                _InvalidMessage = "The trade object cannot be null";
                return false;
            }

            if (Trade.Sender == 0)
            {
                _InvalidMessage = "Player to trade with cannot be the server (ID=0)";
                return false;
            }

            if (!Trade.IsValid())
            {
                _InvalidMessage = Trade.InvalidMessage;
                return false;
            }
            // TODO: check if trade is valid

            return true;
        }
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            // we need a good location
            if (Location == null)
            {
                _InvalidMessage = "Location can't be null";
                return false;
            }

            // Make sure the player does not put robber or pirate on the edge of the map,
            // which is forbidden
            // TODO: remove assumption edge of map equals boundaries of array
            // possible solutions:
            // -on map serialization determine an edgemap, include edgemap property
            //
            if (Location.H == 0 ||
                Location.W == 0 ||
                Location.H >= game.Board.Height ||
                Location.W >= game.Board.Width)
            {
                _InvalidMessage = "putting robber on the edge is not allowed";
                return false;
            }

            // TODO: check if a previous action included rolling a 7,
            // or playing a soldier development card

            // Player may not leave the robber on the same location
            if (game.Robber.Equals(Location))
            {
                _InvalidMessage = "putting robber back onto same location is not allowed";
                return false;
            }

            // valid hexes include:
            // -seahexes for pirate
            // -ordinary resource hexes
            // -volcano's
            // -jungle's
            //
            // invalid places include:
            // -Randomhex
            // -Nonehex
            // -DiscoveryHex
            // -

            Hex hex = game.Board.Hexes[Location];

            if (hex is NoneHex ||
                hex is DiscoveryHex ||
                hex is RandomHex)
            {
                _InvalidMessage = "Can't place robber or pirate on a " + hex.GetType().Name;
                return false;
            }

            return true;
        }
Пример #5
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;
            }
        }
Пример #6
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;
        }
Пример #7
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game)) return false;

            //if (_VolcanosRolled == null)
               // {
            //    _InvalidMessage = "No volcanoes to roll for";
            //    return false;
            //}
            //if (RollDice == null)
            //{
            //    _InvalidMessage = "RollDice of type RolDiceAction can't be null";
            //    return false;
            //}
            /*
            if (Dice != 1 &&
                Dice != 2 &&
                Dice != 3 &&
                Dice != 4 &&
                Dice != 5 &&
                Dice != 6)
            {
                _Message = "We use cubes as dice. Number 1-6 please";
                return false;
            }
             */

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

            if (Resources == null || Amount == 0)
            {
                _InvalidMessage = "Resources or amount cannot be null or 0";
                return false;
            }

            //Bank should have the picked resources
            if (!game.Bank.HasAtLeast(Resources))
            {
                _InvalidMessage = String.Format("Bank does not have {0}",
                    Resources);
                return false;
            }

            if (Amount != Resources.CountAllExceptDiscovery)
            {
                _InvalidMessage = "Amount of gold should be equal to the amount of picked resources";
                return false;
            }

            return true;
        }
        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);
        }
Пример #10
0
 public void SetData(XmlGame game)
 {
     // Create a list of pickgoldActions. If player should not pick gold, add it anyways but
     // set the amount to 0.
     List<PickGoldAction> pickGoldActions = new List<PickGoldAction>();
     foreach (GamePlayer player in game.Players)
     {
         var shouldPickGold = game.ActionsQueue.OfType<PickGoldAction>()
             .Where(pga => pga.Sender == player.XmlPlayer.ID)
             .FirstOrDefault();
         if (shouldPickGold == null)
         {
             pickGoldActions.Add(new PickGoldAction()
             {
                 Sender = player.XmlPlayer.ID,
                 Amount = 0
             });
         }
         else
         {
             pickGoldActions.Add(shouldPickGold);
         }
     }
     _PickGoldActions = pickGoldActions;
     uiPlayer.ItemsSource = _PickGoldActions;
     _BankResources = game.Bank;
 }
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid(game))
                return false;

            return true;
        }
Пример #12
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;
        }
Пример #13
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            // set current player to winner
            xmlGame.PlayerOnTurn = xmlGame.Players[0];

            _Message = String.Format("{0} should start. Waiting for {0} to roll the dice", GamePlayer.XmlPlayer.Name);

            base.PerformTurnAction(xmlGame);
        }
Пример #14
0
        public override void PerformTurnAction(XmlGame xmlGame)
        {
            XmlUser spectator = xmlGame.Spectators.Find(user => user.ID == Sender);

            xmlGame.Spectators.Remove(spectator);

            _Message = String.Format("Spectator {0} left the game.",
                spectator.Name);
        }
Пример #15
0
 /// <summary>
 /// Calculate three possible locations for the road to be placed at placement gamephase
 /// </summary>
 /// <param name="game"></param>
 /// <param name="board"></param>
 /// <param name="townOrCity"></param>
 public RoutePlaces(XmlGame game, BoardVisual board, HexPoint townOrCity)
 {
     // Add each side to children
     foreach (HexSide side in townOrCity.GetNeighbourSides)
     {
         Point2D newPoint = board.CalculatePosition(side);
         HexSideVisual newHexSide = new HexSideVisual(newPoint, side);
         Children.Add(newHexSide);
     }
 }
Пример #16
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());
        }
Пример #17
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);
        }
Пример #18
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);
        }
Пример #19
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;
        }
Пример #20
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);
        }
Пример #21
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);
        }
Пример #22
0
 public bool IsSecond(XmlGame game)
 {
     if (game.Settings.TournamentStart)
         return false;
     else
     {
         if (game.GameLog.OfType<BuildTownAction>().Count() < (game.Players.Count * 2))
             return true;
         else
             return false;
     }
 }
Пример #23
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);
        }
Пример #24
0
        public override bool IsValid(XmlGame game)
        {
            if (!base.IsValid()) return false;

            if (String.IsNullOrEmpty(Message))
            {
                _InvalidMessage = "You gotta have something to say. Message IsNullOrEmpty.";
                return false;
            }

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

            if (game.PlayerOnTurn.XmlPlayer.ID != Sender)
            {
                _InvalidMessage = "A turnaction should always originate from the player on turn";
                return false;
            }

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

            if (game.Phase.GetType() != typeof(PlayTurnsGamePhase))
            {
                _InvalidMessage = "Wrong gamephase: expected playTurns gamephase";
                return false;
            }

            return true;
        }
Пример #27
0
        private List<HexSide> OpponentsRoadsShips(XmlGame game)
        {
            List<HexSide> result = new List<HexSide>();

            foreach (GamePlayer player in game.Players)
            {
                if (player.XmlPlayer.Name != game.PlayerOnTurn.XmlPlayer.Name)
                {
                    foreach (HexSide road in player.Roads) result.Add(road);
                    foreach (HexSide ship in player.Ships) result.Add(ship);
                }
            }

            return result;
        }
Пример #28
0
 /// <summary>
 /// Calculate all possible positions to build a ship or a road
 /// </summary>
 /// <param name="game"></param>
 /// <param name="board"></param>
 /// <param name="ships"></param>
 public RoutePlaces(
     XmlGame game,
     BoardVisual board,
     bool ships)
 {
     if (ships)
     {
         foreach (HexSide side in game.PlayerOnTurn.GetShipBuildPlaces(game, board.Board))
             Children.Add(new HexSideVisual(board.CalculatePosition(side), side));
     }
     else
     {
         foreach (HexSide side in game.PlayerOnTurn.GetRoadBuildPlaces(game, board.Board))
             Children.Add(new HexSideVisual(board.CalculatePosition(side), side));
     }
 }
Пример #29
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;
        }
        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);
        }