Package games.war

Source Code of games.war.WarPlayer

package games.war;

import java.util.ArrayList;

import game.Card;
import game.Player;
import games.war.behaviors.CheatingBehavior;
import hand.HandBehaviour;

/**
* The player in the war game, adds a cheating aspect to the Player class written by TJ
* @author chris
*
*/
public class WarPlayer extends Player
{
    CheatingBehavior howToCheat;

    /**
     *
     * @param handBehaviour The wanted HandBehaviour, should be WarHand, but any work.
     * @param cheating The wanted CheatingBehavior; Cheating, NotCheating, RandomCheating
     */
    public WarPlayer(HandBehaviour handBehaviour, CheatingBehavior cheating)
    {
        super(handBehaviour);
        howToCheat = cheating;
        getHand().drawHand();
        //System.out.println(hand);
    }

    /**
     * Tells the player to pick their next card to play
     * @return The next to to be played
     */
    public Card takeTurn()
    {
        Card nextCard = cheat();
        return nextCard;
    }

    /**
     * Uses the player's CheatingBehavior to choose the next card.
     * @return
     */
    protected Card cheat()
    {
        return howToCheat.getNextCard(getHand());
    }

    /**
     * Tells the player to pick the next 3 cards, if able, for a war.
     * @return
     */
    public Card[] war()
    {
        Card tmp[] = new Card[3];
        int warCards = 3;
        if (getHand().getSize() <= 3)
        {
            warCards = getHand().getSize()-1;
        }

        for (int i = 0; i < warCards; i++)
        {
            tmp[i] = getHand().getCard(0);
            getHand().removeCard(0);
        }
        return tmp;
    }

    /**
     * Adds the given ArrayList of cards to the player's hand
     * @param newCards An ArrayList of cards that should be added to the player's hand
     */
    public void addCardsToHand(ArrayList<Card> newCards)
    {
      getHand().addCards(newCards);
    }

    /**
     * @return The number of cards in the player's hand
     */
    public int getHandSize()
    {
        return getHand().getSize();
    }

    /**
     * Removes every card from the player's hand
     */
    public void clearHand()
    {
      getHand().clear();
    }
}
TOP

Related Classes of games.war.WarPlayer

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.