Advertisement
Guest User

Untitled

a guest
Nov 8th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1.  
  2. import java.util.Random;
  3.  
  4. public class Kosci {
  5. static int tura = 1;
  6. static boolean boolGracz1 = false;
  7. static boolean boolGracz1Win = false;
  8. static boolean boolGracz2 = false;
  9. static boolean boolGracz2Win = false;
  10.  
  11. String gracz1 = "Gracz 1";
  12. String gracz2 = "Gracz 2";
  13. static float totalSumPlayer1 = 0;
  14. static float totalSumPlayer2 = 0;
  15.  
  16. static int[] kosc1 = { 1, 2, 3, 4, 5, 6 };
  17. static int[] kosc2 = { 1, 2, 3, 4, 5, 6 };
  18.  
  19. public static void main(String[] args) {
  20.  
  21.  
  22. loop:
  23. while (tura <= 5) {
  24. System.out.println("***** Tura numer: " + tura + " *****");
  25.  
  26. outerLoop:
  27. if (boolGracz1 == false) {
  28.  
  29. System.out.println(" %% Gracz 1 %%");
  30. loopik:
  31. for (int rzut = 1; rzut <= 10; rzut++) {
  32.  
  33. int rand1 = new Random().nextInt(kosc1.length);
  34. int rand2 = new Random().nextInt(kosc2.length);
  35.  
  36. int liczba1 = kosc1[rand1];
  37. int liczba2 = kosc2[rand2];
  38.  
  39. System.out.println(" / Rzut numer: " + rzut + " / ");
  40. System.out.println(" Kosc1: " + liczba1);
  41. System.out.println(" Kosc2: " + liczba2);
  42. float sumaGracz1 = liczba1 + liczba2;
  43.  
  44. if (rzut == 1 && (sumaGracz1 == 7 || sumaGracz1 == 11)) {
  45.  
  46. System.out.println("suma: " + sumaGracz1);
  47. System.out.println("Wygrał gracz 1");
  48. boolGracz2 = true;
  49. boolGracz1Win = true;
  50. break outerLoop;
  51.  
  52. }
  53. if (rzut == 0 && (sumaGracz1 == 2 || sumaGracz1 == 12)) {
  54. System.out.println("Przegrywa gracz 1, rozpoczyna gracz 2");
  55. boolGracz2 = true;
  56. break outerLoop;
  57.  
  58. }
  59.  
  60. if (sumaGracz1 == 5) {
  61. System.out.println("Wygrał gracz 1");
  62. boolGracz1Win = true;
  63. break loop;
  64. }
  65.  
  66. else
  67. sumaGracz1 = sumaGracz1 + sumaGracz1 / rzut;
  68. System.out.println("suma: " + sumaGracz1);
  69. totalSumPlayer1 += sumaGracz1;
  70.  
  71. }
  72. System.out.println("total suma Gracz1: " + totalSumPlayer1);
  73. boolGracz2 = true;
  74. }
  75. endLoop: if (boolGracz2 == true) {
  76. System.out.println(" %% Gracz 2 %%");
  77. loopik2:
  78. for (int rzut = 1; rzut <= 10; rzut++) {
  79.  
  80. int rand1 = new Random().nextInt(kosc1.length);
  81. int rand2 = new Random().nextInt(kosc2.length);
  82.  
  83. int liczba1 = kosc1[rand1];
  84. int liczba2 = kosc2[rand2];
  85.  
  86. System.out.println(" / Rzut numer: " + rzut + " / ");
  87. System.out.println(" Kosc1: " + liczba1);
  88. System.out.println(" Kosc2: " + liczba2);
  89. float sumaGracz2 = liczba1 + liczba2;
  90.  
  91. if (rzut == 1 && (sumaGracz2 == 7 || sumaGracz2 == 11)) {
  92. System.out.println("suma: " + sumaGracz2);
  93. System.out.println("Wygrał gracz 2");
  94. boolGracz2Win = true;
  95. break endLoop;
  96.  
  97. }
  98. if (rzut == 0 && (sumaGracz2 == 2 || sumaGracz2 == 12)) {
  99. System.out.println("Przegrywa gracz 2, rozpoczyna gracz 1");
  100. // boolGracz2 = true;
  101. break endLoop;
  102.  
  103. }
  104. if (sumaGracz2 == 5) {
  105. System.out.println("Wygrał gracz 2");
  106. boolGracz2Win = true;
  107. break loop;
  108. } else
  109. sumaGracz2 = sumaGracz2 + sumaGracz2 / rzut;
  110. System.out.println("suma: " + sumaGracz2);
  111. totalSumPlayer2 += sumaGracz2;
  112.  
  113. }
  114.  
  115. System.out.println("total suma Gracz2: " + totalSumPlayer2);
  116.  
  117. }
  118.  
  119. tura++;
  120.  
  121. }
  122.  
  123. System.out.println("*************koniec************");
  124. System.out.println("total suma Gracz1: " + totalSumPlayer1);
  125. System.out.println("total suma Gracz2: " + totalSumPlayer2);
  126. if ((boolGracz1Win == true) || (boolGracz2Win == false && totalSumPlayer1 < totalSumPlayer2))
  127. System.out.println("Wygrał gracz 1");
  128. if ((boolGracz2Win == true) || (boolGracz1Win == false && totalSumPlayer2 < totalSumPlayer1)
  129. || ((boolGracz2Win == true && totalSumPlayer1 > totalSumPlayer2)))
  130. System.out.println("Wygrał gracz 2");
  131. if (boolGracz1Win == true && boolGracz2Win == true) {
  132. System.out.println("remis");
  133. }
  134.  
  135. }
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement