Advertisement
Guest User

Game Number wars

a guest
Sep 3rd, 2020
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class GameNumberWars2 {
  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 numberWars = 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. if (numberWars) {
  18. if (card1 > card2) {
  19. System.out.println("Number wars!");
  20. System.out.printf("%s is winner with %d points", namePlayerOne, points1);
  21. } else {
  22. System.out.printf("%s is the winner with %d points", namePlayerTwo, points2 );
  23. }
  24. break;
  25. }
  26. if (card1 == card2) {
  27. input = scanner.nextLine();
  28. numberWars = true;
  29. continue;
  30. }
  31. if (card1 > card2) {
  32. points1 = points1 + (card1 - card2);
  33. } else {
  34. points2 = points2 + (card2 - card1);
  35. }
  36. input = scanner.nextLine();
  37. }
  38. if (!numberWars) {
  39. System.out.printf("%s has %d points%n", namePlayerOne, points1);
  40. System.out.printf("%s has %d points", namePlayerTwo, points2);
  41.  
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement