var EHDI = EHDI || Object.create(null);

EHDI.GAME = EHDI.GAME || Object.create(null);

EHDI.GAME.components = EHDI.GAME.components || Object.create(null);

EHDI.GAME.components.CardPlayer = function(cardBoard) {
	this.cardBoard = cardBoard;
	this.setForNewGame();
}

EHDI.GAME.components.CardPlayer.prototype.nextMove = function(card, callback) {
	this.dropCard(card);
	this.addCardToBoardAnim(card, callback);
}

EHDI.GAME.components.CardPlayer.prototype.setCardsInHand = function(cards) {
	this.prevHandCards = this.handCards.slice(0);
	this.handCards = cards;
}

EHDI.GAME.components.CardPlayer.prototype.addCardToHand = function(card) {
	this.handCards.push(card);
}

EHDI.GAME.components.CardPlayer.prototype.addCardToBoard = function(card) {
	this.boardCards.push(card);
}

EHDI.GAME.components.CardPlayer.prototype.dropCard = function(card) {
	var index = this.handCards.indexOf(card);
	this.handCards.splice(index, 1);
	this.addCardToBoard(card);
}

EHDI.GAME.components.CardPlayer.prototype.removeBoardCards = function(except) {
	var except = except || this.draftedCards;
	this.boardCards.length = 0;
	for(var i = 0; i < except.length; i++) {
		except[i].setDrafted(true);
		this.boardCards.push(except[i]);
	}
}

EHDI.GAME.components.CardPlayer.prototype.addCardToBoardAnim = function(card) {
	/**/
}

EHDI.GAME.components.CardPlayer.prototype.setForNewGame = function() {
	this.points = 0;
	this.handCards = [];
	this.prevHandCards = [];
	this.boardCards = [];
	this.draftedCards = [];
	this.enemyBoardCards = [];
	this.effectCalculator = new EHDI.GAME.components.EffectCalculator(false, this);
	this.timeline = new TimelineLite({paused:true});
}

EHDI.GAME.components.CardPlayer.prototype.setForNextRound = function() {
	this.handCards.length = 0;
	this.boardCards.length = 0;
	for(var i = 0; i < this.draftedCards.length; i++) {
		this.boardCards.push(this.draftedCards[i]);
	}
}

EHDI.GAME.components.CardPlayer.prototype.calculateFinal = function(callback) {
	this.effectCalculator.calculateFinal(this.boardCards, this.enemyBoardCards, callback);
}

EHDI.GAME.components.CardPlayer.prototype.addScore = function(val) {
	this.points += val;
 	EHDI.GAME.soundManager.playSFX("score_up");
	this.scoreManager.addScore(val);
}

EHDI.GAME.components.CardPlayer.prototype.setScoreManager = function(sm) {
	this.scoreManager = sm;
}