oop2.setGame
Class SetGame

java.lang.Object
  extended byoop2.setGame.SetGame

public class SetGame
extends Object

Implements the primary logic for the Set Game


Constructor Summary
SetGame()
          Construct a new SetGame with no cards on the table
 
Method Summary
 void add(Card c)
          Adds a card to the table.
 void clearCardsOnTable()
          Removes all cards from the table.
 List findSet()
          Checks to see if there is a set within the cards currently on the table.
static List generateDeck()
          Generates a randomly sorted deck of Set cards and returns it.
 int getCardCount()
          Get the number of cards on the table.
 List getCardsOnTable()
          Returns a list of the cards on the table.
static boolean isSet(Card c1, Card c2, Card c3)
          Checks to see if three cards form a set
 void removeCards(List cardsToRemove)
          Removes the specificied cards from the table.
 void setCardsOnTable(List cardList)
          Sets the cards on the table to be those in the cardList.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SetGame

public SetGame()
Construct a new SetGame with no cards on the table

Method Detail

getCardsOnTable

public List getCardsOnTable()
Returns a list of the cards on the table. null entries in the list indicate blank spots where cards have been removed

Returns:
A List containing the cards on the table.

setCardsOnTable

public void setCardsOnTable(List cardList)
Sets the cards on the table to be those in the cardList. The List should not contain any null values.

Parameters:
cardList - The new list of cards on the table.

clearCardsOnTable

public void clearCardsOnTable()
Removes all cards from the table. After calling this method the list returned by getCardsOnTable should be empty.


add

public void add(Card c)
Adds a card to the table. The card should fill the first blank position that exists in the card list. If there are no blank positions the card should be added to the end of the list.


getCardCount

public int getCardCount()
Get the number of cards on the table. Don't count blank spots corresponding to cards that have been picked up. In particular, this method does not necessarily return the same value as getCardsOnTable.size()

Returns:
the number of cards on the table.

removeCards

public void removeCards(List cardsToRemove)
Removes the specificied cards from the table. This operation should not effect the position of the cards remaining on the table. Instead, nulls should be used to indicate blank spots where cards have been removed.

Parameters:
cardsToRemove - - Cards to be removed from the label.
Throws:
IllegalArgumentException - - if a card to be removed is not on the table.

findSet

public List findSet()
Checks to see if there is a set within the cards currently on the table. Returns any set of cards that match the definition for a set of matching cards. Does not update the cards on the table.

Returns:
Set of cards found. If the cards do not contain any sets, return null. If the cards contain multiple sets, any set may be returned.

generateDeck

public static List generateDeck()
Generates a randomly sorted deck of Set cards and returns it. The deck should contain all 81 legal set cards (3 numbers * 3 shapes * 3 colors * 3 shadings = 81 combinations). The Randomand/or Collectionsclasses will be useful to you in randomly sorting/shuffling a deck of cards.

Returns:
a randomized list containing the 81 legal Cards in the game Set.

isSet

public static boolean isSet(Card c1,
                            Card c2,
                            Card c3)
Checks to see if three cards form a set

Parameters:
c1 - - First card
c2 - - Second card
c3 - - Third card
Returns:
true if the three cards form a set