Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java- FloodIt game The model The first step is to build the model of the game. This will be done via the class GameModel and

java- FloodIt game

The model

The first step is to build the model of the game. This will be done via the class GameModel and the helper class DotInfo. Our unique instance of the class GameModel will have to store the current state of the game. This includes

The colour and status (captured or not) of each dot on the board. The class DotInfo helps with this.

The size of the board.

The number of steps taken by the player so far

The number of dots captured so far

the currently selected colour

It also provides the necessary setters and getters, so the the controller and the view can check the status of any dot, and the controller can change the status of a dot or set the current colour to a new value. Finally, it provides a way to (re)initialize the game, reallocating the initial colours randomly.

A detailed description of the classes can be found here:

// ADD YOUR IMPORTS HERE

/** * The class GameModel holds the model, the state of the systems. * It stores the followiung information: * - the state of all the ``dots'' on the board (color, captured or not) * - the size of the board * - the number of steps since the last reset * - the current color of selection * * The model provides all of this informations to the other classes trough * appropriate Getters. * The controller can also update the model through Setters. * Finally, the model is also in charge of initializing the game public class GameModel { /** * predefined values to capture the color of a DotInfo */ public static final int COLOR_0 = 0; public static final int COLOR_1 = 1; public static final int COLOR_2 = 2; public static final int COLOR_3 = 3; public static final int COLOR_4 = 4; public static final int COLOR_5 = 5; public static final int NUMBER_OF_COLORS = 6; // ADD YOUR INSTANCE VARIABLES HERE /** * Constructor to initialize the model to a given size of board. * * @param size * the size of the board */ public GameModel(int size) { // ADD YOUR CODE HERE } /** * Resets the model to (re)start a game. The previous game (if there is one) * is cleared up . */ public void reset(){ // ADD YOUR CODE HERE } /** * Getter method for the size of the game * * @return the value of the attribute sizeOfGame */ public int getSize(){ // ADD YOUR CODE HERE } /** * returns the current color of a given dot in the game * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot * @return the status of the dot at location (i,j) */ public int getColor(int i, int j){ // ADD YOUR CODE HERE } /** * returns true is the dot is captured, false otherwise * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot * @return the status of the dot at location (i,j) */ public boolean isCaptured(int i, int j){ // ADD YOUR CODE HERE } /** * Sets the status of the dot at coordinate (i,j) to captured * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot */ public void capture(int i, int j){ // ADD YOUR CODE HERE } /** * Getter method for the current number of steps * * @return the current number of steps */ public int getNumberOfSteps(){ // ADD YOUR CODE HERE } /** * Setter method for currentSelectedColor * * @param val * the new value for currentSelectedColor */ public void setCurrentSelectedColor(int val) { // ADD YOUR CODE HERE } /** * Getter method for currentSelectedColor * * @return currentSelectedColor */ public int getCurrentSelectedColor() { // ADD YOUR CODE HERE } /** * Getter method for the model's dotInfo reference * at location (i,j) * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot * * @return model[i][j] */ public DotInfo get(int i, int j) { // ADD YOUR CODE HERE } /** * The metod step updates the number of steps. It must be called * once the model has been updated after the payer selected a new color. */ public void step(){ // ADD YOUR CODE HERE } /** * The metod isFinished returns true iff the game is finished, that * is, all the dats are captured. * * @return true if the game is finished, false otherwise */ public boolean isFinished(){ // ADD YOUR CODE HERE } /** * Builds a String representation of the model * * @return String representation of the model */ public String toString(){ // ADD YOUR CODE HERE } }

/** * The class DotInfo is a simple helper class to store the initial color and state * (captured or not) at the dot position (x,y) * */ public class DotInfo { // ADD YOUR INSTANCE VARIABLES HERE /** * Constructor * * @param x * the x coordinate * @param y * the y coordinate * @param color * the initial color */ public DotInfo(int x, int y, int color){ // ADD YOUR CODE HERE } /** * Getter method for the attribute x. * * @return the value of the attribute x */ public int getX(){ // ADD YOUR CODE HERE } /** * Getter method for the attribute y. * * @return the value of the attribute y */ public int getY(){ // ADD YOUR CODE HERE } /** * Setter for captured * @param captured * the new value for captured */ public void setCaptured(boolean captured) { // ADD YOUR CODE HERE } /** * Get for captured * * @return captured */ public boolean isCaptured(){ // ADD YOUR CODE HERE } /** * Get for color * * @return color */ public int getColor() { // ADD YOUR CODE HERE } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database Design With Microcomputer Applications

Authors: Glenn A. Jackson

1st Edition

0137718411, 978-0137718412

More Books

Students also viewed these Databases questions

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago