public void StartGame() { // Setup new game board gameFlow game = new gameFlow(); bool KeepPlaying = true; bool[] gameOptions = new bool[] { true, true }; do { // Create new players Player player1 = new Player(); Player player2 = new Player(); // Display splash screen Console.Clear(); BattleShip.UI.GameWorkflow.DisplayMessages.StartScreen(); Console.ReadLine(); // Gather player 1 name and ship placement Console.Clear(); player1.Name = game.getPlayerName("1"); BattleShip.UI.GameWorkflow.ShipSetup.PlayerShipSetup(player1); // Gather player 2 name and ship placement Console.Clear(); player2.Name = game.getPlayerName("2"); BattleShip.UI.GameWorkflow.ShipSetup.PlayerShipSetup(player2); // Start game play &&&& Talking SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak("Lets play the game."); Console.WriteLine("\nLet's Play the Game!"); gameFlow.AlternatePlayerGame(player1, player2); // Roll game credits BattleShip.UI.GameWorkflow.DisplayMessages.RollCredits(); // Do you want to play again Console.ResetColor(); Console.Clear(); Console.WriteLine("\n\nWould you like to play again? Enter N for new game enter Q for quit."); //Talk talk.SetOutputToDefaultAudioDevice(); talk.Speak("Would you like to play again?"); string UserInput = Console.ReadLine().ToUpper(); if (UserInput != "N") { KeepPlaying = false; } } while (KeepPlaying); //Closing application Console.Clear(); Console.WriteLine("Press any key to close"); Console.ReadLine(); }
public static void AlternatePlayerGame(Player player1, Player player2) { bool isVictory = false; Player currentPlayer = player1; Player otherPlayer = player2; string userInput = ""; while (!isVictory) { Console.Clear(); DrawBoard.DrawBoardShotHistory(otherPlayer); DrawBoard.DrawBoardShips(currentPlayer); Coordinate coord; bool isValidCoordinate = false; FireShotResponse response = new FireShotResponse(); do { Console.ResetColor(); //Talking---this is repeated a bunch...possible loop to change/alternate the saying?? Or will have to leave out. SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak(String.Format("{0}, it's your turn. Stay on target.", currentPlayer.Name));//maybe just say FIRE! Console.WriteLine("\n\n{0}, enter a coordinate to fire a shot.", currentPlayer.Name); userInput = Console.ReadLine(); coord = ConvertInputToCoordinate(userInput); isValidCoordinate = CheckValidCoord(coord); if (!isValidCoordinate) { //Talking talk.SetOutputToDefaultAudioDevice(); talk.Speak(" Those are not the coordinates we were looking for! "); Console.WriteLine("\nInvalid Coordinate - Repeat Turn"); } else { response = otherPlayer.PlayerBoard.FireShot(coord); Console.Beep(); Console.Beep(); Console.Beep(); switch (response.ShotStatus) { case ShotStatus.Hit: //Talking talk.SetOutputToDefaultAudioDevice(); talk.Speak(" It's a hit! "); GameWorkflow.DisplayMessages.DisplayHitMessage(); Console.WriteLine("\nYou hit something!, Press Enter to continue...."); Console.ReadLine(); break; case ShotStatus.HitAndSunk: //Talking // SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak(string.Format(" With great power comes great responsiblity. You sank your opponents {0}",response.ShipImpacted)); GameWorkflow.DisplayMessages.DisplaySinkingShip(); Console.WriteLine("\nYou sank your opponent's {0}!, Press Enter to continue....", response.ShipImpacted); Console.ReadLine(); break; case ShotStatus.Miss: //Talking //SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak(" These are not the ships you are looking for. You didn't hit squat!"); GameWorkflow.DisplayMessages.DisplayMissMessage(); Console.WriteLine("\nYour projectile splashes into the ocean, you missed! \n\nPress Enter to continue...."); Console.ReadLine(); break; case ShotStatus.Duplicate: //talking //SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak(" Hey genius! You already tried that!"); Console.WriteLine("\nDuplicate shot - repeat turn. Press Enter to continue...."); Console.ReadLine(); break; case ShotStatus.Victory: //Talking //SpeechSynthesizer talk = new SpeechSynthesizer(); talk.SetOutputToDefaultAudioDevice(); talk.Speak(String.Format("May the force be with {0}! You sank all of your opponents ships. You won the game!", currentPlayer.Name)); GameWorkflow.DisplayMessages.DisplayVictoryMessage(); Console.WriteLine("\n{0}, you have sunk all of your opponents ships, you win!- End Game", currentPlayer.Name); System.Threading.Thread.Sleep(2000); break; } } } while (!isValidCoordinate || response.ShotStatus == ShotStatus.Duplicate); if (response.ShotStatus == ShotStatus.Victory) { isVictory = true; } else { isVictory = false; Player tempPlayer = currentPlayer; currentPlayer = otherPlayer; otherPlayer = tempPlayer; } } }