/**
* Player stores all information about the state of a player at any given point.
*/
package voodoo.collection.gameplay.player;
import java.util.Vector;
import voodoo.collection.card.Card;
import voodoo.collection.card.creature.monkey.FlamingMonkey;
import voodoo.collection.gameplay.Modifier;
import voodoo.collection.resource.Resource;
import voodoo.collection.utility.Event;
import voodoo.collection.utility.Notifier;
/**
* Player represents one player of the game. Everything that is based on a single Player
* goes here, including the Player's deck, hand and played Cards, and any rules specific to the
* Player.
*
*/
public class Player extends Notifier {
// The name of the Player.
protected String _name;
// The Cards in the Player's hand.
protected Vector<Card> _hand = new Vector<Card>();
// The Cards in the Player's deck.
protected Vector<Card> _deck = new Vector<Card>();
// The Cards the Player has played.
protected Vector<Card> _played = new Vector<Card>();
// The hidden Cards for this Player, including rules Cards.
protected Vector<Card> _hidden = new Vector<Card>();
// The resources this player has. Note that unlike Magic, these may not be cards.
// NOTE: If the resources are cards, we could ignore _resources
protected Modifier[] _resources = new Modifier[Resource.NUM_RESOURCES];
/**
* Default constructor.
*/
public Player() {}
/**
* Constructor.
* @param name The name of the Player.
*/
public Player( String name ) {
_name = name;
}
/**
* Perform one of the Player's turns, including playing any cards
* and handling any mechanics.
*/
public void turn() {
notifyListeners( Event.TURN_BEGIN_EVENT );
// pick a card to play!
// TODO: This is not the way it should work.
Card toPlay = getNextMove();
System.out.println( "Player " + _name + " plays " + toPlay.getName() );
_played.add( toPlay );
notifyListeners( Event.TURN_PLAY_EVENT );
notifyListeners( Event.TURN_END_EVENT );
}
/**
* Get the Player's name.
* @return The Player's name.
*/
public String getName() {
return _name;
}
/**
* Get the list of Cards the Player has played.
* @return The list of played cards.
*/
public Vector<Card> getPlayed() {
return _played;
}
/**
* Get the Player's hidden Cards.
* @return The list of hidden cards.
*/
public Vector<Card> getHidden() {
return _hidden;
}
/**
* Gets the number of cards in this Player's hand (not the deck)
* @return The number of cards in the Player's hand.
*/
public int getNumHandCards() {
return _hand.size();
}
/**
* Get the next Card the Player will play.
* TODO: This is too dependent on particular mechanics, and should be changed. It was
* intended just to make the game work in a simple form.
* @return The next Card the Player will play.
*/
public Card getNextMove() {
// TODO: Un-hardcode this
return new FlamingMonkey();
}
/**
* Check whether the Player has life left.
* @return <code>true</code> if the Player has life left, <code>false</code> otherwise.
*/
public boolean isAlive() {
return( getLife().getValue() > 0 );
}
/**
* Change the amount of one of the Player's resources.
* @param resource The resource type to change. See @link voodoo.collection.resource.Resource .
* @param change The amount to change by.
*/
public void changeResource( int resource, int change ) {
_resources[resource].changeValue( change );
}
/**
* Change the amount of all the Player's resources.
* @param changes An array specifying the number to change each resource by. Must be of length
* NUM_RESOURCES in @link voodoo.collection.resource.Resources .
*/
public void changeResources( int[] changes ) {
if( _resources.length != changes.length ) {
throw new IllegalArgumentException( "In changeResources, incorrect number of resources sent in." );
}
for( int i = 0; i < Resource.NUM_RESOURCES; i++ ) {
_resources[i].changeValue( changes[i] );
}
}
/**
* Check if the player has a particular amount (or more) of one resource.
* @param resource The resource type to check. See @link voodoo.collection.resource.Resource .
* @param num The amount to check.
* @return <code>true</code> if the Player has <code>num</code> or more of the resource.
*/
public boolean hasResource( int resource, int num ) {
return( _resources[resource].getValue() >= num );
}
/**
* Check if the player has a particular amount (or more) of a bunch of resources.
* @param resources The amount of each resource to check. Must be of length
* NUM_RESOURCES in @link voodoo.collection.resource.Resources .
* @return <code>true</code> if the Player has ALL the resources specified, or more.
*/
public boolean hasResources( int[] resources ) {
for( int i = 0; i < Resource.NUM_RESOURCES; i++ ) {
if( _resources[i].getValue() < resources[i] ) {
return false;
}
}
return true;
}
/**
* Get Player's life left.
* @return Player's life left.
*/
public Modifier getLife() {
return getResource(Resource.LIFE);
}
/**
* Change the amount of life the Player has.
* @param change The amount to change Life by.
*/
public void changeLife( int change ) {
getLife().changeValue( change );
}
/**
* Set the amount of life the Player has.
* @param life The value to set Life to.
*/
public void setLife( int life ) {
getLife().setValue( life );
}
/**
* Get the given resource.
* @param Resource to get.
* @return The resource.
*/
public Modifier getResource(int resource) {
if ( _resources[resource] == null ) {
_resources[resource] = new Modifier();
}
return _resources[resource];
}
}