Exemplo n.º 1
0
        public void TestMovement()
        {
            // Generates a new independent game each time.
            IGame game = new NormalGameBuilder().BuildGame("test1", new VikingFactory(), "test2", new GauloisFactory());
            int size = game.Map.Size;
            IRound round = game.Round;

            // Gets an unit of the current player:
            for(int i = 0; i < size; i++) {
                for(int j = 0; j < size; j++) {
                    IPoint pos = new Point(i, j);
                    if(round.IsCurrentPlayerPosition(pos)) {
                        IUnit unit = round.GetUnits(pos)[0];

                        // Selects it:
                        List<IUnit> unitsL = new List<IUnit>();
                        unitsL.Add(unit);
                        round.SelectUnits(unitsL, pos);

                        // Sets the destination point:
                        IPoint destination = GetDestination(game, pos, unit);
                        Assert.IsTrue(round.SetDestination(destination));

                        // Executes the movement and checks its result:
                        round.ExecuteMove();
                        List<IUnit> units = game.Map.GetUnits(destination);
                        Assert.IsTrue(units.Contains(unit));
                        return;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void TestAttackMovement()
        {
            // Generates a new independent game each time.
            IGame game = new NormalGameBuilder().BuildGame("test1", new VikingFactory(), "test2", new GauloisFactory());
            int size = game.Map.Size;
            IRound round = game.Round;

            // Gets an unit of the current player:
            for(int i = 0; i < size; i++) {
                for(int j = 0; j < size; j++) {
                    IPoint pos = new Point(i, j);
                    if(round.IsCurrentPlayerPosition(pos)) {
                        IUnit unit = round.GetUnits(pos)[0];

                        // Selects it:
                        List<IUnit> unitsL = new List<IUnit>();
                        unitsL.Add(unit);
                        round.SelectUnits(unitsL, pos);

                        // Sets the destination point and place an enemy unit on it:
                        IPoint destination = GetDestination(game, pos, unit);
                        Assert.IsTrue(game.CurrentPlayer.Equals(game.Player1));
                        IUnit enemy = game.Player2.CreateUnits(1)[0];
                        game.Map.PlaceUnit(enemy, destination);
                        Assert.IsTrue(round.SetDestination(destination));
                        Assert.IsTrue(game.Map.IsEnemyPosition(destination, unit));

                        // Executes the movement and checks its result:
                        round.ExecuteMove();
                        List<IUnit> unitsAtDestination = game.Map.GetUnits(destination);
                        List<IUnit> unitsAtOrigin = game.Map.GetUnits(pos);
                        // The results depend on the result from the fight:
                        switch(round.LastCombatResult) {
                            case CombatResult.DRAW:
                                Assert.IsTrue(unitsAtOrigin.Contains(unit));
                                Assert.IsTrue(unitsAtDestination.Contains(enemy));
                                break;
                            case CombatResult.LOSE:
                                Assert.IsFalse(unitsAtOrigin.Contains(unit));
                                Assert.IsTrue(unitsAtDestination.Contains(enemy));
                                break;
                            case CombatResult.WIN:
                                Assert.IsFalse(unitsAtDestination.Contains(enemy));
                                Assert.IsTrue(unitsAtOrigin.Contains(unit) || unitsAtDestination.Contains(unit));
                                break;
                            default:
                                Assert.Fail();
                                break;
                        }
                        return;
                    }
                }
            }
        }