Class Board
java.lang.Object
Board
- Direct Known Subclasses:
ElevensBoard
public class Board extends Object
This class represents a Board that can be used in a collection
of solitaire games similar to Elevens. The variants differ in
card removal and the board size.
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Card
cardAt(int k)
Accesses a card on the board.List<Integer>
cardIndexes()
Gets the indexes of the actual (non-null) cards on the board.void
deal(int k)
Deal a card to the kth position in this board.int
deckSize()
Accesses the deck's size.boolean
gameIsWon()
Determine whether or not the game has been won, i.e.boolean
isEmpty()
Determines if the board is empty (has no cards).void
newGame()
Start a new game by shuffling the deck and dealing some cards to this board.void
replaceSelectedCards(List<Integer> selectedCards)
Replaces selected cards on the board by dealing new cards.int
size()
Accesses the size of the board.String
toString()
Generates and returns a string representation of this board.
-
Constructor Details
-
Board
Creates a newBoard
instance.- Parameters:
size
- the number of cards in the boardranks
- the names of the card ranks needed to create the decksuits
- the names of the card suits needed to create the deckpointValues
- the integer values of the cards needed to create the deck
-
-
Method Details
-
newGame
public void newGame()Start a new game by shuffling the deck and dealing some cards to this board. -
size
public int size()Accesses the size of the board. Note that this is not the number of cards it contains, which will be smaller near the end of a winning game.- Returns:
- the size of the board
-
isEmpty
public boolean isEmpty()Determines if the board is empty (has no cards).- Returns:
- true if this board is empty; false otherwise.
-
deal
public void deal(int k)Deal a card to the kth position in this board. If the deck is empty, the kth card is set to null.- Parameters:
k
- the index of the card to be dealt.
-
deckSize
public int deckSize()Accesses the deck's size.- Returns:
- the number of undealt cards left in the deck.
-
cardAt
Accesses a card on the board.- Parameters:
k
- is the board position of the card to return.- Returns:
- the card at position k on the board.
-
replaceSelectedCards
Replaces selected cards on the board by dealing new cards.- Parameters:
selectedCards
- is a list of the indices of the cards to be replaced.
-
cardIndexes
Gets the indexes of the actual (non-null) cards on the board.- Returns:
- a List that contains the locations (indexes) of the non-null entries on the board.
-
toString
Generates and returns a string representation of this board. -
gameIsWon
public boolean gameIsWon()Determine whether or not the game has been won, i.e. neither the board nor the deck has any more cards.- Returns:
- true when the current game has been won; false otherwise.
-