Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- Donkey D = new Donkey();
- Monkey M = new Monkey();
- Parrot P = new Parrot();
- /*D.show();
- M.show();
- P.show();
- */
- Judge J = new Judge();
- //wybór graczy
- J.play(M.show(),P.show());
- }
- }
- public interface Player {
- int show();
- }
- public class Donkey implements Player{
- @Override
- public int show() {
- System.out.println("Donkey choose Rock");
- return 0;
- }
- }
- public class Monkey implements Player {
- @Override
- public int show() {
- int random = (int)(Math.random() * 3);
- if (random == 0){
- System.out.println("Monkey choose Rock");
- }
- else if (random == 1){
- System.out.println("Monkey choose Papper");
- }
- else if (random == 2){
- System.out.println("Monkey choose Scissors");
- }
- return random;
- }
- }
- public class Parrot implements Player {
- @Override
- public int show() {
- int random = (int)(Math.random() * 2);
- if (random == 0){
- System.out.println("Parrot choose Rock");
- }
- else if (random == 1){
- System.out.println("Parrot choose Papper");
- }
- return random;
- }
- }
- public class Judge {
- void play(int g1, int g2){
- // 0 - Rock
- // 1 - Papper
- // 2 - Scissors
- if(g1==0 && g2==1) {
- System.out.println("");
- System.out.println("Papper beats Rock");
- }
- else if(g1==0 && g2==2) {
- System.out.println("");
- System.out.println("Rock beats Scissors");
- }
- else if(g1==1 && g2==0) {
- System.out.println("");
- System.out.println("Papper beats Rock");
- }
- else if(g1==1 && g2==2) {
- System.out.println("");
- System.out.println("Scissors beats Papper");
- }
- else if(g1==2 && g2==0) {
- System.out.println("");
- System.out.println("Rock beats Scissors");
- }
- else if(g1==2 && g2==1) {
- System.out.println("");
- System.out.println("Scissors beats Papper");
- }
- else if(g1==g2){
- System.out.println("");
- System.out.println("DRAW");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement