Пример #1
0
        public void WarriorTakesDamageWhenOtherHumanPlayerIsHitFromMonster()
        {
            // arrange
            var builder = new CharacterBuilder();
            var cleric = (Cleric)builder.BuildCharacter("cleric", "TestUser1");
            var warrior = (Warrior)builder.BuildCharacter("warrior", "TestUser");
            var monster = builder.BuildCharacter("monster", "TestMonster");

            var gameBoard = new BoardGame(new List<Player> { warrior, monster, cleric }, false);
            warrior.Initialize(gameBoard);
            cleric.Initialize(gameBoard);

            var shareTheLoadCard = warrior.CardsToDrawFrom.First(card => card.GetType() == typeof(ShareTheLoad));
            warrior.CurrentCards.Add(shareTheLoadCard);
            warrior.CardsToDrawFrom.Remove(shareTheLoadCard);

            var healthBefore = cleric.Hp;
            var attackParameters = new AttackParameters
                                                             {
                                                                 AdjustedAmount = 4,
                                                                 OriginalAmount = 4,
                                                                 PlayerAttacking = monster,
                                                                 PlayerBeingAttacked = cleric
                                                             };
            // act
            cleric.TakeDamage(gameBoard, attackParameters);

            // assert
            Assert.AreEqual(healthBefore - 2, cleric.Hp);
        }
Пример #2
0
        public void ShareTheLoadIsNotRemovedWhenDefensiveInstantCardNotUsedOnSelf()
        {
            // arrange
            var builder = new CharacterBuilder();
            var cleric = (Cleric)builder.BuildCharacter("cleric", "TestUser1");
            var warrior = (Warrior)builder.BuildCharacter("warrior", "TestUser");
            var monster = builder.BuildCharacter("monster", "TestMonster");

            var gameBoard = new BoardGame(new List<Player> { warrior, monster, cleric }, false);
            warrior.Initialize(gameBoard);
            cleric.Initialize(gameBoard);

            var shareTheLoadCard = warrior.CardsToDrawFrom.First(card => card.GetType() == typeof(ShareTheLoad));
            warrior.CurrentCards.Add(shareTheLoadCard);
            warrior.CardsToDrawFrom.Remove(shareTheLoadCard);

            Assert.IsFalse(warrior.UsedInstantCard);
            Assert.AreEqual(1, warrior.CurrentCards.Count);
            var warriorHp = warrior.Hp;
            var attackParameters = new AttackParameters
            {
                AdjustedAmount = 4,
                OriginalAmount = 4,
                PlayerAttacking = monster,
                PlayerBeingAttacked = cleric
            };

            // act
            warrior.TakeDamage(gameBoard, attackParameters);

            // assert
            Assert.IsFalse(warrior.UsedInstantCard);
            Assert.AreEqual(warriorHp - 4, warrior.Hp);
            Assert.AreEqual(1, warrior.CurrentCards.Count);
        }
Пример #3
0
        public void AttackCorrectly()
        {
            // arrange
            var builder = new CharacterBuilder();
            var humanPlayer = builder.BuildCharacter("cleric", "Someone");

            // act

            // assert
            Assert.IsTrue(humanPlayer.CanTakeTurn);
        }
        public void HumanPlayerPlaysInstantCardWhenHeIsAttackedByAMonster()
        {
            // arrange
            var builder = new CharacterBuilder();
            var warrior = builder.BuildCharacter("warrior", "TestUser");
            var monster = builder.BuildCharacter("monster", "TestMonster");

            var gameBoard = new BoardGame(new List<Player> { warrior, monster }, false);
            ((HumanPlayer)warrior).Initialize(gameBoard);

            // act

            // assert
        }
Пример #5
0
        private static BoardGame SetupBoardGame(Player playerToTest, int monsterNum = 1)
        {
            var players = new List<Player> { playerToTest };
            var builder = new CharacterBuilder();

            for (var i = 0; i < monsterNum; i++)
            {
                var monster = builder.BuildCharacter("monster", "Monster" + i);
                players.Add(monster);
            }

            var boardGame = new BoardGame(players);

            return boardGame;
        }
Пример #6
0
        public void AttackCorrectly1()
        {
            // arrange
            var builder = new CharacterBuilder();
            var humanPlayer = builder.BuildCharacter("cleric", "SomePlayer1");
            var boardGame = SetupBoardGame(humanPlayer);
            var monster = boardGame.GetMonsters().First();
            var monsterHp = monster.Hp;

            // act

            humanPlayer.TakeTurn(boardGame);

            // assert
            Assert.IsTrue(monsterHp > monster.Hp);
        }
Пример #7
0
        public void VerifyGameEndsWhenOneTeamIsDead()
        {
            // arrange
            var builder = new CharacterBuilder();
            var archer = builder.BuildCharacter("archer", "CoolArcher");
            var players = new List<Player> { archer, builder.BuildCharacter("monster", "BadMonster") };

            var boardGame = new BoardGame(players, false);

            // act
            Assert.IsFalse(boardGame.GameEnded());
            archer.TakeDamage(archer.Hp);

            // assert
            Assert.IsTrue(boardGame.GameEnded());
        }
Пример #8
0
        public JsonResult Play(List<Dictionary<string, string>> players)
        {
            // simulate the game being played currently
            var characterBuilder = new CharacterBuilder();

            var gamePlayers = players.Select(player => characterBuilder.BuildCharacter(player["PClass"], player["Name"])).ToList();
            for (var i = 0; i < players.Count; i++)
            {
                var monster = characterBuilder.BuildCharacter("monster", "monster_" + (i + 1));
                gamePlayers.Add(monster);
            }

            var boardGame = new BoardGame(gamePlayers, false);
            var gameResults = boardGame.StartGame();

            return Json(new { results = gameResults}, JsonRequestBehavior.AllowGet);
        }
Пример #9
0
        static void Main(string[] args)
        {
            // want to get in a state where two users are taking turns to do something
            var builder = new CharacterBuilder();

            var users = new List<Player> {
                builder.BuildCharacter("cleric", "mike"),
                builder.BuildCharacter("wizard", "jeff"),
                builder.BuildCharacter("monster", "monster_1"),
                builder.BuildCharacter("monster", "monster_2")};

            var boardGame = new BoardGame(users);
            var logs = boardGame.StartGame();

            foreach (var log in logs)
            {
                Console.WriteLine(log);
            }

            Console.ReadLine();
        }
Пример #10
0
        private void HandleMonstersAfterTurn()
        {
            // if there aren't any more monsters left
            var aliveMonsters = this.GetMonsters().Where(monster => !monster.IsDead).ToList();

            if (aliveMonsters.Any())
            {
                return;
            }

            // remove all monsters from list
            foreach (var monster in this.GetMonsters())
            {
                this.DeadMonsters.Add(monster);
                this.Players.Remove(monster);
            }

            var characterBuilder = new CharacterBuilder();
            for (var i = 0; i < this.GetHumanPlayers().Count(); i++)
            {
                var newMonster = characterBuilder.BuildCharacter("monster", "monster_" + (this.DeadMonsters.Count + i + 1));
                this.Players.Add(newMonster);
            }
        }