コード例 #1
0
        public void AttackUnit_ArcherAttackCloseCombatAllTypes()
        {
            Player         Player1        = new Player(1, "Игрок №1", null);
            Player         Player2        = new Player(2, "Игрок №2", null);
            Archer         Archer         = new Archer(Player1, 9, 9);
            Map            Map            = CreateMap();
            GameController GameController = new GameController(Map);


            // Лучник имеет 50 жизней. Погибнет за два удара.
            Archer ArcherTarget = new Archer(Player2, 10, 10);

            Assert.AreEqual(2, GetAttacksCount(GameController, Archer, ArcherTarget));

            // Катапульта имеет 75 жизней. Погибнет за три удара.
            Catapult CatapultTarget = new Catapult(Player2, 10, 10);

            Assert.AreEqual(3, GetAttacksCount(GameController, Archer, CatapultTarget));

            // Всадник имеет 200 жизней. Необходимо 8 ударов.
            Horseman HorsemanTarget = new Horseman(Player2, 10, 10);

            Assert.AreEqual(8, GetAttacksCount(GameController, Archer, HorsemanTarget));

            // Мечник имеет 100 жизней. Погибнет за 4 удара.
            Swordsman SwordsmanTarget = new Swordsman(Player2, 10, 10);

            Assert.AreEqual(4, GetAttacksCount(GameController, Archer, SwordsmanTarget));
        }
コード例 #2
0
        public void AttackUnit_CatapultAttackCloseCombatAllTypes()
        {
            var player1        = new Player(1, "Игрок №1", null);
            var player2        = new Player(2, "Игрок №2", null);
            var catapult       = new Catapult(player1, 9, 9);
            var map            = CreateMap();
            var gameController = new GameController(map);


            // Лучник имеет 50 жизней. Погибнет за один удар.
            var archerTarget = new Archer(player2, 10, 10);

            Assert.AreEqual(1, GetAttacksCount(gameController, catapult, archerTarget));

            // Катапульта имеет 75 жизней. Погибнет за два удара.
            var catapultTarget = new Catapult(player2, 10, 10);

            Assert.AreEqual(2, GetAttacksCount(gameController, catapult, catapultTarget));

            // Всадник имеет 200 жизней. Необходимо 4 удара.
            var horsemanTarget = new Horseman(player2, 10, 10);

            Assert.AreEqual(4, GetAttacksCount(gameController, catapult, horsemanTarget));

            // Мечник имеет 100 жизней. Погибнет за два удара.
            var swordsmanTarget = new Swordsman(player2, 10, 10);

            Assert.AreEqual(2, GetAttacksCount(gameController, catapult, swordsmanTarget));
        }
コード例 #3
0
        public void GetObjectCoordinates_AllTypes()
        {
            var player         = new Player(1, "Игрок №1", null);
            var map            = new Map(null, null);
            var gameController = new GameController(map);


            var archer = new Archer(player)
            {
                X = 1, Y = 2
            };
            var archerCoordinates = gameController.GetObjectCoordinates(archer);

            Assert.AreEqual(1, archerCoordinates.X);
            Assert.AreEqual(2, archerCoordinates.Y);

            var catapult = new Catapult(player)
            {
                X = 3, Y = 4
            };
            var catapultCoordinates = gameController.GetObjectCoordinates(catapult);

            Assert.AreEqual(3, catapultCoordinates.X);
            Assert.AreEqual(4, catapultCoordinates.Y);

            var horseman = new Horseman(player)
            {
                X = 5, Y = 6
            };
            var horsemanCoordinates = gameController.GetObjectCoordinates(horseman);

            Assert.AreEqual(5, horsemanCoordinates.X);
            Assert.AreEqual(6, horsemanCoordinates.Y);

            var swordsman = new Swordsman(player)
            {
                X = 7, Y = 8
            };
            var swordsmanCoordinates = gameController.GetObjectCoordinates(swordsman);

            Assert.AreEqual(7, swordsmanCoordinates.X);
            Assert.AreEqual(8, swordsmanCoordinates.Y);


            var grass = new Grass {
                X = 9, Y = 10
            };
            var grassCoordinates = gameController.GetObjectCoordinates(grass);

            Assert.AreEqual(9, grassCoordinates.X);
            Assert.AreEqual(10, grassCoordinates.Y);

            var water = new Water {
                X = 11, Y = 12
            };
            var waterCoordinates = gameController.GetObjectCoordinates(water);

            Assert.AreEqual(11, waterCoordinates.X);
            Assert.AreEqual(12, waterCoordinates.Y);
        }
コード例 #4
0
        public void MoveUnit_AllTypes()
        {
            const int movePositionX = 15;
            const int movePositionY = 15;

            Player         Player         = new Player(1, "Игрок №1", null);
            Map            Map            = CreateMap();
            GameController GameController = new GameController(Map);


            Archer Archer = new Archer(Player, 14, 14);

            GameController.MoveUnit(Archer, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, Archer.UnitCoordinates.X);
            Assert.AreEqual(movePositionY, Archer.UnitCoordinates.Y);

            Catapult Catapult = new Catapult(Player, 14, 14);

            GameController.MoveUnit(Catapult, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, Catapult.UnitCoordinates.X);
            Assert.AreEqual(movePositionY, Catapult.UnitCoordinates.Y);

            Horseman Horseman = new Horseman(Player, 14, 14);

            GameController.MoveUnit(Horseman, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, Horseman.UnitCoordinates.X);
            Assert.AreEqual(movePositionY, Horseman.UnitCoordinates.Y);

            Swordsman Swordsman = new Swordsman(Player, 14, 14);

            GameController.MoveUnit(Swordsman, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, Swordsman.UnitCoordinates.X);
            Assert.AreEqual(movePositionY, Swordsman.UnitCoordinates.Y);
        }
コード例 #5
0
        public void AttackUnit_CatapultAttackAllTypes()
        {
            Player         Player1        = new Player(1, "Игрок №1", null);
            Player         Player2        = new Player(2, "Игрок №2", null);
            Catapult       Catapult       = new Catapult(Player1, 8, 8);
            Map            Map            = CreateMap();
            GameController GameController = new GameController(Map);


            // Лучник имеет 50 жизней. Погибнет за один удар.
            Archer ArcherTarget = new Archer(Player2, 10, 10);

            Assert.AreEqual(1, GetAttacksCount(GameController, Catapult, ArcherTarget));

            // Катапульта имеет 75 жизней. Погибнет за один удар.
            Catapult CatapultTarget = new Catapult(Player2, 10, 10);

            Assert.AreEqual(1, GetAttacksCount(GameController, Catapult, CatapultTarget));

            // Всадник имеет 200 жизней. Необходимо 2 удара.
            Horseman HorsemanTarget = new Horseman(Player2, 10, 10);

            Assert.AreEqual(2, GetAttacksCount(GameController, Catapult, HorsemanTarget));

            // Мечник имеет 100 жизней. Погибнет за один удар.
            Swordsman SwordsmanTarget = new Swordsman(Player2, 10, 10);

            Assert.AreEqual(1, GetAttacksCount(GameController, Catapult, SwordsmanTarget));
        }
コード例 #6
0
        public void CanMoveUnit_HorsemanOnEmptyMap(int x, int y, bool canMove)
        {
            const int startPositionX = 20;
            const int startPositionY = 20;

            Player         Player         = new Player(1, "Игрок №1", null);
            Horseman       Horseman       = new Horseman(Player, startPositionX, startPositionY);
            Map            Map            = CreateMap(units: new[] { Horseman });
            GameController GameController = new GameController(Map);

            Assert.AreEqual(canMove, GameController.CanMoveUnit(Horseman, x, y));
        }
