Class SameModel

java.lang.Object
  extended by SameModel

public class SameModel
extends java.lang.Object

The Model for the game. Holds all data regarding the game and any associated accessor and mutator methods. Note: The game uses same[][] to store data regarding the boxes, so column and row index positions will will be needed to access the boxes at any given position. I have, however used a single index position to access the boxes, as I originally had same[], but only later chnaged to a same[][]. I have kept the original methods, using 'single index positions', but I have had to convert them to column and row index postions through an additional method, to be able to access the same[][]

Version:
1.2
Author:
Afzal Bhamjee

Constructor Summary
SameModel()
          A simple constructor that takes no parameters.
 
Method Summary
 java.lang.Boolean checkMatches(int num)
          Searches the matchedBoxes array list for the value the method was called with
 void clearMatches()
          Clears the matchedBoxes array list
 void findNearbyMatches(java.lang.Integer boxNum)
          For any given box, the method will fill an array list, matchedBoxes, with all boxes vertically and horizontally adjacent that are of the same colour.
 java.lang.Integer getBox(int num)
          Returns the Integer stored in the same array of arrays at the index position calculated from the parameter
 int getBoxes()
          Returns the number boxes in the game
 java.awt.Color getColour(int colourNum)
          Returns the Color stored at index position of the paramter
 int getDimention()
          Returns the size of the game
 int getHoverScore()
          Returns the score for the current set of boxes the mouse is over
 int getMatchedBox(int num)
          Returns the Game Box index stored at the matchedBoxes index position specified in the parameter
 int getMatchedBoxesSize()
          Return the size of the matchedBoxes array list
 int getNumColours()
          Returns the number of colours in the game
 int getScore()
          Returns the current value of score
static int getTotalColours()
          Returns the total number of colours possible in the game
 void giveNextHint()
          Will search for a set of nearby matches, and if found, then it will stop, so the matchedBoxes array list will contain the indexes for these matches These matches will be used for the hint
 java.lang.Boolean isGameOver()
          Checks is there are any more group of boxes left and returns boolean
 void newGame()
          Resets the game, for when a new game needs to be started Is also used when the first game is created, to set some values
 void resetHoverScore()
          Resets the value of hoverScore back to 0
 void setDimention(int dimention)
          Sets the parameter value as the dimention for the next game
 void setHoverScore()
          Sets the value for hoverScore, which is displayed when the mouse hovers over a set of boxes
 void setNumColours(int numColours)
          Sets the parameter value as the number of colours for the next game
 void shuffleBoxesDown()
          This will remove a box from 'sets of boxes', a single box at a time, when called, and shuffling boxes above it down to fill the 'blank' box.
 void shuffleBoxesToRight()
          Shuffles columns to the right, if any 'blank' columns are found, and the 'blank' column is added to the left most of the game
 void test()
          Used in the JUnit tests to help setup the game in the correct state
 void updateScore()
          Updates the score by adding to it the current value of hoverScore
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SameModel

public SameModel()
A simple constructor that takes no parameters.

Method Detail

checkMatches

public java.lang.Boolean checkMatches(int num)
Searches the matchedBoxes array list for the value the method was called with

Parameters:
int - number to search for in the matchedBoxes array list
Returns:
Boolean true or false, if the int is found

clearMatches

public void clearMatches()
Clears the matchedBoxes array list


findNearbyMatches

public void findNearbyMatches(java.lang.Integer boxNum)
For any given box, the method will fill an array list, matchedBoxes, with all boxes vertically and horizontally adjacent that are of the same colour. matchedBoxes will only contain indexes' for unique boxes, the box will not be added a second time, if it is already in the array list

Parameters:
'single - number index position' of type int

getBox

public java.lang.Integer getBox(int num)
Returns the Integer stored in the same array of arrays at the index position calculated from the parameter

Parameters:
The - int to be calculated to the index position of same
Returns:
Integer from same

getBoxes

public int getBoxes()
Returns the number boxes in the game

Returns:
The number of boxes

getColour

public java.awt.Color getColour(int colourNum)
Returns the Color stored at index position of the paramter

Parameters:
Index - position of the colours array
Returns:
Color from the colours array

getDimention

public int getDimention()
Returns the size of the game

Returns:
The size (dimention) of the game

getHoverScore

public int getHoverScore()
Returns the score for the current set of boxes the mouse is over

Returns:
The current hoverScore

getMatchedBox

public int getMatchedBox(int num)
Returns the Game Box index stored at the matchedBoxes index position specified in the parameter

Parameters:
int - nposition of matchedBoxes
Returns:
matchedBoxes int value

getMatchedBoxesSize

public int getMatchedBoxesSize()
Return the size of the matchedBoxes array list

Returns:
Size of matchedBoxes array list

getNumColours

public int getNumColours()
Returns the number of colours in the game

Returns:
int value for number of colours

getScore

public int getScore()
Returns the current value of score

Returns:
score for the current game

getTotalColours

public static int getTotalColours()
Returns the total number of colours possible in the game

Returns:
int of total possible number of colours

giveNextHint

public void giveNextHint()
Will search for a set of nearby matches, and if found, then it will stop, so the matchedBoxes array list will contain the indexes for these matches These matches will be used for the hint


isGameOver

public java.lang.Boolean isGameOver()
Checks is there are any more group of boxes left and returns boolean

Returns:
Boolean true or false to the question, is the game over

newGame

public void newGame()
Resets the game, for when a new game needs to be started Is also used when the first game is created, to set some values


resetHoverScore

public void resetHoverScore()
Resets the value of hoverScore back to 0


setDimention

public void setDimention(int dimention)
Sets the parameter value as the dimention for the next game

Parameters:
New - int value for dimention

setHoverScore

public void setHoverScore()
Sets the value for hoverScore, which is displayed when the mouse hovers over a set of boxes


setNumColours

public void setNumColours(int numColours)
Sets the parameter value as the number of colours for the next game

Parameters:
New - int value for number of colours

shuffleBoxesDown

public void shuffleBoxesDown()
This will remove a box from 'sets of boxes', a single box at a time, when called, and shuffling boxes above it down to fill the 'blank' box. The 'blank' box will then be added to the top of each row.


shuffleBoxesToRight

public void shuffleBoxesToRight()
Shuffles columns to the right, if any 'blank' columns are found, and the 'blank' column is added to the left most of the game


test

public void test()
Used in the JUnit tests to help setup the game in the correct state


updateScore

public void updateScore()
Updates the score by adding to it the current value of hoverScore