Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

java-minesweeper (complete the code) The model (20 marks) The first step is to build the model of the game. This will be done via the

java-minesweeper (complete the code)

The model (20 marks)

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 icon (number of neighbouring mines, or blank if none) and status (covered 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 mines around each dots

The total number of mines in the Model

The number of uncovered dots so far

It also provides the necessary setters and getters, so the the controller and the view can check the status of any square, and the controller can change the status of a square. Finally, it provides a way to (re)initialize the game, reallocating the initial position of the mine randomly. A detailed description of the classes can be found in the documentation. The starting files for the source code are at https://www.eecs.uottawa.ca/ gvj/Courses/ITI1121/assignments/02/A2src.zip

GameModel:

import java.util.Random;

/** * The class GameModel holds the model, the state of the systems. * It stores the following information: * - the state of all the ``dots'' on the board (mined or not, clicked * or not, number of neighbooring mines...) * - the size of the board * - the number of steps since the last reset * * 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 * * @author Guy-Vincent Jourdan, University of Ottawa */ public class GameModel {

// ADD YOUR INSTANCE VARIABLES HERE

/** * Constructor to initialize the model to a given size of board. * * @param width * the width of the board * * @param heigth * the heigth of the board * * @param numberOfMines * the number of mines to hide in the board */ public GameModel(int width, int heigth, int numberOfMines) { // ADD YOU CODE HERE

}

/** * Resets the model to (re)start a game. The previous game (if there is one) * is cleared up . */ public void reset(){

// ADD YOU CODE HERE

}

/** * Getter method for the heigth of the game * * @return the value of the attribute heigthOfGame */ public int getHeigth(){ // ADD YOU CODE HERE

}

/** * Getter method for the width of the game * * @return the value of the attribute widthOfGame */ public int getWidth(){ // ADD YOU CODE HERE

}

/** * returns true if the dot at location (i,j) is mined, 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 isMined(int i, int j){ // ADD YOU CODE HERE

}

/** * returns true if the dot at location (i,j) has * been clicked, 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 hasBeenClicked(int i, int j){ // ADD YOU CODE HERE

}

/** * returns true if the dot at location (i,j) has zero mined * neighboor, 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 isBlank(int i, int j){ // ADD YOU CODE HERE

} /** * returns true if the dot is covered, 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 isCovered(int i, int j){ // ADD YOU CODE HERE

}

/** * returns the number of neighbooring mines os the dot * at location (i,j) * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot * @return the number of neighbooring mines at location (i,j) */ public int getNeighbooringMines(int i, int j){ // ADD YOU CODE HERE

}

/** * Sets the status of the dot at location (i,j) to uncovered * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot */ public void uncover(int i, int j){ // ADD YOU CODE HERE

}

/** * Sets the status of the dot at location (i,j) to clicked * * @param i * the x coordinate of the dot * @param j * the y coordinate of the dot */ public void click(int i, int j){ // ADD YOU CODE HERE

} /** * Uncover all remaining covered dot */ public void uncoverAll(){ // ADD YOU CODE HERE

}

/** * Getter method for the current number of steps * * @return the current number of steps */ public int getNumberOfSteps(){ // ADD YOU 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 YOU 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 square. */ public void step(){ // ADD YOU CODE HERE

} /** * The metod isFinished returns true iff the game is finished, that * is, all the nonmined dots are uncovered. * * @return true if the game is finished, false otherwise */ public boolean isFinished(){ // ADD YOU CODE HERE

}

/** * Builds a String representation of the model * * @return String representation of the model */ public String toString(){ // ADD YOU CODE HERE

} }

DotInfo:

/** * The class DotInfo is a simple helper class to store * the state (e.g. clicked, mined, number of neighbooring mines...) * at the dot position (x,y) * * @author Guy-Vincent Jourdan, University of Ottawa */

public class DotInfo {

// ADD YOUR INSTANCE VARIABLES HERE

/** * Constructor, used to initialize the instance variables * * @param x * the x coordinate * @param y * the y coordinate */ public DotInfo(int x, int y){

// ADD YOU CODE HERE

}

/** * Getter method for the attribute x. * * @return the value of the attribute x */ public int getX(){

// ADD YOU CODE HERE

} /** * Getter method for the attribute y. * * @return the value of the attribute y */ public int getY(){

// ADD YOU CODE HERE

} /** * Setter for mined */ public void setMined() {

// ADD YOU CODE HERE

}

/** * Getter for mined * * @return mined */ public boolean isMined() {

// ADD YOU CODE HERE

}

/** * Setter for covered */ public void uncover() {

// ADD YOU CODE HERE

}

/** * Getter for covered * * @return covered */ public boolean isCovered(){

// ADD YOU CODE HERE

}

/** * Setter for wasClicked */ public void click() {

// ADD YOU CODE HERE

}

/** * Getter for wasClicked * * @return wasClicked */ public boolean hasBeenClicked() {

// ADD YOU CODE HERE

}

/** * Setter for neighbooringMines * * @param neighbooringMines * number of neighbooring mines */ public void setNeighbooringMines(int neighbooringMines) {

// ADD YOU CODE HERE

}

/** * Get for neighbooringMines * * @return neighbooringMines */ public int getNeighbooringMines() {

// ADD YOU 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

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions