proj2
Class Game

java.lang.Object
  extended by proj2.Game

public class Game
extends java.lang.Object

This class provides all methods used by the GUI for Monte Carlo Solitaire

Class Invariant:
To be supplied by the student

Author:
Dennis Frey

Constructor Summary
Game(int rows, int cols)
          Construct a new Monte Carlo Solitaire object
 
Method Summary
 int cardsLeft()
          Calculates the number of cards still in the deck
 void consolidate()
          Moves cards in the tableau towards the top (left and up) to replace the cards that were removed.
 proj2.Rank getRank(proj2.Coordinates coord)
          Returns a Rank object representing the rank of the card at the specified Coordinates in the tableau
 proj2.Suit getSuit(proj2.Coordinates coord)
          Returns a Suit object representing the suit of the card at the specified Coordinates in the tableau
 java.lang.String help()
          Creates a String containing Help for the player
 proj2.Coordinates[] hint()
          Finds two matching cards according to the rules of the game
 void newGame(long gameNr)
          Starts a new game of solitaire.
 boolean playerWins()
          Determines if the player has won the game by removing all the cards and thereby achieving a score of 52
 boolean removeCards(proj2.Coordinates card1, proj2.Coordinates card2)
          Determines if the cards at the specified tableau locations are a match according to the rules of Monte Carlo Solitaire and if so, removes them from the tableau (formerly cardsMatch())
 void replay()
          Restarts the current game
 int score()
          Accessor for the player's current score
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Game

public Game(int rows,
            int cols)
Construct a new Monte Carlo Solitaire object

Parameters:
rows - the number of rows in the tableau
cols - the number of columns in the tableau
Method Detail

score

public int score()
Accessor for the player's current score

Returns:
Player's current game score (0 to 52)

playerWins

public boolean playerWins()
Determines if the player has won the game by removing all the cards and thereby achieving a score of 52

Returns:
true if the player has won, false otherwise

newGame

public void newGame(long gameNr)
Starts a new game of solitaire. The first game played is game #12345 and should result in the same tableau as displayed in the screen shot in the project description.

Parameters:
gameNr - is the seed for the Random number generator used to shuffle the cards.

removeCards

public boolean removeCards(proj2.Coordinates card1,
                           proj2.Coordinates card2)
Determines if the cards at the specified tableau locations are a match according to the rules of Monte Carlo Solitaire and if so, removes them from the tableau (formerly cardsMatch())

Parameters:
card1 - - the coordinates of one card in the tableau
card2 - - the coordinates of the 2nd card in the tableau
Returns:
true if the cards match and were removed; false otherwise
See Also:
Coordinates

getSuit

public proj2.Suit getSuit(proj2.Coordinates coord)
Returns a Suit object representing the suit of the card at the specified Coordinates in the tableau

Parameters:
coord - - the coordinates of the card in the tableau
Returns:
the Suit of the card or null if no card exists in the tableau at the specified Coordinates
See Also:
Coordinates

getRank

public proj2.Rank getRank(proj2.Coordinates coord)
Returns a Rank object representing the rank of the card at the specified Coordinates in the tableau

Parameters:
coord - - the Coordinates of the card in the tableau
Returns:
the Rank of the card or null if no card exists in the tableau at the specified Coordinates
See Also:
Coordinates

help

public java.lang.String help()
Creates a String containing Help for the player

Returns:
the Help string to be displayed

replay

public void replay()
Restarts the current game


hint

public proj2.Coordinates[] hint()
Finds two matching cards according to the rules of the game

Returns:
an array[2] of Coordinates for the matching cards if found

null if no matching pair of cards exist

See Also:
Coordinates

consolidate

public void consolidate()
Moves cards in the tableau towards the top (left and up) to replace the cards that were removed. Then deals cards from the deck to refill the empty spaces at the bottom of the tableau


cardsLeft

public int cardsLeft()
Calculates the number of cards still in the deck

Returns:
the number of cards in the deck that may still be dealt to fill the tableau