From Subtle Pheasant, 6 Years ago, written in Plain Text.
Embed
  1. package run;
  2.  
  3.  
  4. import java.util.ArrayList;
  5. import java.util.InputMismatchException;
  6. import java.util.Scanner;
  7.  
  8. import player.Player;
  9. import selectionMenu.PostSelectionMenu;
  10. import selectionMenu.PreSelectionMenu;
  11. /**
  12.  * @author Cormac
  13.  * t
  14.  *
  15.  */
  16. public class EndGame {
  17.        
  18.         public static void gameEnder(Player player, ArrayList<Player> players) throws InputMismatchException {
  19.                
  20.                 Scanner restartGameScanner = new Scanner(System.in);
  21.  
  22.                 if (PreSelectionMenu.isExitedGame() == true || PostSelectionMenu.isExitedGame() == true) {
  23.                         System.out.println(player.getPlayerName()+" took the coward's way out. Game Over!");
  24.                 } else {
  25.                         System.out.println(player.getPlayerName()+" has gone bankrupt. Game Over!");
  26.                 }
  27.                
  28.                 determineWinner(players);
  29.                
  30.                 System.out.println("Sadly, all good things must come to an end. And so this game of Technopoly draws to a close.");
  31.                 System.out.println("But, just for you, I'm willing to let you take another ride on the Technopoly rollercoaster. Do you want to play again?");
  32.                 System.out.println("Please make your selection: ");
  33.                 System.out.println("1. Yes");
  34.                 System.out.println("2. No");
  35.                
  36.                 int restartGameChoice;
  37.         boolean valid = false;
  38.                 do {
  39.             try {
  40.                 restartGameChoice = restartGameScanner.nextInt();
  41.                 switch (restartGameChoice) {
  42.                 case 1:
  43.                     System.out.println("As you wish! The Cosmic Ballet goes on!");
  44.                                 //startGame();
  45.                     valid = true;
  46.                     break;
  47.                 case 2:
  48.                         System.out.println("As you wish. Until we meet again, my friends!");
  49.                     valid = true;
  50.                     break;
  51.                 default:
  52.                     System.out.println("Invalid selection, try again");
  53.                     valid = false;
  54.                 }
  55.             } catch (InputMismatchException e) {
  56.                 System.out.println("Invalid input, please try again.");
  57.                 restartGameScanner.next();
  58.             }
  59.         } while (!valid);
  60.                
  61.                 restartGameScanner.close();
  62.                
  63.         }
  64.        
  65.         public static void determineWinner(ArrayList<Player> players) {
  66.                 int highestBalance = -9999;
  67.                 String winner = "";
  68.                 boolean draw = false;
  69.                 for (Player element : players) {
  70.                         if (element.getCurrentBalance() > highestBalance) {
  71.                                         highestBalance = element.getCurrentBalance();
  72.                                         winner = element.getPlayerName();
  73.                                 } else if (element.getCurrentBalance() == highestBalance) {
  74.                                         System.out.println("Incredible! "+element.getPlayerName() +" has the exact same amount of money as "+winner+"! It's a draw!");
  75.                                         draw = true;
  76.                                 }
  77.                         }
  78.                 if (draw == true) {
  79.                         System.out.println("The game has ended as a draw, with the following players sharing the wealth and glories of victory! Truly, the real Technopoly was friendship all along.");
  80.                         for (Player element : players) {
  81.                                 if (element.getCurrentBalance() == highestBalance) {
  82.                                         System.out.println(element.getPlayerName());
  83.                                 }
  84.                         } System.out.println();
  85.                 } else {
  86.                         System.out.println("Congratulations, "+winner+", you have won the game with an astonishing "+highestBalance+" in the bank! You may lord this victory over your friends for the rest of time.");
  87.                         System.out.println();
  88.                 }
  89.                
  90.                 System.out.println("Final Rankings: ");
  91.                 for (Player element : players) {
  92.                         System.out.println(element.getPlayerName()+" ended the game with "+element.getCurrentBalance()+" in their account.");
  93.                 } System.out.println();
  94.         }
  95. }