package games.memory;
import game.Card;
import game.Deck;
import game.Game;
import games.memory.difficulty.Difficulty;
import games.memory.difficulty.EasyDifficulty;
import games.memory.difficulty.HardDifficulty;
import games.memory.state.MemoryState;
import java.util.Vector;
/**
* Functionality associated with Memory
* @author Ian Keefer
*/
public class Memory extends Game
{
private int lives;
private Card selectionOne;
private Card selectionTwo;
private Difficulty difficulty;
private MemoryState state;
protected Card gameBoard[][];
private static Memory memory;
/**
* sets gameBoard to a 4 by 13 2d array and sets lives to 10 by default. Also calls a method to fill up the gameBoard
* with a full deck of cards
*/
private Memory()
{
gameBoard = new Card[4][13];
difficulty = new EasyDifficulty();
lives = difficulty.getLives();
createBoard();
}
/**
* sets memory instance variable to the memory class
* @return memory
*/
public static Memory getInstance()
{
if(memory == null)
{
memory = new Memory();
}
return memory;
}
/**
* resets memory so the tests can run with new data
*/
public static void reset()
{
memory = null;
}
/**
* Creates the gameBoard[][] with an entire deck
*/
public void createBoard()
{
deck.shuffle();
int temp = 0;
for(int i = 0; i < gameBoard.length; i++)
{
for(int j = 0; j < gameBoard[i].length; j++)
{
gameBoard[i][j] = deck.getCard(temp);
temp++;
}
}
}
/**
* Compares cards based on suit and values and returns true if and only if they have the same
* color and same value
* @return
*/
public boolean compareCards()
{
if(selectionOne.getSuit() == 'd')
{
if(selectionTwo.getSuit() != 'h')
{
return false;
}
} else if (selectionOne.getSuit() == 's')
{
if(selectionTwo.getSuit() != 'c')
{
return false;
}
} else if (selectionOne.getSuit() == 'h')
{
if(selectionTwo.getSuit() != 'd')
{
return false;
}
} else if (selectionOne.getSuit() == 'c')
{
if(selectionTwo.getSuit() != 's')
{
return false;
}
}
if(selectionOne.getValue() == selectionTwo.getValue())
{
return true;
}
else
{
return false;
}
}
/**
* @return lives
*/
public int getLives()
{
return lives;
}
/**
* @return selectionOne
*/
public Card getSelectionOne()
{
return selectionOne;
}
/**
* @return selectionTwo
*/
public Card getSelectionTwo()
{
return selectionTwo;
}
/**
* @return difficulty
*/
public Difficulty getDifficulty()
{
return difficulty;
}
/**
* @return state
*/
public MemoryState getState()
{
return state;
}
/**
* sets the selections to parameters card and card2
* @param card
* @param card2
*/
public void setSelections(Card card, Card card2)
{
selectionOne = card;
selectionTwo = card2;
}
/**
* sets lives to parameter life
* @param life
*/
public void setLives(int life)
{
lives = life;
}
/**
* sets difficulty to parameter difficulty
* @param difficulty
*/
public void setDifficulty(Difficulty difficulty)
{
this.difficulty = difficulty;
lives = difficulty.getLives();
}
/**
* sets state to parameter state
* @param state
*/
public void setState(MemoryState state)
{
this.state = state;
}
}