public void RoundEngine_ClearList_PotionsPool_Should_Pass() { //Arrange //populating Potions Potion pool Engine.populatePotionsList(); //adding a character to the potions pool BaseMonster monster = new BaseMonster(); Engine.NewRound(); //Act Engine.EndRound(); //Reset //Assert Assert.AreEqual(Engine.potionPool.Count, 0); }
private bool _needsRefresh; // boolean for whether data is stale or not // Constructor: loads data and listens for broadcast from views public BattleViewModel() { Title = "Battle Begin"; // Initialize battle engine BattleEngine = new BattleEngine(); // Create observable collections SelectedCharacters = new ObservableCollection <Character>(); AvailableCharacters = new ObservableCollection <Character>(); SelectedMonsters = new ObservableCollection <Monster>(); availItems = new ObservableCollection <Item>(); // Load data command LoadDataCommand = new Command(async() => await ExecuteLoadDataCommand()); // Load the data ExecuteLoadDataCommand().GetAwaiter().GetResult(); // For adding Characters to party MessagingCenter.Subscribe <CharactersSelectPage, IList <Character> >(this, "AddData", (obj, data) => { SelectedCharacters.Clear(); BattleEngine.CharacterList = data.ToList <Character>(); foreach (var c in data) { SelectedCharacters.Add(c); } }); //Messages for adding a character to party MessagingCenter.Subscribe <CharactersSelectPage, Character>(this, "AddSelectedCharacter", async(obj, data) => { SelectedListAdd(data); }); // Messages for removing a character from the party MessagingCenter.Subscribe <CharactersSelectPage, Character>(this, "RemoveSelectedCharacter", async(obj, data) => { SelectedListRemove(data); }); //Messages to start new round MessagingCenter.Subscribe <BattleEngine, RoundEnum>(this, "NewRound", async(obj, data) => { BattleEngine.NewRound(); }); //Messages for round next turn MessagingCenter.Subscribe <BattlePage, RoundEnum>(this, "RoundNextTurn", async(obj, data) => { ExecuteLoadDataCommand().GetAwaiter().GetResult(); BattleEngine.RoundNextTurn(); }); // Messages to end battle MessagingCenter.Subscribe <BattlePage, RoundEnum>(this, "EndBattle", async(obj, data) => { BattleEngine.EndBattle(); }); }
public async Task HackathonScenario_Scenario_1_Default_Should_Pass() { /* * Scenario Number: * 1 * * Description: * Make a Character called Mike, who dies in the first round * * Changes Required (Classes, Methods etc.) List Files, Methods, and Describe Changes: * No Code changes requied * * Test Algrorithm: * Create Character named Mike * Set speed to -1 so he is really slow * Set Max health to 1 so he is weak * Set Current Health to 1 so he is weak * * Startup Battle * Run Auto Battle * * Test Conditions: * Default condition is sufficient * * Validation: * Verify Battle Returned True * Verify Mike is not in the Player List * Verify Round Count is 1 * */ //Arrange // Set Character Conditions BattleEngine.MaxNumberPartyCharacters = 1; var CharacterPlayerMike = new CharacterModel { SpeedAttribute = -1, // Will go last... Level = 1, CurrentHealth = 1, ExperiencePoints = 1, Name = "Mike", }; // Make list of players var playerList = new List <CharacterModel>(); // Add Mike to player list playerList.Add(CharacterPlayerMike); // Give player list to BattleEngine BattleEngine.SetParty(playerList); // Enable auto battle BattleEngine.SetAutoBattle(true); // Set Monster Conditions // (Auto Battle will add the monsters) //Act var result = BattleEngine.startBattle(); //Reset BattleEngine.Referee.AutoBattleEnabled = false; BattleEngine.NewRound(); //Assert Assert.AreEqual(true, result); Assert.AreEqual(null, BattleEngine.Referee.Characters.Find(m => m.Name.Equals("Mike"))); Assert.AreEqual(1, BattleEngine.Referee.BattleScore.RoundCount); }
// If UI is enabled, there will be popups that guide you through battle as you click the next turn button // If not, it will drop you straight to the result page public async void BattleEngineStart_Command(object sender, EventArgs e) { #if !EnableUI do { // If the round is over start a new one... if (RoundResult == RoundEnum.NewRound) { myBattleEngine.NewRound(); } PlayerInfo currentPlayer = myBattleEngine.GetNextPlayerInList(); // Check if character or monster if (currentPlayer.PlayerType == PlayerTypeEnum.Character) { string id = null; RoundResult = myBattleEngine.RoundNextTurn(id); } // else monster turn else { RoundResult = myBattleEngine.RoundNextTurn(); } Debug.WriteLine(myBattleEngine.TurnMessage); } while (RoundResult != RoundEnum.GameOver); #endif #if EnableUI if (RoundResult != RoundEnum.GameOver) { // If the round is over start a new one... if (RoundResult == RoundEnum.NewRound) { myBattleEngine.NewRound(); var answer = await DisplayAlert("New Round", "Begin", "Start", "Cancel"); if (answer) { await Navigation.PushAsync(new ManualBattlePage(myBattleEngine, RoundResult)); return; } } PlayerInfo currentPlayer = myBattleEngine.GetNextPlayerInList(); // Check if character or monster if (currentPlayer.PlayerType == PlayerTypeEnum.Character) { string id = null; var dataset = myBattleEngine.MonsterList.Where(a => a.Alive).ToList(); string[] names = new string[dataset.Count]; string[] IDs = new string[dataset.Count]; int ctr = 0; foreach (var data in dataset) { names[ctr] = data.Name; IDs[ctr] = data.Guid; ctr++; } var action = await DisplayActionSheet("Select Monster", null, null, names); ctr = 0; foreach (var data in dataset) { if (action == data.Name) { id = IDs[ctr]; break; } ctr++; } RoundResult = myBattleEngine.RoundNextTurn(id); } // else monster turn else { RoundResult = myBattleEngine.RoundNextTurn(); } var response = await DisplayAlert("Turn Result", myBattleEngine.TurnMessage, "Continue", "Quit"); if (!response) { await Navigation.PushAsync(new OpeningPage()); } } #endif if (RoundResult == RoundEnum.GameOver) { myBattleEngine.EndBattle(); string result = "Battle Ended" + " Total Experience :" + myBattleEngine.BattleScore.ExperienceGainedTotal + " Rounds :" + myBattleEngine.BattleScore.RoundCount + " Turns :" + myBattleEngine.BattleScore.TurnCount + " Monster Kills :" + myBattleEngine.BattleScore.MonstersKilledList; var answer = await DisplayAlert("Game Result", result, "Set Name", "Restart"); if (answer) { // Link to enter name await Navigation.PushAsync(new EditScorePage(new ScoreDetailViewModel(myBattleEngine.BattleScore))); } else { await Navigation.PushAsync(new OpeningPage()); } } }
public void HakathonScenario_4_greedy_char_drinks_Health_Potions_Should_Pass() { /* * Scenario Number: * #4 * * Description: * Every Round should have 6 new health potions added * and if you are in auto battle and have a character bellow 20% * they are really greedy and would drink all potions before an attack * * Changes Required (Classes, Methods etc.) List Files, Methods, and Describe Changes: * RoundEngine.cs * added a populatePotionsFunction * new round populates the potionspool * TurnEngine.cs * add a function called DrinkAllPotions will have a character drink all health potions even if they only need one * added a fucntion called bellowTwentyHealth will return true is health bellow 20 percent * edited Attack to have a character that is bellow 20 percent drink all the potions * Base Engine.cs * add a variable called potions pool * * Test Algrorithm: * make a character bellow 20 percent health * make round healing on * make auto battle on * have a new round made to populate potion pool * call attack with greedy character * check the count of health potions in the pool * Assert that the count is 0 * * Test Conditions: * potion pool is full and there is a character with less than 20 percent health * * * Validation: * Validate the potions pool only has mana potions. it is to show that * your character is greedy and will drink all the potions before anyone attacks */ //Arrange //turning healing on Engine.RoundHealing = RoundHealingEnum.Healing_on; Engine.BattleScore.AutoBattle = true; PlayerInfoModel character = new PlayerInfoModel(); character.PlayerType = PlayerTypeEnum.Character; character.MaxHealth = 100; double Bellow = (double)(character.MaxHealth * .20); character.CurrHealth = (int)(Bellow - 1); Engine.CharacterList.Add(character); //Act //seeing if the potion list will be populated with 6th potions Engine.NewRound(); Engine.Attack(character); bool potions_Health_0_count = false; int count = 0; foreach (PotionsModel potion in Engine.potionPool) { if (potion.GetPotionType() == PotionsEnum.Health) { count++; } } if (count == 0) { potions_Health_0_count = true; } //Assert Assert.AreEqual(true, potions_Health_0_count); }
/// <summary> /// Call to the Engine for a New Round to Happen /// </summary> public void NewRound() { BattleEngine.NewRound(); }
public void HackathonScenario_Scenario_14_If_Confusion_Turn_Character_Should_Skip() { /* * Scenario Number: * 14 * * Description: * Confusion, have % chance to occuring each round. * If happens, then confusion occurs for each monster and character for that round * Each party member rolls a chance of being confused. * * Changes Required (Classes, Methods etc.) List Files, Methods, and Describe Changes: * Change to Turn Engine, Take Turn method, added switch check and dice roll * Changed BaseEngine, added boolean switch for enabling confusion, and is confusion turn or not. * Check for Experience gained is 0 * * Test Algrorithm: * Create Character named Bob * Create Monster * Call TakeTurn * * Test Conditions: * Test with Character of Named ConfusionCharacter * * Validation: * Verify Experience gained is 0 * */ //Arrange DiceHelper.EnableForcedRolls(); DiceHelper.SetForcedRollValue(0); // Set Character Conditions BattleEngine.MaxNumberPartyCharacters = 1; var TestSword = ItemViewModel.Dataset.Where(a => a.Location == ItemLocationEnum.PrimaryHand).FirstOrDefault(); var CharacterPlayer = new EntityInfoModel( new CharacterModel { Level = 10, CurrentHealth = 200, MaxHealth = 200, //TestDamage = 123, Experience = 100, Name = "Confused Character", }); CharacterPlayer.Attack = 25; CharacterPlayer.Speed = 20; CharacterPlayer.Defense = 25; CharacterPlayer.AddItem(ItemLocationEnum.PrimaryHand, TestSword.Id); BattleEngine.CharacterList.Add(CharacterPlayer); // Set Monster Conditions // Add a monster to attack BattleEngine.MaxNumberPartyCharacters = 1; var MonsterPlayer = new EntityInfoModel( new MonsterModel { Speed = 10, Level = 10, CurrentHealth = 100, Experience = 100, Name = "Monster", }); BattleEngine.CharacterList.Add(MonsterPlayer); // Have dice roll to 20 DiceHelper.EnableForcedRolls(); DiceHelper.SetForcedRollValue(20); // EnableConfusionRounds BattleEngine.EnableConfusionRound = true; BattleEngine.NewRound(); //Act var result = BattleEngine.TakeTurn(CharacterPlayer); //Reset DiceHelper.DisableForcedRolls(); BattleEngine.EnableConfusionRound = false; //Assert Assert.AreEqual(true, result); Assert.AreEqual(AutoBattleEngine.BattleScore.ExperienceGainedTotal, 0); }