// Button for next round in game private async void NextRoundButton_Clicked(object sender, EventArgs e) { _viewModel.NewRound(); await Navigation.PushAsync(new BattlePage(BattleViewModel.Instance)); Navigation.RemovePage(this); }
/// <summary> /// Next Turn Button /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public async void OnNextClicked(object sender, EventArgs args) { // Hold the current state var CurrentRoundState = _viewModel.BattleEngine.RoundStateEnum; // If the round is over start a new one... if (CurrentRoundState == RoundEnum.NewRound) { //ItemDropPage //Send the user to the party page to reorganize their items ShowModalPageBattleParty(); _viewModel.NewRound(); MessagingCenter.Send(this, "NewRound"); Debug.WriteLine("New Round :" + _viewModel.BattleEngine.BattleScore.RoundCount); } // Check for Game Over if (CurrentRoundState == RoundEnum.GameOver) { _viewModel.EndBattle(); MessagingCenter.Send(this, "EndBattle"); Debug.WriteLine("End Battle"); // Output Formatted Results var myResult = _viewModel.BattleEngine.GetResultsOutput(); Debug.Write(myResult); // Let the user know the game is over ClearMessages(); // Clear message AppendMessage("Game Over\n"); // Show Game Over // Clear the players from the center of the board DrawGameBoardClear(); // Change to the Game Over Button GameNextButton.IsVisible = false; GameOverButton.IsVisible = true; // Save the Score to the Score View Model, by sending a message to it. var myScore = _viewModel.BattleEngine.BattleScore; MessagingCenter.Send(this, "AddData", myScore); return; } // Do the turn... _viewModel.RoundNextTurn(); MessagingCenter.Send(this, "RoundNextTurn"); // Output the Game Board DrawGameBoardAttackerDefender(); // Output The Message that happened. GameMessage(); // Output TimeWarp If it Happens if (GameGlobals.TimeWarpEnabled) { AppendMessage("Time Warp Happened\n"); } }
// Initialize page and populate buttons public BattleMonsterListPage() { InitializeComponent(); _viewModel = BattleViewModel.Instance; //MessagingCenter.Send(this, "StartBattle"); //handle round number 2+ Debug.WriteLine("Current round count in the monsterListPage: " + _viewModel.BattleEngine.BattleScore.RoundCount); if (_viewModel.BattleEngine.BattleScore.RoundCount > 1) { _viewModel.NewRound(); } //handles rounds 1 else { _viewModel.StartBattle(); Debug.WriteLine("Battle Start" + " Characters :" + BattleViewModel.Instance.BattleEngine.CharacterList.Count); // Load the Characters into the Battle Engine //MessagingCenter.Send(this, "LoadCharacters"); _viewModel.LoadCharacters(); // Start the Round //MessagingCenter.Send(this, "StartRound"); _viewModel.StartRound(); Debug.WriteLine("Round Start" + " Monsters:" + BattleViewModel.Instance.BattleEngine.MonsterList.Count); foreach (Models.Monster Monster in BattleViewModel.Instance.BattleEngine.MonsterList) { Debug.WriteLine("Round Start" + " Monster List:" + Monster.Name); } Debug.WriteLine("round start observable collection monster list: "); } Datalist = BattleViewModel.Instance.BattleEngine.MonsterList; BindingContext = Datalist; foreach (var data in Datalist) { var myHP = new Label() { Text = "HP : " + data.GetHealthCurrent(), TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; var myLevel = new Label() { Text = "Level : " + data.Level, TextColor = Color.Black, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; var myName = new Label() { Text = data.Name, TextColor = Color.White, HorizontalTextAlignment = TextAlignment.Center, VerticalTextAlignment = TextAlignment.Center }; var myURI = "Troll2.png"; if (!string.IsNullOrEmpty(data.ImageURI)) { myURI = data.ImageURI; } var myImage = new Image() { //Source = FileImageSource.FromUri(new Uri(myURI)), Source = myURI, WidthRequest = 50.0, HeightRequest = 50.0 }; StackLayout OuterFrame = new StackLayout { MinimumWidthRequest = 400, WidthRequest = 400, Padding = 10 }; OuterFrame.Children.Add(myImage); OuterFrame.Children.Add(myName); OuterFrame.Children.Add(myLevel); OuterFrame.Children.Add(myHP); MonsterListFrame.Children.Add(OuterFrame); } }
// Handles when user chooses an option and hits submit public async void SubmitClicked(object sender, EventArgs args) { //send the selected monster info into target if (_viewModel.BattleEngine.PlayerCurrent.PlayerType == PlayerTypeEnum.Character) { _viewModel.BattleEngine.ManualTarget = SelectedMonster; } //update xaml front end local message section if (_viewModel.BattleEngine.TurnType == MoveEnum.Rest) { LocalMessageText.Text = localMessages; } else if (_viewModel.BattleEngine.TurnType == MoveEnum.UseItem) { LocalMessageText.Text = localMessages; } else { LocalMessageText.Text = null; } //do the turn _viewModel.RoundNextTurn(); //update front end options after turn taken if (_viewModel.BattleEngine.PlayerCurrent.PlayerType == PlayerTypeEnum.Character) { ItemPool.IsEnabled = true; GameNextButton.IsEnabled = false; AttackButton.IsEnabled = true; RestButton.IsEnabled = true; UseItemButton.IsEnabled = true; } else { ItemPool.IsEnabled = false; GameNextButton.IsEnabled = true; AttackButton.IsEnabled = false; RestButton.IsEnabled = false; UseItemButton.IsEnabled = false; } // Hold the current state var CurrentRoundState = _viewModel.BattleEngine.RoundStateEnum; Debug.WriteLine("Current round state after this turn: " + CurrentRoundState.ToString()); // Draw the Game Board DrawGameBoardAttackerDefender(); RefreshMonsters(); RefreshCharacters(); //used if im using an observable collection //_viewModel.SyncMonsterAndCharacterLists(); //updates current player up in frontend OnPropertyChanged(); //reset all these for next turn ableToSelectMonster = false; SelectedMonster = null; // If the round is over start a new one... if (CurrentRoundState == RoundEnum.NewRound) { Debug.WriteLine("NEW ROUND TRIGGERED"); _viewModel.NewRound(); // Show new round and Round count Debug.WriteLine("New Round :" + _viewModel.BattleEngine.BattleScore.RoundCount); //push up modal monster list page to show new monsters youre fighting ShowModalPageMonsterList(); //StartGameSetting(); // Show name of current player Debug.WriteLine("current player: " + _viewModel.BattleEngine.PlayerCurrent.Name); if (_viewModel.BattleEngine.PlayerCurrent.PlayerType == PlayerTypeEnum.Character) { GameNextButton.IsEnabled = false; AttackButton.IsEnabled = true; RestButton.IsEnabled = true; UseItemButton.IsEnabled = true; ItemPool.IsEnabled = true; } else { GameNextButton.IsEnabled = true; AttackButton.IsEnabled = false; RestButton.IsEnabled = false; UseItemButton.IsEnabled = false; ItemPool.IsEnabled = false; } OnPropertyChanged(); } // Check for Game Over if (CurrentRoundState == RoundEnum.GameOver) { //MessagingCenter.Send(this, "EndBattle"); _viewModel.EndBattle(); Debug.WriteLine("End Battle"); // Output Formatted Results var myResult = _viewModel.BattleEngine.GetResultsOutput(); Debug.Write(myResult); OnPropertyChanged(); // Let the user know the game is over GameMessage("Game Over\n"); // Change to the Game Over Button GameNextButton.IsVisible = false; GameOverButton.IsVisible = true; return; } // Output The Message that happened. GameMessage(_viewModel.BattleEngine.BattleMessages.TurnMessage); Debug.WriteLine("List of characters and HP remaining: "); foreach (Models.Character character in _viewModel.BattleEngine.CharacterList) { Debug.WriteLine("Name : " + character.Name); Debug.WriteLine("HP : " + character.CharacterAttribute.getCurrentHealth() + "/" + character.CharacterAttribute.getMaxHealth()); } Debug.WriteLine("\n"); Debug.WriteLine("List of monsters and HP remaining: "); foreach (Models.Monster monster in _viewModel.BattleEngine.MonsterList) { Debug.WriteLine("Name : " + monster.Name); Debug.WriteLine("HP : " + monster.MonsterAttribute.getCurrentHealth() + "/" + monster.MonsterAttribute.getMaxHealth()); } }
//do this to display next turn button public async void Turn_Command(object sender, EventArgs e) { // go to the next turn _instanceC.RoundNextTurn(); //MessagingCenter.Send(this, "RoundNextTurn"); // Hold the current state var CurrentRoundState = _instanceC.BattleEngine.RoundStateEnum; // If the round is over start a new one... if (CurrentRoundState == RoundEnum.NewRound) { ClearMessages(); _instanceC.NewRound(); // MessagingCenter.Send(this, "NewRound"); Debug.WriteLine("!!!!!!!!!!!!!!New Round :" + _instanceC.BattleEngine.BattleScore.RoundCount); //ShowModalPageMonsterList(); } // Check for Game Over if (CurrentRoundState == RoundEnum.GameOver) { _instanceC.EndBattle(); //MessagingCenter.Send(this, "EndBattle"); Debug.WriteLine("End Battle!!!!!!!!!!!!!!!!!!!"); // output results of the game after battle is over var myResult = _instanceC.BattleEngine.GetResultsOutput(); var myScore = _instanceC.BattleEngine.GetScoreValue(); Debug.Write(myResult); // Let the user know the game is over ClearMessages(); // Clear message AppendMessage("Game Over\n"); // Show Game Over var outputString = "Mellow Fox Battle Over!"; // the pop up for either cancel or see the score details var action = await DisplayActionSheet(outputString, "Cancel", null, "View Score Results"); // Show the results if (action == "View Score Results") { var myScoreObject = _instanceC.BattleEngine.GetScoreObject(); await Navigation.PushAsync(new GameOver(new ScoreDetailViewModel(myScoreObject))); //await Navigation.PushAsync(new ScoreDetailPage(new ScoreDetailViewModel(myScoreObject))); } return; } //updates the data _instanceC.LoadDataCommand.Execute(null); // game message GameMessage(); }