Advertisement
Guest User

iojjo

a guest
Oct 22nd, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. public class Main {
  2. public static void main(String[] args) {
  3.  
  4. Donkey D = new Donkey();
  5. Monkey M = new Monkey();
  6. Parrot P = new Parrot();
  7.  
  8. /*D.show();
  9. M.show();
  10. P.show();
  11. */
  12.  
  13. Judge J = new Judge();
  14. //wybór graczy
  15. J.play(M.show(),P.show());
  16. }
  17. }
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34. public interface Player {
  35. int show();
  36. }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. public class Donkey implements Player{
  48.  
  49. @Override
  50. public int show() {
  51. System.out.println("Donkey choose Rock");
  52. return 0;
  53. }
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. public class Monkey implements Player {
  79.  
  80. @Override
  81. public int show() {
  82. int random = (int)(Math.random() * 3);
  83. if (random == 0){
  84. System.out.println("Monkey choose Rock");
  85. }
  86. else if (random == 1){
  87. System.out.println("Monkey choose Papper");
  88. }
  89. else if (random == 2){
  90. System.out.println("Monkey choose Scissors");
  91. }
  92. return random;
  93. }
  94. }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. public class Parrot implements Player {
  107.  
  108. @Override
  109. public int show() {
  110. int random = (int)(Math.random() * 2);
  111. if (random == 0){
  112. System.out.println("Parrot choose Rock");
  113. }
  114. else if (random == 1){
  115. System.out.println("Parrot choose Papper");
  116. }
  117. return random;
  118. }
  119. }
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134. public class Judge {
  135.  
  136. void play(int g1, int g2){
  137. // 0 - Rock
  138. // 1 - Papper
  139. // 2 - Scissors
  140. if(g1==0 && g2==1) {
  141. System.out.println("");
  142. System.out.println("Papper beats Rock");
  143. }
  144. else if(g1==0 && g2==2) {
  145. System.out.println("");
  146. System.out.println("Rock beats Scissors");
  147. }
  148. else if(g1==1 && g2==0) {
  149. System.out.println("");
  150. System.out.println("Papper beats Rock");
  151. }
  152. else if(g1==1 && g2==2) {
  153. System.out.println("");
  154. System.out.println("Scissors beats Papper");
  155. }
  156. else if(g1==2 && g2==0) {
  157. System.out.println("");
  158. System.out.println("Rock beats Scissors");
  159. }
  160. else if(g1==2 && g2==1) {
  161. System.out.println("");
  162. System.out.println("Scissors beats Papper");
  163. }
  164. else if(g1==g2){
  165. System.out.println("");
  166. System.out.println("DRAW");
  167. }
  168. }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement