Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. public abstract class Player {
  2.     private String name;
  3.     private int points = 0;
  4.  
  5.     public Player(String name) {
  6.         this.name = name;
  7.     }
  8.    
  9.     public abstract int getMove();
  10.  
  11.     public int getPoints() {
  12.         return points;
  13.     }
  14.  
  15.     public void addPoint() {
  16.         points++;
  17.     }
  18.  
  19.     public String getName() {
  20.         return name;
  21.     }
  22. }
  23.  
  24. public class Human extends Player {
  25.  
  26.     public Human(String name) {
  27.         super(name);
  28.     }
  29.  
  30.     public int getMove() {
  31.         return IO.getPlayerMove();
  32.     }
  33. }
  34.  
  35. public class Computer extends Player {
  36.    
  37.     private static final Random random = new Random();
  38.  
  39.     public Computer() {
  40.         super("Komputer");
  41.     }
  42.  
  43.     public int getMove() {
  44.         return random.nextInt(3) + 1;
  45.     }
  46. }
  47.  
  48. public class GameRule {
  49.  
  50.         PAPIER | KAMIEŃ | NOŻYCE  <- ruch player 1
  51. PAPIER     0       -1        1
  52. KAMIEŃ     1        0        -1
  53. NOŻYCE     -1       1         0
  54.  
  55.     private int[][] rules = {
  56.     { 0, -1, 1 },
  57.     { 1, 0, -1 },
  58.     { -1, 1, 0}
  59. };
  60.    
  61.     public int whoWin(int player1Move, int player2Move) {
  62.         return rules[player1Move][player2Move];
  63.     }
  64.  
  65. }
  66.  
  67. public class GameController {
  68.  
  69.     private int maxPoints;
  70.     private GameRule rule;
  71.     private Player player1;
  72.     private Player player2;
  73.  
  74.     // konstruktor
  75.    
  76.     public void startGame() {
  77.         while(player1.getPoints() < maxPoints || player2.getPoints() < maxPoints) {
  78.    
  79.         }
  80.  
  81.     }  
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement