package games.gofish.state;
import game.Card;
import game.Player;
import games.gofish.GoFish;
import hand.Hand;
/**
* Handles events for when it is the computers turn for gofish
* @author TJ Renninger
*
*/
public class ComputerTurnSate implements TurnState
{
/**
* The computer will ask for a card
*/
@Override
public void askForCard(GoFish gofish, Player player, Player computer, int value)
{
boolean exchange = false;
for (int i = 0; i < player.getHand().getSize(); i++)
{
Card card = player.getHand().getCard(i);
if (card.getValue() == value)
{
computer.getHand().addCard(card);
player.getHand().removeCard(i);
exchange = true;
i--;
}
}
if (!exchange)
goFish(player, computer);
checkForMatch(player, computer);
gofish.setState(new PlayerTurnState());
}
/**
* The computer will fish for a card
*/
@Override
public void goFish(Player player, Player computer)
{
computer.draw();
}
/**
* Computer checks for match
*/
@Override
public boolean checkForMatch(Player player, Player computer)
{
Hand h = computer.getHand();
int matches;
for (int i = 0; i < h.getSize(); i++)
{
matches = 1;
for (int j = i + 1; j < h.getSize(); j++)
{
if (h.getCard(i).getValue() == h.getCard(j).getValue())
matches++;
}
if (matches == 4)
return true;
}
return false;
}
}