Beispiel #1
0
        /// <summary>
        /// Build the game.
        /// Creates the game manager with the right players, units and map.
        /// </summary>
        /// <remarks>
        /// The map is created in the C++ library as for the unit positions.
        /// </remarks>
        /// <param name="name1">The first player's name.</param>
        /// <param name="factory1">The factory for the first player.</param>
        /// <param name="name2">The second player's name.</param>
        /// <param name="factory2">The factory for the second player.</param>
        /// <returns>The game manager.</returns>
        public IGame BuildGame(string name1, IUnitFactory factory1, string name2, IUnitFactory factory2)
        {
            // Builds the map using the MapBuilder:
            IMap map = MapBuilder.Instance.BuildMap(this.mapSize);
            ITile[,] tiles = map.Tiles;
            int[][] mapAsIntegers = TileFactory.GetNumbers(tiles);

            IPlayer player1 = new Player(name1, factory1);
            IPlayer player2 = new Player(name2, factory2);

            // Retrieves the starting points from the wrapper:
            int[][] starts = Wrapper.getStartsPlayers(mapAsIntegers, this.mapSize);
            IPoint startPlayer1 = new Point(starts[0][0], starts[0][1]);
            IPoint startPlayer2 = new Point(starts[1][0], starts[1][1]);

            // Creates and places the units for each player:
            List<IUnit> units1 = player1.CreateUnits(this.nbUnits);
            for(int i = 0; i < this.nbUnits; i++) {
                map.PlaceUnit(units1[i], startPlayer1);
            }
            List<IUnit> units2 = player2.CreateUnits(this.nbUnits);
            for(int i = 0; i < this.nbUnits; i++) {
                map.PlaceUnit(units2[i], startPlayer2);
            }

            return new Game(player1, player2, map, this.maxRounds);
        }
Beispiel #2
0
        public void TestGetIdleUnit()
        {
            Player player = new Player("test", new VikingFactory());
            IViking vikingA = new Viking(player);
            map.PlaceUnit(vikingA, new Point(0, 0));

            Tuple<IUnit, IPoint> idleUnit = map.GetIdleUnit(player);
            Assert.IsTrue(idleUnit.Item2.Equals(new Point(0, 0)));
            Assert.AreSame(idleUnit.Item1, vikingA);

            IViking vikingB = new Viking(player);
            map.PlaceUnit(vikingB, new Point(1, 1));
            Assert.IsTrue(vikingA.Move(new Forest()));

            idleUnit = map.GetIdleUnit(player);
            Assert.IsTrue(idleUnit.Item2.Equals(new Point(1, 1)));
            Assert.AreSame(idleUnit.Item1, vikingB);
        }
Beispiel #3
0
        /// <summary>
        /// End of the game
        /// </summary>
        public virtual void End()
        {
            int maxScore = -1;

            foreach (Player player in this.Players)
            {
                if (!player.CurrentFaction.IsDecimated() && player.Score > maxScore)
                {
                    this.Victor = player;
                    maxScore = player.Score;
                }
            }

            OnRaiseEndGame();
        }
Beispiel #4
0
 /// <summary>
 /// Add a new player to the existing list
 /// </summary>
 /// <param name="player"></param>
 public void AddNewPlayer(Player player)
 {
     Players.Add(player);
 }
Beispiel #5
0
        public void TestUnitPositions()
        {
            // Places a few units for tests:
            Player player1 = new Player("test1", new VikingFactory());
            Player player2 = new Player("test2", new GauloisFactory());
            IViking vikingA = new Viking(player1);
            IViking vikingB = new Viking(player1);
            IGaulois gauloisA = new Gaulois(player2);
            IGaulois gauloisB = new Gaulois(player2);
            map.PlaceUnit(vikingA, new Point(0, 0));
            map.PlaceUnit(vikingB, new Point(0, 0));
            map.PlaceUnit(gauloisA, new Point(14, 14));
            map.PlaceUnit(gauloisB, new Point(14, 14));
            List<IUnit> units = map.GetUnits(new Point(0, 0));
            Assert.AreEqual(2, units.Count);
            units = map.GetUnits(new Point(14, 14));
            Assert.AreEqual(2, units.Count);

            // Tests RemoveUnit:
            Assert.IsTrue(map.RemoveUnit(gauloisB, new Point(14, 14)));
            units = map.GetUnits(new Point(14, 14));
            Assert.AreEqual(1, units.Count);

            // Tests MoveUnit:
            map.MoveUnit(vikingB, new Point(0, 0), new Point(0, 1));
            units = map.GetUnits(new Point(0, 0));
            Assert.AreEqual(1, units.Count);
            units = map.GetUnits(new Point(0, 1));
            Assert.AreEqual(1, units.Count);

            // Tests EnemyPosition:
            Assert.IsFalse(map.IsEnemyPosition(new Point(14, 14), gauloisA));
            Assert.IsTrue(map.IsEnemyPosition(new Point(0, 0), gauloisB));
        }