public void BattleEngine_EndBattle_Default_Should_Pass() { // Arrange // Act var result = Engine.EndBattle(); // Reset // Assert Assert.AreEqual(true, result); }
public void BattleEngine_EndBattle_Should_Pass() { MockForms.Init(); // Can create a new battle engine... var myBattleEngine = new BattleEngine(); myBattleEngine.StartBattle(true); myBattleEngine.EndBattle(); var Actual = myBattleEngine.BattleRunningState(); var Expected = false; Assert.AreEqual(Expected, Actual, TestContext.CurrentContext.Test.Name); }
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(); }); }
// 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()); } } }
/// <summary> /// Call to the Engine to End the Battle /// </summary> // End Battle public void EndBattle() { BattleEngine.EndBattle(); }