Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve asap need another person's perspective with these codes to-dos, I want to verify if I did my code correct tor if there are more

Solve asap

need another person's perspective with these codes to-dos, I want to verify if I did my code correct tor if there are more efficient ways to do it.

Here is the code:

import java.util.Random;

public class Minesweeper {

private boolean map[][]; // true if it's mined; false otherwise private char board[][]; // control the game's board private int size; private int mines; private static final int MIN_SIZE = 6; private static final int MIN_MINES = 1;

// TODO #1: finish the implementation of the constructor according to the instructions public Minesweeper(int size, int mines) {

}

// displays the board @Override public String toString() { String str = "x\\y\t"; for (int i = 0; i < this.size; i++) str += i + "\t"; str += " "; for (int i = 0; i < this.size; i++) { str += i + "\t"; for (int j = 0; j < this.size; j++) str += board[i][j] + "\t"; str += " "; } return str; }

// tries to hide a mine at a random location; returns true if attempt was successful; false otherwise private boolean hideMine() { Random rnd = new Random(); int x = rnd.nextInt(size); int y = rnd.nextInt(size); if (!map[x][y]) { map[x][y] = true; return true; } return false; }

// returns true if the location is valid and mined, false otherwise private boolean isMined(int x, int y) { if (x < 0 || x > size - 1 || y < 0 || y > size - 1) return false; return map[x][y]; }

// returns true if the location is valid and flagged, false otherwise private boolean isFlagged(int x, int y) { if (x < 0 || x > size - 1 || y < 0 || y > size - 1) return false; return board[x][y] == '+'; }

// returns the number of hidden mines public int getMines() { return mines; }

// TODO #2: this method should return the number of mines (immediately) around the given location private int minesAround(int x, int y) { return 0; }

// TODO #3: this method should return true if there is at least one tile in the board that reveals a mine public boolean isMineDetonated() { return false; }

// TODO #4: this method should return true if ALL non-mined tiles were revealed OR a mine was detonated; false otherwise // hint: check if the number of tiles marked with '?' matches the number of mines; also look for a "detonated" mine public boolean isGameOver() { return false; }

// same as reveal but with flag set to false public void reveal(int x, int y) { reveal(x, y, false); }

// TODO #5: this method should reveal the board tile based on the given location; // you must use the char conventions detailed in the README file // if you are not implementing the flag feature (bonus points) just ignore parameter "flag" void reveal(int x, int y, boolean flag) {

} }

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

Describe the agents duties to the principal.

Answered: 1 week ago

Question

14. Let X be uniform over (0, 1). Find E[X|X Answered: 1 week ago

Answered: 1 week ago

Question

What is the effect of word war second?

Answered: 1 week ago