コード例 #7
0
        public void CanMoveUnit_HorsemanOnEmptyMap(int x, int y, bool canMove)
        {
            const int startPositionX = 20;
            const int startPositionY = 20;

            var player         = new Player(1, "Игрок №1", null);
            var horseman       = new Horseman(player, startPositionX, startPositionY);
            var map            = CreateMap(units: new[] { horseman });
            var gameController = new GameController(map);

            Assert.AreEqual(canMove, gameController.CanMoveUnit(horseman, x, y));
        }
コード例 #8
0
        public void CanMoveUnit_CatapultOnHorseman_False()
        {
            const int horsemanPositionX = 15;
            const int horsemanPositionY = 15;

            Player         Player         = new Player(1, "Игрок №1", null);
            Catapult       Catapult       = new Catapult(Player, 10, 10);
            Horseman       Horseman       = new Horseman(Player, horsemanPositionX, horsemanPositionY);
            Map            Map            = CreateMap(units: new object[] { Catapult, Horseman });
            GameController GameController = new GameController(Map);

            Assert.False(GameController.CanMoveUnit(Horseman, horsemanPositionX, horsemanPositionY));
        }
コード例 #9
0
ファイル: HorsemanDto.cs プロジェクト: aslaef/Strategy-Game
 public HorsemanDto(Horseman a)
 {
     if (a != null)
     {
         UnitId  = a.UnitId;
         Counter = a.Counter;
         Price   = a.Price;
         Salary  = a.Salary;
         Food    = a.Food;
         Atk     = a.Atk;
         Def     = a.Def;
     }
 }
コード例 #10
0
        public void CanMoveUnit_CatapultOnHorseman_False()
        {
            const int horsemanPositionX = 15;
            const int horsemanPositionY = 15;

            var player         = new Player(1, "Игрок №1", null);
            var catapult       = new Catapult(player, 10, 10);
            var horseman       = new Horseman(player, horsemanPositionX, horsemanPositionY);
            var map            = CreateMap(units: new Unit[] { catapult, horseman });
            var gameController = new GameController(map);

            Assert.False(gameController.CanMoveUnit(horseman, horsemanPositionX, horsemanPositionY));
        }
コード例 #11
0
        public void CanAttackUnit_Horseman(int x, int y, bool canAttack)
        {
            const int startPositionX = 10;
            const int startPositionY = 10;

            var player1        = new Player(1, "Игрок №1", null);
            var player2        = new Player(2, "Игрок №2", null);
            var horseman       = new Horseman(player1, startPositionX, startPositionY);
            var target         = new Archer(player2, x, y);
            var map            = CreateMap(units: new Unit[] { horseman, target });
            var gameController = new GameController(map);

            Assert.AreEqual(canAttack, gameController.CanAttackUnit(horseman, target));
        }
コード例 #12
0
        public async Task <Unit> postH(int id)
        {
            var country = _dbcontext.Countries.Where(c => c.CountryId == id).SingleOrDefault();

            var a = new Horseman()
            {
                OwnerCountry = country
            };

            _dbcontext.Horsemans.Add(a);
            await _dbcontext.SaveChangesAsync();

            return(a);
        }
コード例 #13
0
        public void CanAttackUnit_Horseman(int x, int y, bool canAttack)
        {
            const int startPositionX = 10;
            const int startPositionY = 10;

            Player         Player1        = new Player(1, "Игрок №1", null);
            Player         Player2        = new Player(2, "Игрок №2", null);
            Horseman       Horseman       = new Horseman(Player1, startPositionX, startPositionY);
            Archer         Target         = new Archer(Player2, x, y);
            Map            Map            = CreateMap(units: new object[] { Horseman, Target });
            GameController GameController = new GameController(Map);

            Assert.AreEqual(canAttack, GameController.CanAttackUnit(Horseman, Target));
        }
