Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A player is either <code>active</code> or <code>inactive</code>. Once he is active, he has to make a decision to <code>roll()</code> or to <code>hold()</code>. Each player has a strategy for this decision making process - a human player has the strategy <em>in mind</em>, the computer player needs a strategy implemented in code. This strategy could offer on method: <code>decide(int myScore, int oppenentsScorce)</code> and produce a result: <em>to roll or not to roll</em>.</p> <p>The <code>Player</code> class could look like this:</p> <pre><code> public class Player { enum Decision { ROLL, HOLD } private Controller gameController; public Player(Controller gameController) { this.gameController = gameController; } // this is the real players strategy (-&gt; Strategy pattern) abstract Decision decide(int myScore, int opponentsScore); // this method is called by the controller public void doTurn() { Decision decision = decide(gameController.getScore(this), gameControlle.getOpponentsScore(this); if (decision == ROLL) gameController.roll(this); if (decision == HOLD) gameController.hold(this); } } </code></pre> <p>The <code>HumanPlayer</code> subclass could open a dialog for the human player, which shows the actual results and offers two buttons: roll / hold. The <code>ComputerPlayers</code> implementation would use an algorithm for the decision.</p> <p>The Controller controls the game, rolls the dice and keeps the score. And the controller checks after each turn, if there's a winner.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload