import java.util.Scanner;
public class Game {
    private final Player player1;
    private final Player player2;
    private int pointsP1;
    private int pointsP2;
    private final int pointsToWin;
    private static final Scanner in;
    static { // Static Initialization Block
        in = new Scanner(System.in);
        // Yes! We can have to Scanners from System.in and it works! :-)
    }
    public Game() {
        System.out.println("Human player's name?");
        player1 = new Player(Player.HUMAN, in.nextLine());
        player2 = new Player(Player.ROBOT, "Robot");
        System.out.println("How many points to get the game?");
        pointsToWin = in.nextInt();
        // No need to set pointsP1 and P2 to 0
    }
    public void playOneHand() {
        Hand hand1 = player1.formHand();
        Hand hand2 = player2.formHand();
        System.out.println("He plays " + hand2);
        switch (hand1.compareTo(hand2)) {
            case Hand.WINS:
                System.out.println("You win! :-)");
                pointsP1++;
                break;
            case Hand.LOOSES:
                System.out.println("You loose! :-(");
                pointsP2++;
                break;
            case Hand.TIES:
                System.out.println("It's a tie! :-/");
                break;
        }
        System.out.println(player1 + " " + pointsP1 + " points. ");
        System.out.println(player2 + " " + pointsP2 + " points. ");
        System.out.println();
    }
    public boolean hasFinishedGame() {
        if (pointsP1 == pointsToWin || pointsP2 == pointsToWin) {
            if (pointsP1 == pointsToWin) {
                System.out.println(player1 + " WINS THE GAME!!!");
            } else {
                System.out.println(player2 + " WINS THE GAME!!!");
            }
            return true;
        } else {
            return false;            
        }
    }
}