コード例 #14
0
        public void MoveUnit_AllTypes()
        {
            const int movePositionX = 15;
            const int movePositionY = 15;

            var player         = new Player(1, "Игрок №1", null);
            var map            = CreateMap();
            var gameController = new GameController(map);


            var archer = new Archer(player)
            {
                X = 14, Y = 14
            };

            gameController.MoveUnit(archer, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, archer.X);
            Assert.AreEqual(movePositionY, archer.Y);

            var catapult = new Catapult(player)
            {
                X = 14, Y = 14
            };

            gameController.MoveUnit(catapult, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, catapult.X);
            Assert.AreEqual(movePositionY, catapult.Y);

            var horseman = new Horseman(player)
            {
                X = 14, Y = 14
            };

            gameController.MoveUnit(horseman, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, horseman.X);
            Assert.AreEqual(movePositionY, horseman.Y);

            var swordsman = new Swordsman(player)
            {
                X = 14, Y = 14
            };

            gameController.MoveUnit(swordsman, movePositionX, movePositionY);
            Assert.AreEqual(movePositionX, swordsman.X);
            Assert.AreEqual(movePositionY, swordsman.Y);
        }
コード例 #15
0
        public void GetObjectCoordinates_AllTypes()
        {
            var player         = new Player(1, "Игрок №1", null);
            var map            = new Map(null, null);
            var gameController = new GameController(map);


            var archer            = new Archer(player, 1, 2);
            var archerCoordinates = gameController.GetObjectCoordinates(archer);

            Assert.AreEqual(1, archerCoordinates.X);
            Assert.AreEqual(2, archerCoordinates.Y);

            var catapult            = new Catapult(player, 3, 4);
            var catapultCoordinates = gameController.GetObjectCoordinates(catapult);

            Assert.AreEqual(3, catapultCoordinates.X);
            Assert.AreEqual(4, catapultCoordinates.Y);

            var horseman            = new Horseman(player, 5, 6);
            var horsemanCoordinates = gameController.GetObjectCoordinates(horseman);

            Assert.AreEqual(5, horsemanCoordinates.X);
            Assert.AreEqual(6, horsemanCoordinates.Y);

            var swordsman            = new Swordsman(player, 7, 8);
            var swordsmanCoordinates = gameController.GetObjectCoordinates(swordsman);

            Assert.AreEqual(7, swordsmanCoordinates.X);
            Assert.AreEqual(8, swordsmanCoordinates.Y);


            var grass            = new Grass(9, 10);
            var grassCoordinates = gameController.GetObjectCoordinates(grass);

            Assert.AreEqual(9, grassCoordinates.X);
            Assert.AreEqual(10, grassCoordinates.Y);

            var water            = new Water(11, 12);
            var waterCoordinates = gameController.GetObjectCoordinates(water);

            Assert.AreEqual(11, waterCoordinates.X);
            Assert.AreEqual(12, waterCoordinates.Y);
        }
コード例 #16
0
        public void AttackUnit_ArcherAttackCloseCombatAllTypes()
        {
            var player1 = new Player(1, "Игрок №1", null);
            var player2 = new Player(2, "Игрок №2", null);
            var archer  = new Archer(player1)
            {
                X = 9, Y = 9
            };
            var map            = CreateMap();
            var gameController = new GameController(map);


            // Лучник имеет 50 жизней. Погибнет за два удара.
            var archerTarget = new Archer(player2)
            {
                X = 10, Y = 10
            };

            Assert.AreEqual(2, GetAttacksCount(gameController, archer, archerTarget));

            // Катапульта имеет 75 жизней. Погибнет за три удара.
            var catapultTarget = new Catapult(player2)
            {
                X = 10, Y = 10
            };

            Assert.AreEqual(3, GetAttacksCount(gameController, archer, catapultTarget));

            // Всадник имеет 200 жизней. Необходимо 8 ударов.
            var horsemanTarget = new Horseman(player2)
            {
                X = 10, Y = 10
            };

            Assert.AreEqual(8, GetAttacksCount(gameController, archer, horsemanTarget));

            // Мечник имеет 100 жизней. Погибнет за 4 удара.
            var swordsmanTarget = new Swordsman(player2)
            {
                X = 10, Y = 10
            };

            Assert.AreEqual(4, GetAttacksCount(gameController, archer, swordsmanTarget));
        }
