Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Player {
- private String name;
- private int points = 0;
- public Player(String name) {
- this.name = name;
- }
- public abstract int getMove();
- public int getPoints() {
- return points;
- }
- public void addPoint() {
- points++;
- }
- public String getName() {
- return name;
- }
- }
- public class Human extends Player {
- public Human(String name) {
- super(name);
- }
- public int getMove() {
- return IO.getPlayerMove();
- }
- }
- public class Computer extends Player {
- private static final Random random = new Random();
- public Computer() {
- super("Komputer");
- }
- public int getMove() {
- return random.nextInt(3) + 1;
- }
- }
- public class GameRule {
- PAPIER | KAMIEŃ | NOŻYCE <- ruch player 1
- PAPIER 0 -1 1
- KAMIEŃ 1 0 -1
- NOŻYCE -1 1 0
- private int[][] rules = {
- { 0, -1, 1 },
- { 1, 0, -1 },
- { -1, 1, 0}
- };
- public int whoWin(int player1Move, int player2Move) {
- return rules[player1Move][player2Move];
- }
- }
- public class GameController {
- private int maxPoints;
- private GameRule rule;
- private Player player1;
- private Player player2;
- // konstruktor
- public void startGame() {
- while(player1.getPoints() < maxPoints || player2.getPoints() < maxPoints) {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement