Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package rollem;
- /**
- *
- * @author wayne
- */
- public class Player
- {
- private int turnScore = 0;
- private int gameScore = 0;
- private int d1;
- private int d2;
- void Player()
- {
- }
- int rollDie(DieLabel die1, DieLabel die2)
- {
- d1 = die1.rollDie();
- d2 = die2.rollDie();
- if (isTurnScoreLost())
- {
- if (isGameScoreLost())
- return 0;
- return 0;
- }
- turnScore += d1 + d2;
- return d1 + d2;
- }
- boolean isTurnScoreLost()
- {
- if (d1 == 1 || d2 == 1)
- {
- turnScore = 0;
- return true;
- }
- else return false;
- }
- boolean isGameScoreLost()
- {
- if (d1 == 1 && d2 == 1)
- {
- reset();
- return true;
- }
- else return false;
- }
- boolean hasWon()
- {
- if (gameScore > 100 || turnScore > 100)
- return true;
- else return false;
- }
- boolean addTurnScoreToGameScore()
- {
- if (isTurnScoreLost())
- return false;
- if (isGameScoreLost())
- return false;
- gameScore += turnScore;
- turnScore = 0;
- return true;
- }
- int getTurnScore()
- {
- return turnScore;
- }
- int getGameScore()
- {
- return gameScore;
- }
- void reset()
- {
- turnScore = 0;
- gameScore = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement