示例#1
0
 internal void AddNewUnitsToPlayer(Player player, int numberOfNewUnits)
 {
     for (int i = 0; i < numberOfNewUnits; i++)
     {
         var unit = new Unit(player);
         NewUnits.Add(unit);
     }
 }
示例#2
0
 public Unit(Player player)
 {
     Killed = false;
     MoveCommand = null;
     NewUnit = true;
     PlaceCommand = null;
     Player = player;
 }
        public AllianceProposal(Player fromPlayer, Player toPlayer)
        {
            if (fromPlayer.Color == toPlayer.Color)
            {
                throw new ApplicationException("Cannot propose an alliance with oneself.");
            }

            FromPlayer = fromPlayer;
            ToPlayer = toPlayer;
        }
        public AlliancePair(Player playerA, Player playerB)
        {
            if (playerA.Color == playerB.Color)
            {
                throw new ApplicationException("A player cannot ally with oneself.");
            }

            // Always order the players in a consistent way.
            if (Compare(playerA.Color, playerB.Color, StringComparison.Ordinal) < 0)
            {
                PlayerA = playerA;
                PlayerB = playerB;
            }
            else
            {
                PlayerA = playerB;
                PlayerB = playerA;
            }
        }
示例#5
0
        private int GetNumberOfNewUnitsForPlayer(Player player)
        {
            int newUnitsThisTurn = Settings.NewUnitsPerTurn;
            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (Settings.NewUnitPerCellsControlled != 0)
            {
                newUnitsThisTurn += NextTurn.NumberOfControlledCells(player) / Settings.NewUnitPerCellsControlled;
            }

            return newUnitsThisTurn;
        }
示例#6
0
        private void AddStartingUnitsToTheBoard(Player player, int playerNumber, int numberOfUnits, int numberOfPlayers)
        {
            Hex ne = new Hex(GridSize, 0, -GridSize);
            Hex e = new Hex(GridSize, -GridSize, 0);
            Hex se = new Hex(0, -GridSize, GridSize);
            Hex sw = new Hex(-GridSize, 0, GridSize);
            Hex w = new Hex(-GridSize, GridSize, 0);
            Hex nw = new Hex(0, GridSize, -GridSize);

            Hex startingHex;
            switch (playerNumber)
            {
                case 0:
                    startingHex = ne;
                    break;

                case 1:
                    switch (numberOfPlayers)
                    {
                        case 2:
                            startingHex = sw;
                            break;
                        case 3:
                        case 4:
                            startingHex = se;
                            break;

                        default:
                            startingHex = e;
                            break;
                    }
                    break;

                case 2:
                    switch (numberOfPlayers)
                    {
                        case 3:
                            startingHex = w;
                            break;

                        case 4:
                            startingHex = sw;
                            break;

                        default:
                            startingHex = se;
                            break;
                    }
                    break;

                case 3:
                    switch (numberOfPlayers)
                    {
                        case 4:
                            startingHex = nw;
                            break;

                        default:
                            startingHex = sw;
                            break;
                    }
                    break;

                case 4:
                    startingHex = w;
                    break;

                case 5:
                    startingHex = nw;
                    break;

                default:
                    throw new ApplicationException("Only supports up to 6 players.");
            }

            Cell unitCell = NextTurn.GetCell(startingHex);

            for (int i = 0; i < numberOfUnits; i++)
            {
                Unit unit = new Unit(player);
                unitCell.AddUnit(unit);
            }
        }
示例#7
0
 private void AddPointsToPlayer(Player player)
 {
     player.PointsLastTurn = NextTurn.NumberOfControlledCells(player);
     player.Points += player.PointsLastTurn;
 }
示例#8
0
        private Player AddPlayer(Guid id)
        {
            lock (AddPlayerLock)
            {
                if (NumberOfPlayers == MaximumNumberOfPlayers)
                {
                    throw new TooManyPlayersException(MaximumNumberOfPlayers);
                }

                if (Started)
                {
                    throw new GameStartedException();
                }

                Player player = new Player(id, PlayersData[NumberOfPlayers].Color, PlayersData[NumberOfPlayers].Name, NumberOfPlayers);
                Players.Add(player);

                return player;
            }
        }
示例#9
0
        public void SetAllPlayersSeemToBeHere(Player player, bool allSeemToBeHere)
        {
            lock (SetAllPlayersSeemToBeHereLock)
            {
                player.Ready = allSeemToBeHere;

                if (Players.All(p => p.Ready))
                {
                    StartGame();
                }
            }
        }
示例#10
0
        /// <summary>Returns the NextTurn board, but only with the specified player's commands.</summary>
        public Turn GetCurrentTurn(Player player)
        {
            var currentTurn = NextTurn.Clone();

            var playersUnitsOnCells = currentTurn.UnitsOnCells.Where(unit => unit.Player.Color != player.Color);
            foreach (var unit in playersUnitsOnCells)
            {
                unit.RemoveMoveCommand();
            }

            var playersNewUnits = currentTurn.NewUnits.Where(unit => unit.Player.Color != player.Color);
            foreach (var unit in playersNewUnits)
            {
                unit.RemovePlaceCommand();
            }

            currentTurn.AllianceProposals.RemoveWhere(proposal => proposal.FromPlayer.Color != player.Color);

            // When planning the turns, only see own alliances.
            if (currentTurn.Mode == TurnMode.PlanMoves)
            {
                IEnumerable<AlliancePair> ownAlliancePairs = currentTurn.Alliances.AlliancePairs.Where(pair => pair.PlayerA.Color == player.Color || pair.PlayerB.Color == player.Color);

                currentTurn.Alliances.ResetAlliances();

                foreach (var pair in ownAlliancePairs)
                {
                    currentTurn.Alliances.AddAlliance(pair.PlayerA, pair.PlayerB);
                }
            }

            return currentTurn;
        }
示例#11
0
 public int NumberOfControlledCells(Player player)
 {
     int numberOfCells = Cells.Count(cell => cell.Units.Any(unit => unit.Player.Equals(player)));
     return numberOfCells;
 }
示例#12
0
 public Status(Player currentPlayer, IEnumerable<Player> players, int turnNumber)
 {
     CurrentPlayer = currentPlayer;
     Players = players;
     TurnNumber = turnNumber;
 }