コード例 #1
0
        public void SetUp()
        {
            _input       = new MockInput();
            _output      = new MockOutput();
            _menuFactory = new MenuFactory();
            _manager     = new MenuManager(_input, _output, _menuFactory);
            _logger      = new EventLogger();
            _playerOne   = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "swordsman");
            Spell fireSpell = SpellFactory.GetSpell(MagicType.Fire, 1);

            _playerOne.AddSpell(fireSpell);
            _playerOne.SetMana(fireSpell.Cost);

            _playerTwo   = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "mage");
            _playerThree = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "alchemist");
            _playerTeam  = new Team(_manager, _playerOne, _playerTwo, _playerThree);

            _enemyTeam = new Team(_manager, new List <IFighter>
            {
                FighterFactory.GetFighter(FighterType.Goblin, 1),
                FighterFactory.GetFighter(FighterType.Goblin, 1),
                FighterFactory.GetFighter(FighterType.Goblin, 1)
            });

            _manager.InitializeForBattle(_playerTeam, _enemyTeam);
        }
コード例 #2
0
        public void Setup()
        {
            _fighter = new TestHumanFighter("Hero", 1);
            _fighter.SetHealth(FighterHealth);
            _fighter.SetMana(FighterMana);
            _fighter.SetStrength(FighterAttack);
            _fighter.SetDefense(FighterDefense);
            _fighter.SetSpeed(FighterSpeed);
            _fighter.SetEvade(FighterEvade);
            _fighter.SetLuck(FighterLuck);

            _factoryFighter = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "Ted");
            _factoryFighter.AddSpell(SpellFactory.GetSpell(MagicType.Fire, 1));
            _enemy             = (TestEnemyFighter)TestFighterFactory.GetFighter(TestFighterType.TestEnemy, 1, "enemy");
            _armoredEnemy      = (TestEnemyFighter)TestFighterFactory.GetFighter(TestFighterType.TestEnemy, 1, "armored");
            _superArmoredEnemy = (TestEnemyFighter)TestFighterFactory.GetFighter(TestFighterType.TestEnemy, 1, "super armored");

            _input         = new MockInput();
            _output        = new MockOutput();
            _menuManager   = new TestMenuManager(_input, _output);
            _chanceService = new MockChanceService();

            _battleManager = new TestBattleManager(_chanceService, _input, _output);

            var humanTeam = new Team(_menuManager, _fighter);

            _battleManager.SetHumanTeam(humanTeam);

            var enemyTeam = new Team(_menuManager, _enemy);

            _battleManager.SetEnemyTeam(enemyTeam);

            _battleManager.SetConfig(new BattleManagerBattleConfiguration());
        }
コード例 #3
0
        public void RestoreHealthEffect_AppropriatelyExecuted_AttackHits()
        {
            int initialHealth = 100 - _restoreHealthEffect.Percentage;

            _human.SetHealth(100, initialHealth);
            _human.SetMana(100, 0);
            _human.SetMove(_attackWithRestoreHealthEffect);
            _human.SetMoveTarget(_enemy);
            _chanceService.PushEventsOccur(true, false); //attack hits, not a crit

            _enemy.SetMove(_doNothingMove);
            _enemy.SetMoveTarget(_enemy);

            _battleManager.Battle(_humanTeam, _enemyTeam);

            Assert.AreEqual(_human.MaxHealth, _human.CurrentHealth, "humman player's health should have been restored when the attack hit!");
            Assert.AreEqual(0, _human.CurrentMana, "humman player's mana should have been unaffected by the restore effect!");
        }
コード例 #4
0
        public void SetUp()
        {
            _menuInput   = new MockInput();
            _menuOutput  = new MockOutput();
            _menuManager = new TestMenuManager(_menuInput, _menuOutput);

            _player = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1);
            Spell fireball   = SpellFactory.GetSpell(MagicType.Fire, 1);
            Spell earthSpell = SpellFactory.GetSpell(MagicType.Earth, 1);

            _player.AddSpell(fireball);
            _player.AddSpell(earthSpell);
            _player.SetMana(fireball.Cost);

            _playerTeam = new Team(_menuManager, _player);
            _enemyTeam  = new Team(_menuManager, (EnemyFighter)FighterFactory.GetFighter(FighterType.Goblin, 1));

            _menu = (Menu)Globals.MenuFactory.GetMenu(MenuType.ChooseAttackTypeMenu, _menuInput, _menuOutput);
            _menu.Build(_player, _playerTeam, _enemyTeam, null);

            _fullSpellMenuPrompt = new List <string>
            {
                $"Which spell would you like to cast?\n{_player.DisplayName} currently has {_player.CurrentMana} / {_player.MaxMana} Mana\n",
            };

            var spellMenu = (SpellSelectionMenu)Globals.MenuFactory.GetMenu(MenuType.ChooseSpellMenu);

            spellMenu.Build(_player, _playerTeam, _enemyTeam, null);

            var spellMenuActions = spellMenu.MenuActions;

            for (var i = 0; i < spellMenuActions.Count; ++i)
            {
                _fullSpellMenuPrompt.Add((i + 1) + ". " + spellMenuActions[i].DisplayText + "\n");
            }

            _fullSpellMenuPrompt.Add(StatusPrompt);
            _fullSpellMenuPrompt.Add(HelpPrompt);

            _fullMenuPrompt = new List <string>
            {
                "How would you like to fight?\n",
                "1. attack\n",
                "2. magic\n",
                StatusPrompt,
                HelpPrompt
            };

            _fullTargetMenuPrompt = new List <string>
            {
                "Who will you target for this action?\n",
                "1. " + _enemyTeam.Fighters[0].DisplayName + "\n",
                StatusPrompt,
                BackPrompt,
                HelpPrompt
            };
        }
コード例 #5
0
        public void DrainManaMethod_AppropriatelyRaisesEvents_ManaDrainIsLessThanCurrentMana()
        {
            _fighter.SetMana(10);
            _fighter.DrainMana(8);

            var logs = _logger.Logs;

            Assert.AreEqual(1, logs.Count);
            Assert.AreEqual(EventType.ManaLost, logs[0].Type);
            Assert.AreEqual(_fighter, logs[0].Sender);
            var e = logs[0].E as ManaLostEventArgs;

            Assert.That(e, Is.Not.Null);
            if (e != null)
            {
                Assert.AreEqual(8, e.ManaSpent);
            }
        }
コード例 #6
0
 public void Setup()
 {
     _fighter = (TestHumanFighter)TestFighterFactory.GetFighter(TestFighterType.TestHuman, 1, "Ted");
     _enemy   = (TestEnemyFighter)TestFighterFactory.GetFighter(TestFighterType.TestEnemy, 1, "enemy");
     _logger  = new EventLogger();
     _logger.SubscribeAll(_fighter);
     _logger.SubscribeAll(_enemy);
     _fireballSpell = SpellFactory.GetSpell(MagicType.Fire, 1);
     _fighter.AddSpell(_fireballSpell);
     _fighter.SetMana(_fireballSpell.Cost);
     _logger.ClearLogs();
 }
コード例 #7
0
        public void HappyPath_SelectValidSpell([Values(MagicType.Fire, MagicType.Earth, MagicType.Water, MagicType.Wind)] MagicType spellType)
        {
            var spell     = SpellFactory.GetSpell(spellType, 1);
            var spellName = spell.Description;

            _player.AddSpell(spell);
            _player.SetMana(spell.Cost);

            _menuInput.Push(new List <string> {
                spellName, "1"
            });

            _fullSpellMenuPrompt = new List <string>
            {
                $"Which spell would you like to cast?\n{_player.DisplayName} currently has {_player.CurrentMana} / {_player.MaxMana} Mana\n",
                "1. " + spellName + " " + spell.Cost + "\n",
                StatusPrompt,
                BackPrompt,
                HelpPrompt
            };
            var count = _fullSpellMenuPrompt.Count;

            var ret = _menu.GetInput();

            var outputs = _menuOutput.GetOutputs();

            for (var i = 0; i < count; ++i)
            {
                Assert.AreEqual(MockOutputMessageType.Normal, outputs[i].Type);
                Assert.AreEqual(_fullSpellMenuPrompt[i], outputs[i].Message);
            }

            Assert.AreEqual(spellName, ret.Move.Description);

            _player.RemoveSpell(spell);
        }
コード例 #8
0
        public void CastSpell_CorrectlyChecksUserHasEnoughMana([Values(4, 8)] int spellCost)
        {
            Spell spell = new Spell("foo", MagicType.Wind, SpellType.Attack, TargetType.SingleEnemy, spellCost, 5);

            int expectedMana = spellCost - 1;

            _human.SetMana(spellCost, expectedMana);
            _human.SetDeathOnTurnEndEvent();
            _human.AddSpell(spell);
            _human.SetMove(spell);
            _human.SetMoveTarget(_enemy);

            _enemy.SetHealth(100);

            _battleManager.Battle(_humanTeam, _enemyTeam);

            Assert.AreEqual(expectedMana, _human.CurrentMana);
        }