コード例 #17
0
        public void GetObjectCoordinates_AllTypes()
        {
            Player         Player         = new Player(1, "Игрок №1", null);
            Map            Map            = new Map(null, null);
            GameController GameController = new GameController(Map);


            Archer      Archer            = new Archer(Player, 1, 2);
            Coordinates ArcherCoordinates = GameController.GetObjectCoordinates(Archer);

            Assert.AreEqual(1, ArcherCoordinates.X);
            Assert.AreEqual(2, ArcherCoordinates.Y);

            Catapult    Catapult            = new Catapult(Player, 3, 4);
            Coordinates CatapultCoordinates = GameController.GetObjectCoordinates(Catapult);

            Assert.AreEqual(3, CatapultCoordinates.X);
            Assert.AreEqual(4, CatapultCoordinates.Y);

            Horseman    Horseman            = new Horseman(Player, 5, 6);
            Coordinates HorsemanCoordinates = GameController.GetObjectCoordinates(Horseman);

            Assert.AreEqual(5, HorsemanCoordinates.X);
            Assert.AreEqual(6, HorsemanCoordinates.Y);

            Swordsman   Swordsman            = new Swordsman(Player, 7, 8);
            Coordinates SwordsmanCoordinates = GameController.GetObjectCoordinates(Swordsman);

            Assert.AreEqual(7, SwordsmanCoordinates.X);
            Assert.AreEqual(8, SwordsmanCoordinates.Y);


            Grass       Grass            = new Grass(9, 10);
            Coordinates GrassCoordinates = GameController.GetObjectCoordinates(Grass);

            Assert.AreEqual(9, GrassCoordinates.X);
            Assert.AreEqual(10, GrassCoordinates.Y);

            Water       Water            = new Water(11, 12);
            Coordinates WaterCoordinates = GameController.GetObjectCoordinates(Water);

            Assert.AreEqual(11, WaterCoordinates.X);
            Assert.AreEqual(12, WaterCoordinates.Y);
        }
コード例 #18
0
 public void RemoveHorseman(Horseman horseman)
 {
     m_HorsemanMask &= ~(1 << (int)horseman);
     m_MusicState.setParameterByID(m_MusicParameterID, m_HorsemanMask);
 }
コード例 #19
0
 public void AddHorseman(Horseman horseman)
 {
     m_HorsemanMask |= 1 << (int)horseman;
     m_MusicState.setParameterByID(m_MusicParameterID, m_HorsemanMask);
 }
コード例 #20
0
ファイル: UsersService.cs プロジェクト: aslaef/Strategy-Game
        public bool RegisterUser(UserDto u)
        {
            var games = _dbcontext.Games.FirstOrDefault();

            if (games == null)
            {
                _dbcontext.Games.Add(new Game {
                    RoundNumber = 1
                });
            }



            var c = new Country()
            {
                CountryName = u.CountryName,
                Gold        = 1500,
            };

            var archer = new Archer();

            archer.OwnerCountry = c;
            archer.Counter      = 10;
            _dbcontext.Units.Add(archer);
            var horseman = new Horseman();

            horseman.OwnerCountry = c;
            _dbcontext.Units.Add(horseman);
            var soldier = new Elite();

            soldier.OwnerCountry = c;
            _dbcontext.Units.Add(soldier);

            var farm = new Farm();

            farm.OwnerCountry = c;
            _dbcontext.Buildings.Add(farm);
            var barrack = new Barrack();

            barrack.OwnerCountry = c;
            barrack.Counter      = 1;
            _dbcontext.Buildings.Add(barrack);


            var user = new User()
            {
                Name         = u.Name,
                Password     = u.Pass,
                OwnedCountry = c,
                Score        = 0,
            };



            _dbcontext.Countries.Add(c);

            _dbcontext.Users.Add(user);

            _dbcontext.SaveChanges();

            return(true);
        }
コード例 #21
0
 public void Init()
 {
     _mockHorse = new Mock <IHorse>();
     _mockHorse.Setup(x => x.Name).Returns(HorseName);
     _horseman = new Horseman(_mockHorse.Object);
 }