Class 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

    Constructors 
    Constructor Description
    Board​(int size, String[] ranks, String[] suits, int[] pointValues)
    Creates a new Board instance.
  • 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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Board

      public Board​(int size, String[] ranks, String[] suits, int[] pointValues)
      Creates a new Board instance.
      Parameters:
      size - the number of cards in the board
      ranks - the names of the card ranks needed to create the deck
      suits - the names of the card suits needed to create the deck
      pointValues - 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

      public Card cardAt​(int k)
      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

      public void replaceSelectedCards​(List<Integer> selectedCards)
      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

      public List<Integer> 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

      public String toString()
      Generates and returns a string representation of this board.
      Overrides:
      toString in class Object
      Returns:
      the string version 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.