Guest User

Game Number wars

a guest
Sep 10th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameNumberWars {
  4. public static void main(String[] args) {
  5. Scanner scanner = new Scanner(System.in);
  6.  
  7. String namePlayerOne = scanner.nextLine();
  8. String namePlayerTwo = scanner.nextLine();
  9. int points1 = 0;
  10. int points2 = 0;
  11. boolean isNumberWars = false;
  12.  
  13. String input = scanner.nextLine();
  14. while (!input.equals("End of game")) {
  15. int card1 = Integer.parseInt(input);
  16. int card2 = Integer.parseInt(scanner.nextLine());
  17.  
  18.  
  19. if (card1 > card2) {
  20. points1 = points1 + (card1 - card2);
  21. } else if (card2 > card1) {
  22. points2 = points2 + (card2 - card1);
  23. } else {
  24. System.out.println("Number wars!");
  25. isNumberWars = true;
  26. while (true) {
  27. card1 = Integer.parseInt(scanner.nextLine());
  28. card2 = Integer.parseInt(scanner.nextLine());
  29. if (card1 > card2) {
  30. System.out.printf("%s is winner with %d points", namePlayerOne, points1);
  31. break;
  32. } else if (card2 > card1) {
  33. System.out.printf("%s is the winner with %d points", namePlayerTwo, points2);
  34. break;
  35. }
  36. }
  37. }
  38. if (isNumberWars) {
  39. break;
  40. }
  41. input = scanner.nextLine();
  42. }
  43. if (input.equals("End of game")) {
  44.  
  45. System.out.printf("%s has %d points%n", namePlayerOne, points1);
  46. System.out.printf("%s has %d points", namePlayerTwo, points2);
  47. }
  48.  
  49. }
  50. }
  51.  
Add Comment
Please, Sign In to add comment