Package game

Source Code of game.Player

package game;

import hand.BlackJackHand;
import hand.Hand;
import hand.HandBehaviour;
/**
* A player that has a hand and a hand behaviour. The hand behaviour determines
* the amount of cards in the hand.
* @author TJ Renninger
*
*/
public class Player
{
  private Hand hand;
  private boolean firstDraw;
  protected HandBehaviour handBehaviour;
 
  public Player()
  {
    this(new BlackJackHand());
  }
 
  /**
   * Create a player and set their hand type
   * @param handBehaviour for the game
   */
  public Player(HandBehaviour handBehaviour)
  {
    this.handBehaviour = handBehaviour;
    hand = this.handBehaviour.setHand();
    firstDraw = true;
  }
 
  /**
   * If first draw, draw whole hand otherwise draw a single card
   */
  public void draw()
  {
    if (firstDraw)
    {
      hand.drawHand();
      firstDraw = false;
    }
    else hand.drawCard();
  }

  /**
   *
   * @return the players hand object
   */
  public Hand getHand()
  {
    return hand;
  }
 
  /**
   *
   * @return the players hand behaviour.
   */
  public HandBehaviour getHandBehaviour()
  {
    return handBehaviour;
  }
}
TOP

Related Classes of game.Player

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.