public void GetInput_ReturnsCorrectMenuSelection_SubMenuRequiresBattleMoveInput() { //arrange MockMenu mockTargetMenu = new MockMenu(requiresBattleMoveInput: true, input: _input, output: _output); mockTargetMenu.SetEchoMode(); KeysOffOwnerNumberInputMenu menu = new KeysOffOwnerNumberInputMenu("foo", _input, _output, mockTargetMenu); int expectedReturnedNumber = 1; _owner.SetHealth(expectedReturnedNumber + 1); menu.Build(_owner, _ownerTeam, _enemyTeam, null); _input.Push(expectedReturnedNumber.ToString()); BattleMove eatPotatoMove = new DoNothingMove("eats a potato"); //act NumberInputMenuSelection returnedSelection = menu.GetInput(eatPotatoMove, null) as NumberInputMenuSelection; //assert Assert.NotNull(returnedSelection); Assert.AreEqual(expectedReturnedNumber, returnedSelection.Number); Assert.AreEqual(eatPotatoMove, returnedSelection.Move); }
public void ReturnsAppopriateResponse() { _input.Push("1"); MenuSelection menuSelection = _menu.GetInput(); NumberInputMenuSelection numberInputSelection = menuSelection as NumberInputMenuSelection; Assert.NotNull(numberInputSelection); Assert.AreEqual(1, numberInputSelection.Number); }
public void CorrectlyKeysOffCurrentHealth_NotMaxHealth() { _owner.SetHealth(100, 10); _menu.Build(_owner, _ownerTeam, _enemyTeam, null); _input.Push("99", "50", "10", "9"); NumberInputMenuSelection selection = _menu.GetInput() as NumberInputMenuSelection; Assert.AreEqual(9, selection?.Number); }
public void CorrectlyKeysOffOwnersHealth([Values(10, 50)] int maxHealth) { _owner.SetHealth(maxHealth); _menu.Build(_owner, _ownerTeam, _enemyTeam, null); _input.Push($"{maxHealth}", $"{maxHealth - 1}"); NumberInputMenuSelection selection = _menu.GetInput() as NumberInputMenuSelection; Assert.AreEqual(maxHealth - 1, selection?.Number); }
public override MenuSelection GetInput(BattleMove move, IMoveExecutor moveExecutor) { MenuSelection ret; NumberInputMenuSelection baseInputSelection = base.GetInput() as NumberInputMenuSelection; if (SubMenu == null) { ret = baseInputSelection; } else { MenuSelection subMenuSelection = SubMenu.RequiresBattleMoveInput ? SubMenu.GetInput(move, moveExecutor) : SubMenu.GetInput(); ret = new NumberInputMenuSelection(baseInputSelection?.Number ?? 0, subMenuSelection.Description, subMenuSelection.Move, subMenuSelection.Target, moveExecutor); } return(ret); }
private static bool Foo() { SelectEnemyTeamMenuManager enemyTeamGenerator = new SelectEnemyTeamMenuManager(Globals.Input, Globals.Output); BattleConfigurationSpecialFlag battleFlag; Team enemyTeam = enemyTeamGenerator.GetTeam(new MenuManager(Globals.Input, Globals.Output, Globals.MenuFactory), Globals.Input, Globals.Output, out battleFlag); NumberInputMenu levelInputMenu = new NumberInputMenu("What levels will your fighters be (min 1. Max 5)?", Globals.Input, Globals.Output, 1, 5); NumberInputMenuSelection levelInput = levelInputMenu.GetInput() as NumberInputMenuSelection; if (levelInput == null) { throw new Exception("something went terribly wrong, a NumberInputMenu did not return a NumberInputMenuSelection"); } int level = levelInput.Number; var playerOne = (HumanFighter)FighterFactory.GetFighter(FighterType.HumanControlledPlayer, level, "Dante"); var playerTwo = (HumanFighter)FighterFactory.GetFighter(FighterType.HumanControlledPlayer, level, "Arrokoh"); var playerTeam = new Team(new MenuManager(Globals.Input, Globals.Output, Globals.MenuFactory), playerOne, playerTwo); BattleMove doNothing = MoveFactory.Get(BattleMoveType.DoNothing); BattleMove feintAttack = MoveFactory.Get(BattleMoveType.Attack, "feint"); BattleMove shieldBuster = MoveFactory.Get(BattleMoveType.ShieldBuster); foreach (HumanFighter fighter in playerTeam.Fighters) { fighter.AddMove(doNothing); fighter.AddMove(feintAttack); fighter.AddMove(shieldBuster); } FakeBattleManager manager = new FakeBattleManager(Globals.ChanceService, Globals.Input, Globals.Output); manager.Battle(playerTeam, enemyTeam, config: new BattleManagerBattleConfiguration { SpecialBattleFlag = battleFlag }); return(true); }
public override MenuSelection GetInput() { NumberInputMenuSelection ret = null; var validRet = false; while (!validRet) { int retAsNumber; PrintPromptHeader(); string input = _input.ReadInput(); if (input == "") { _output.WriteLineError("input is required"); _input.WaitAndClear(_output); } else if (!int.TryParse(input, out retAsNumber)) { _output.WriteLineError("input not recognized as a number"); _input.WaitAndClear(_output); } else if (retAsNumber < MinValue || retAsNumber > MaxValue) { _output.WriteLineError($"input must be between {MinValue} and {MaxValue}, inclusive"); _input.WaitAndClear(_output); } else { validRet = true; ret = new NumberInputMenuSelection(retAsNumber); } } return(ret); }
protected override MenuSelection GetSubMenuInput(IMenu subMenu, MenuAction selectedAction) { NumberInputMenuSelection numberInputSelection = subMenu.GetInput() as NumberInputMenuSelection; if (numberInputSelection == null) { throw new InvalidOperationException("SelectEnemyFighterMenu's action's subMenu did not return a MenuAction of type NumberInputMenuSelection"); } TypedMenuAction <BattleConfigurationSpecialFlag> typedSelectedAction = selectedAction as TypedMenuAction <BattleConfigurationSpecialFlag>; if (typedSelectedAction == null) { throw new InvalidOperationException("SelectEnemyFighterMenu should have initialized its menu actions as TypedMenuAction<BattleConfigurationSpecialFlags>"); } FighterType selectedType = (FighterType)Enum.Parse(typeof(FighterType), selectedAction.CommandText); var menuSelection = new SelectEnemyFighterMenuSelection(selectedType, numberInputSelection.Number, typedSelectedAction.Item); return(menuSelection); }