Advertisement
Guest User

Untitled

a guest
Oct 13th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. package com.company;
  2. import java.util.*;
  3.  
  4. public class Main {
  5.  
  6. public static void main(String[] args) {
  7. Init();
  8. }
  9.  
  10. public static class Player{
  11. Scanner input = new Scanner(System.in);
  12. String name = input.nextLine();
  13. }
  14.  
  15. public static class Data{
  16. int value = 3;
  17. }
  18.  
  19. public static void Init(){
  20. boolean player = true;
  21. Data pile1 = new Data();
  22. Data pile2 = new Data();
  23. Data pile3 = new Data();
  24. print("What is the name of the first player?: ");
  25. Player player1 = new Player();
  26. print("And the second?: ");
  27. Player player2 = new Player();
  28. pile2.value = 4;
  29. pile3.value = 5;
  30. int[] piles;
  31. piles = new int[]{pile1.value,pile2.value,pile3.value};
  32. Display(player1.name, player2.name, piles, player);
  33. }
  34.  
  35. public static void Display(String player1, String player2, int[] piles, boolean player){
  36. for(int i = 0; i <= 2; i++){
  37. println("Pile "+ (i + 1) + " : " + piles[i]);
  38. }
  39. gamePlay(player1, player2, piles, player);
  40. }
  41.  
  42. public static void gamePlay(String name1,String name2,int[] piles, boolean player){
  43. Scanner input = new Scanner(System.in);
  44. int choice = 0;
  45. do {
  46. if (arraySum(piles) == 0){
  47. if (player == true){
  48. println("Player "+ name1 + " wins!");
  49. }
  50. else{
  51. println("Player "+ name2 + " wins!");
  52. }
  53. println("Thanks for playing");
  54. System.exit(0);
  55. }
  56. if (player) {
  57. print("What pile will you choose " + name1 + "?:");
  58. } else {
  59. print("What pile will you choose " + name2 + "?:");
  60. }
  61. choice = input.nextInt();
  62.  
  63. if (choice > 3 | choice < 1) {
  64.  
  65. println("That's not an option bud");
  66. }
  67. } while (choice > 3 | choice < 1);
  68.  
  69. int out = 0;
  70. do{
  71. print("How many are we taking out?: ");
  72. out = input.nextInt();
  73.  
  74. if(out < piles[choice - 1]){
  75. println(("Sorry, that's an invalid choice."));
  76. }
  77. else{
  78. piles[choice - 1] = piles[choice - 1] - out;
  79. player = !player;
  80. Display(name1, name2,piles, player);
  81. }
  82. println(out + " have been take out");
  83. } while (out < piles[choice - 1]);
  84. }
  85.  
  86. public static int arraySum(int[] array){
  87. int x = 0;
  88. for(int i = 0; i <= 2; i++){
  89. x += array[i];
  90. }
  91. return x;
  92. }
  93.  
  94. public static void println(Object line){
  95.  
  96. System.out.println(line);
  97. }
  98.  
  99. public static void print(Object line){
  100. System.out.print(line);
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement