SlideShare a Scribd company logo
This is a homework assignment that I have for my Java coding class. I have completed most of
the assignment, but I am having some issue. Could you find my problem and then take my code
and add the corrections to it and then display the complete code that works? I REPEAT CAN
YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD
THE CHANGES. I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND
THEN USE MY CODE AND ADD THE CHANGES!
I have asked this question 3 times and no one has done what I have requested. I don't want a
different solution to my problem. It doesn't take a lot of work to search chegg and then copy and
paste an answer from another question. I REPEAT CAN YOU LOCATE WHY MY CODE
ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES!
Objective:
Write a game where you are an X trying to get an ice cream cone in a mine field
Before the game starts, a field of mines are created.
The board has to be first initialized
There mines occupy a tenth of the board (IE (BoardSize x BoardSize)/10 = the number of mines)
The mines are randomly placed on the board. If a space which is already occupied (either by the
player, the ice cream cone, or another mine) is selected then another space must be selected until
an empty space is found.
The player is placed at 0,0
The ice cream cone is placed at a random location on the board
At each turn, the player chooses to move in the X or Y direction by entering either -1, 0, or 1,
where
-1 is going one space in the negative direction
1 is going one space in the positive direction (remember positive for Y is down)
0 is staying still
9 quits the game
Anything other than these values should prompt the player that they have inputted an invalid
value and then not move in that direction (IE 0).
Before each turn the board is displayed indicating where the player (X) and the goal (^) are
located. Unoccupied spaces and mines are denoted by and underscore (_). Remember mines need
to be hidden so they are also underscores (_). The board is maximum 10 spaces long and wide.
Once the player reaches the ice cream cone the player wins
If the player lands on a space with a mine they are killed and the game is over
After the game is over, the player should be prompted whether or not they want to play again.
Example Dialog:
Welcome to Mine Walker. Get the ice cream cone and avoid the mines
X_________
__________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
1
Enter either a -1,0, or 1 in the Y
1
__________
_X________
__________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
0
Enter either a -1,0, or 1 in the Y
1
__________
__________
_X________
__________
__________
__________
__________
__________
__________
_________^
Enter either a -1, 0, or 1 in the X or 9 to quit
-1
Enter either a -1,0, or 1 in the Y
1
Boom! Dead!
Would you like to play again?
This is the code I have so far. And it works fine. But when you land on a bomb or the ice cream
and it ask you to play again, if you say yes then it doesn't reset the game board. Instead it just
continues from where the "X" last was on the board. How can I reset the board at the end if the
user wants to play again? Again can you add the changes that need to be made to my existing
code and then give the answer with the complete code that works? I REPEAT CAN YOU
LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE
CHANGES! I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND
THEN USE MY CODE AND ADD THE CHANGES! I REPEAT CAN YOU LOCATE WHY
MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES!
import java.util.Random;
import java.util.Scanner;
public class MineWalker
{
//Setup enum, Scanner, and final variables
enum Spaces {Empty, Player, Mines, Ice_Cream, Walked_Path};
private static final int BOARD_SIZE = 10;
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args)
{
//Player's location
int pX = 0;
int pY = 0;
//Game intro
System.out.println("Welcome to Mine Walker. Get the ice cream cone and avoid the mines");
int numberOfMoves = 0;
//Setup board for the game
Spaces[][] board = new Spaces[BOARD_SIZE][BOARD_SIZE];
//Location of the ice cream
Random r = new Random();
int gX = r.nextInt(BOARD_SIZE);
int gY = r.nextInt(BOARD_SIZE);
//Initialize the game board
for (int y = 0; y < board.length; y++)
{
for(int x = 0; x < board[y].length; x++)
{
board[x][y] = Spaces.Empty;
}
}
board[pX][pY] = Spaces.Player;
board[gX][gY] = Spaces.Ice_Cream;
int mineMax = 10;
int mineCount = 0;
//Place mines on the board
do
{
int x = r.nextInt(BOARD_SIZE - 1) + 1; //Makes sure mine isn't 0,0
int y = r.nextInt(BOARD_SIZE - 1) + 1;
if(board[x][y] == Spaces.Empty)
{
board[x][y] = Spaces.Mines;
mineCount++;
}
}while(mineMax > mineCount);
boolean gameOver = false;
while(gameOver == false)
{
for(int y = 0; y < board.length; y++)
{
for(int x = 0; x < board[y].length; x++)
{
switch(board[x][y])
{
case Empty:
System.out.print("_");
break;
case Player:
System.out.print("X");
break;
case Walked_Path:
System.out.print("#");
break;
case Ice_Cream:
System.out.print("^");
break;
case Mines:
System.out.print("o");
break;
default:
System.out.print("?");
break;
}
}
System.out.println(" ");
}
//The player moves
System.out.println("Enter either a -1, 0, or 1 in the X direction or 9 to quit");
//Movement in the X direction
int dX = scanner.nextInt();
//Or quit
if(dX == 9)
{
System.out.println("Game over");
break;
}
System.out.println("Enter either a -1, 0, or 1 in the Y direction");
//Movement in the Y direction
int dY = scanner.nextInt();
//Checks to see if the movement is valid
if(dX < -1 || dX > 1)
{
System.out.println("Invalid input X");
dX = 0;
}
if(dY < -1 || dY > 1)
{
System.out.println("Invalid input Y");
dY = 0;
}
//Sets the player position to a walked path
board[pX][pY] = Spaces.Walked_Path;
//Moves the player
pY += dX;
pX += dY;
//Makes sure everything is still in bounds
if(pX < 0)
{
pX = 0;
}
else if(pX > BOARD_SIZE - 1)
{
pX = BOARD_SIZE - 1;
}
if(pY < 0)
{
pY = 0;
}
else if(pY > BOARD_SIZE - 1)
{
pY = BOARD_SIZE - 1;
}
//Losing condition
if(board[pX][pY] == Spaces.Mines)
{
System.out.println("Boom! Dead!");
gameOver = true;
System.out.println("Would you like to play again? Yes or No");
String playAgain = scanner.next();
if(playAgain.equals("yes"))
{
gameOver = false;
}
else if(playAgain.equals("no"))
{
System.out.println("Thanks for playing!");
gameOver = true;
}
}
//Winning condition
if(board[pX][pY] == Spaces.Ice_Cream)
{
System.out.println("You made it to the ice cream cone!");
gameOver = true;
System.out.println("Would you like to play again? Yes or No");
String playAgain = scanner.next();
if(playAgain.equals("yes"))
{
gameOver = false;
}
else if(playAgain.equals("no"))
{
System.out.println("Thanks for playing!");
gameOver = true;
}
}
board[pX][pY] = Spaces.Player;
numberOfMoves++;
}
}
}
Please don't just answer with different code. Use my existing code and fix my problem.
I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY
CODE AND ADD THE CHANGES!I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T
WORKING AND THEN USE MY CODE AND ADD THE CHANGES!I REPEAT CAN YOU
LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE
CHANGES!
Solution
I have found few problem. the mines are not hidden in the board. some where your comparison
of bool values are not standard. I have corrected all those stuff. Now the code works fine.
package chegg;
import java.util.Random;
import java.util.Scanner;
public class MineWalker {
// Setup enum, Scanner, and final variables
enum Spaces {
Empty, Player, Mines, Ice_Cream, Walked_Path
};
private static final int BOARD_SIZE = 10;
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
// Player's location
int pX = 0;
int pY = 0;
boolean freshGame = false;
// Game intro
System.out.println("Welcome to Mine Walker. Get the ice cream cone and avoid the
mines");
int numberOfMoves = 0;
// Setup board for the game
Spaces[][] board = new Spaces[BOARD_SIZE][BOARD_SIZE];
// Location of the ice cream
Random r = new Random();
int gX = r.nextInt(BOARD_SIZE);
int gY = r.nextInt(BOARD_SIZE);
// Initialize the game board
for (int y = 0; y < board.length; y++) {
for (int x = 0; x < board[y].length; x++) {
board[x][y] = Spaces.Empty;
// System.out.println("Empty space"+Spaces.Empty);
}
}
board[pX][pY] = Spaces.Player;
board[gX][gY] = Spaces.Ice_Cream;
int mineMax = 10;
int mineCount = 0;
// Place mines on the board
do {
int x = r.nextInt(BOARD_SIZE - 1) + 1; // Makes sure mine isn't 0,0
int y = r.nextInt(BOARD_SIZE - 1) + 1;
if (board[x][y].equals(Spaces.Empty)) // change
{
board[x][y] = Spaces.Mines;
mineCount++;
}
} while (mineMax > mineCount);
boolean gameOver = false;
while (!gameOver) {
freshGame=false;
for (int y = 0; y < board.length; y++) {
for (int x = 0; x < board[y].length; x++) {
switch (board[x][y]) {
case Empty:
System.out.print("_");
break;
case Player:
System.out.print("X");
break;
case Walked_Path:
System.out.print("#");
break;
case Ice_Cream:
System.out.print("^");
break;
case Mines:
System.out.print("_");
break;
default:
System.out.print("?");
break;
}
}
System.out.println(" ");
}
// The player moves
System.out.println("Enter either a -1, 0, or 1 in the X direction or 9 to quit");
// Movement in the X direction
int dX = scanner.nextInt();
// Or quit
if (dX == 9) {
System.out.println("Game over");
break;
}
System.out.println("Enter either a -1, 0, or 1 in the Y direction");
// Movement in the Y direction
int dY = scanner.nextInt();
// Checks to see if the movement is valid
if (dX < -1 || dX > 1) {
System.out.println("Invalid input X");
dX = 0;
}
if (dY < -1 || dY > 1) {
System.out.println("Invalid input Y");
dY = 0;
}
// Sets the player position to a walked path
board[pX][pY] = Spaces.Walked_Path;
// Moves the player
pY += dX; // change
pX += dY; // change
// Makes sure everything is still in bounds
if (pX < 0) {
pX = 0;
} else if (pX > BOARD_SIZE - 1) {
pX = BOARD_SIZE - 1;
}
if (pY < 0) {
pY = 0;
} else if (pY > BOARD_SIZE - 1) {
pY = BOARD_SIZE - 1;
}
// Losing condition
if (board[pX][pY] == Spaces.Mines) {
System.out.println("Boom! Dead!");
gameOver = true;
System.out.println("Would you like to play again? Yes or No");
String playAgain = scanner.next();
if (playAgain.equals("yes")) {
gameOver = false;
} else if (playAgain.equals("no")) {
System.out.println("Thanks for playing!");
gameOver = true;
}
}
// Winning condition
if (board[pX][pY] == Spaces.Ice_Cream) {
System.out.println("You made it to the ice cream cone!");
gameOver = true;
System.out.println("Would you like to play again? Yes or No");
String playAgain = scanner.next();
if (playAgain.equals("yes")) {
gameOver = false;
} else {
System.out.println("Thanks for playing!");
gameOver = true;
}
}
board[pX][pY] = Spaces.Player;
numberOfMoves++;
}
}
}

More Related Content

PDF
This is for an homework assignment using Java code. Here is the home.pdf
PDF
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
PDF
PLEASE can do this in NETBEAN I need that way thank very muchManca.pdf
PDF
Yet another building metaphor
PDF
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
PPTX
Project 2
PDF
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
PDF
The main class of the tictoe game looks like.public class Main {.pdf
This is for an homework assignment using Java code. Here is the home.pdf
Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf
PLEASE can do this in NETBEAN I need that way thank very muchManca.pdf
Yet another building metaphor
In Java using Eclipse, Im suppose to write a class that encapsulat.pdf
Project 2
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
The main class of the tictoe game looks like.public class Main {.pdf

Similar to This is a homework assignment that I have for my Java coding class. .pdf (19)

PDF
Hello!This is Java assignment applet.Can someone help me writing.pdf
PDF
pptuni1
PDF
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
PDF
#In this project you will write a program play TicTacToe #using tw.pdf
PDF
#In this project you will write a program play TicTacToe #using tw.pdf
PPT
Tic tac toe on c++ project
PDF
The Ring programming language version 1.10 book - Part 71 of 212
PPT
2nd National ArithmetEQ Challenge Rules
PPT
National ArithmetEQ Challenge Rules 2010
PPTX
Problem Solving - Games
PPT
problem-reduction-game-problemgmgntc.ppt
PDF
Upload
DOCX
New microsoft office word document
PDF
this is what i have. i really need help on updating the scores only..pdf
PDF
TornadoBrickSmasherUserManual
PDF
19012011102_Nayan Oza_Practical-7_AI.pdf
PDF
Arbetsprov spelmanual
PDF
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
PDF
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
pptuni1
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
#In this project you will write a program play TicTacToe #using tw.pdf
Tic tac toe on c++ project
The Ring programming language version 1.10 book - Part 71 of 212
2nd National ArithmetEQ Challenge Rules
National ArithmetEQ Challenge Rules 2010
Problem Solving - Games
problem-reduction-game-problemgmgntc.ppt
Upload
New microsoft office word document
this is what i have. i really need help on updating the scores only..pdf
TornadoBrickSmasherUserManual
19012011102_Nayan Oza_Practical-7_AI.pdf
Arbetsprov spelmanual
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
Ad

More from feelinggift (20)

PDF
A) Which of the following element is seen in all organic molecules Si.pdf
PDF
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
PDF
Write an MSP430g2553 C program to drive a continually scrolling mess.pdf
PDF
Which of the following is NOT a financial measurement needed to see .pdf
PDF
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdf
PDF
What motives do corporate executives have that force them to embrace.pdf
PDF
when are business cases or project charters overkillSolutionP.pdf
PDF
True or False The Congressional Budget Office projects that approxi.pdf
PDF
Using the space provided compose an ESSAY concerning the following qu.pdf
PDF
We continually hear about interest groups in the news. Understanding.pdf
PDF
View transaction list Journal entry worksheet 6 9 The company receive.pdf
PDF
Physical security is a fundamental component of any secure infrastru.pdf
PDF
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
PDF
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
PDF
The first thermodynamic law for a system of charged molecules in elec.pdf
PDF
show all of your work to arrive a final result Simple Interest Simpl.pdf
PDF
Terms from which students can chooseMacrophages; •Only one.pdf
PDF
Simulate the Stakeholder deliverable for the development of an onlin.pdf
PDF
I want to write this program in java.Write a simple airline ticket.pdf
PDF
Research how voting is conducted for the following event. Descri.pdf
A) Which of the following element is seen in all organic molecules Si.pdf
Given an ArrayList, write a Java method that returns a new ArrayList.pdf
Write an MSP430g2553 C program to drive a continually scrolling mess.pdf
Which of the following is NOT a financial measurement needed to see .pdf
Which process uses chemiosmosis A. Pyruvate oxidation B. Electron .pdf
What motives do corporate executives have that force them to embrace.pdf
when are business cases or project charters overkillSolutionP.pdf
True or False The Congressional Budget Office projects that approxi.pdf
Using the space provided compose an ESSAY concerning the following qu.pdf
We continually hear about interest groups in the news. Understanding.pdf
View transaction list Journal entry worksheet 6 9 The company receive.pdf
Physical security is a fundamental component of any secure infrastru.pdf
TrueFalse Verilog is case-insensitive TF Verilog has constructs.pdf
The Jannuschs operated Festival Foods, a busi- ness that served conc.pdf
The first thermodynamic law for a system of charged molecules in elec.pdf
show all of your work to arrive a final result Simple Interest Simpl.pdf
Terms from which students can chooseMacrophages; •Only one.pdf
Simulate the Stakeholder deliverable for the development of an onlin.pdf
I want to write this program in java.Write a simple airline ticket.pdf
Research how voting is conducted for the following event. Descri.pdf
Ad

Recently uploaded (20)

PDF
Complications of Minimal Access Surgery at WLH
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Pre independence Education in Inndia.pdf
PPTX
master seminar digital applications in india
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
Institutional Correction lecture only . . .
PDF
Basic Mud Logging Guide for educational purpose
PDF
Classroom Observation Tools for Teachers
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Sports Quiz easy sports quiz sports quiz
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
RMMM.pdf make it easy to upload and study
Complications of Minimal Access Surgery at WLH
Abdominal Access Techniques with Prof. Dr. R K Mishra
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Microbial diseases, their pathogenesis and prophylaxis
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Pre independence Education in Inndia.pdf
master seminar digital applications in india
Pharmacology of Heart Failure /Pharmacotherapy of CHF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Institutional Correction lecture only . . .
Basic Mud Logging Guide for educational purpose
Classroom Observation Tools for Teachers
Module 4: Burden of Disease Tutorial Slides S2 2025
Supply Chain Operations Speaking Notes -ICLT Program
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Sports Quiz easy sports quiz sports quiz
102 student loan defaulters named and shamed – Is someone you know on the list?
RMMM.pdf make it easy to upload and study

This is a homework assignment that I have for my Java coding class. .pdf

  • 1. This is a homework assignment that I have for my Java coding class. I have completed most of the assignment, but I am having some issue. Could you find my problem and then take my code and add the corrections to it and then display the complete code that works? I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES. I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! I have asked this question 3 times and no one has done what I have requested. I don't want a different solution to my problem. It doesn't take a lot of work to search chegg and then copy and paste an answer from another question. I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! Objective: Write a game where you are an X trying to get an ice cream cone in a mine field Before the game starts, a field of mines are created. The board has to be first initialized There mines occupy a tenth of the board (IE (BoardSize x BoardSize)/10 = the number of mines) The mines are randomly placed on the board. If a space which is already occupied (either by the player, the ice cream cone, or another mine) is selected then another space must be selected until an empty space is found. The player is placed at 0,0 The ice cream cone is placed at a random location on the board At each turn, the player chooses to move in the X or Y direction by entering either -1, 0, or 1, where -1 is going one space in the negative direction 1 is going one space in the positive direction (remember positive for Y is down) 0 is staying still 9 quits the game Anything other than these values should prompt the player that they have inputted an invalid value and then not move in that direction (IE 0). Before each turn the board is displayed indicating where the player (X) and the goal (^) are located. Unoccupied spaces and mines are denoted by and underscore (_). Remember mines need to be hidden so they are also underscores (_). The board is maximum 10 spaces long and wide. Once the player reaches the ice cream cone the player wins If the player lands on a space with a mine they are killed and the game is over After the game is over, the player should be prompted whether or not they want to play again. Example Dialog:
  • 2. Welcome to Mine Walker. Get the ice cream cone and avoid the mines X_________ __________ __________ __________ __________ __________ __________ __________ __________ _________^ Enter either a -1, 0, or 1 in the X or 9 to quit 1 Enter either a -1,0, or 1 in the Y 1 __________ _X________ __________ __________ __________ __________ __________ __________ __________ _________^ Enter either a -1, 0, or 1 in the X or 9 to quit 0 Enter either a -1,0, or 1 in the Y 1 __________ __________ _X________ __________ __________ __________ __________
  • 3. __________ __________ _________^ Enter either a -1, 0, or 1 in the X or 9 to quit -1 Enter either a -1,0, or 1 in the Y 1 Boom! Dead! Would you like to play again? This is the code I have so far. And it works fine. But when you land on a bomb or the ice cream and it ask you to play again, if you say yes then it doesn't reset the game board. Instead it just continues from where the "X" last was on the board. How can I reset the board at the end if the user wants to play again? Again can you add the changes that need to be made to my existing code and then give the answer with the complete code that works? I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! import java.util.Random; import java.util.Scanner; public class MineWalker { //Setup enum, Scanner, and final variables enum Spaces {Empty, Player, Mines, Ice_Cream, Walked_Path}; private static final int BOARD_SIZE = 10; private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { //Player's location int pX = 0; int pY = 0; //Game intro System.out.println("Welcome to Mine Walker. Get the ice cream cone and avoid the mines");
  • 4. int numberOfMoves = 0; //Setup board for the game Spaces[][] board = new Spaces[BOARD_SIZE][BOARD_SIZE]; //Location of the ice cream Random r = new Random(); int gX = r.nextInt(BOARD_SIZE); int gY = r.nextInt(BOARD_SIZE); //Initialize the game board for (int y = 0; y < board.length; y++) { for(int x = 0; x < board[y].length; x++) { board[x][y] = Spaces.Empty; } } board[pX][pY] = Spaces.Player; board[gX][gY] = Spaces.Ice_Cream; int mineMax = 10; int mineCount = 0; //Place mines on the board do { int x = r.nextInt(BOARD_SIZE - 1) + 1; //Makes sure mine isn't 0,0 int y = r.nextInt(BOARD_SIZE - 1) + 1; if(board[x][y] == Spaces.Empty) { board[x][y] = Spaces.Mines; mineCount++; } }while(mineMax > mineCount);
  • 5. boolean gameOver = false; while(gameOver == false) { for(int y = 0; y < board.length; y++) { for(int x = 0; x < board[y].length; x++) { switch(board[x][y]) { case Empty: System.out.print("_"); break; case Player: System.out.print("X"); break; case Walked_Path: System.out.print("#"); break; case Ice_Cream: System.out.print("^"); break; case Mines: System.out.print("o"); break; default: System.out.print("?"); break; } } System.out.println(" "); } //The player moves System.out.println("Enter either a -1, 0, or 1 in the X direction or 9 to quit"); //Movement in the X direction int dX = scanner.nextInt(); //Or quit
  • 6. if(dX == 9) { System.out.println("Game over"); break; } System.out.println("Enter either a -1, 0, or 1 in the Y direction"); //Movement in the Y direction int dY = scanner.nextInt(); //Checks to see if the movement is valid if(dX < -1 || dX > 1) { System.out.println("Invalid input X"); dX = 0; } if(dY < -1 || dY > 1) { System.out.println("Invalid input Y"); dY = 0; } //Sets the player position to a walked path board[pX][pY] = Spaces.Walked_Path; //Moves the player pY += dX; pX += dY; //Makes sure everything is still in bounds if(pX < 0) { pX = 0; } else if(pX > BOARD_SIZE - 1) { pX = BOARD_SIZE - 1; } if(pY < 0) { pY = 0;
  • 7. } else if(pY > BOARD_SIZE - 1) { pY = BOARD_SIZE - 1; } //Losing condition if(board[pX][pY] == Spaces.Mines) { System.out.println("Boom! Dead!"); gameOver = true; System.out.println("Would you like to play again? Yes or No"); String playAgain = scanner.next(); if(playAgain.equals("yes")) { gameOver = false; } else if(playAgain.equals("no")) { System.out.println("Thanks for playing!"); gameOver = true; } } //Winning condition if(board[pX][pY] == Spaces.Ice_Cream) { System.out.println("You made it to the ice cream cone!"); gameOver = true; System.out.println("Would you like to play again? Yes or No"); String playAgain = scanner.next(); if(playAgain.equals("yes")) { gameOver = false; }
  • 8. else if(playAgain.equals("no")) { System.out.println("Thanks for playing!"); gameOver = true; } } board[pX][pY] = Spaces.Player; numberOfMoves++; } } } Please don't just answer with different code. Use my existing code and fix my problem. I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES!I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES!I REPEAT CAN YOU LOCATE WHY MY CODE ISN'T WORKING AND THEN USE MY CODE AND ADD THE CHANGES! Solution I have found few problem. the mines are not hidden in the board. some where your comparison of bool values are not standard. I have corrected all those stuff. Now the code works fine. package chegg; import java.util.Random; import java.util.Scanner; public class MineWalker { // Setup enum, Scanner, and final variables enum Spaces { Empty, Player, Mines, Ice_Cream, Walked_Path }; private static final int BOARD_SIZE = 10; private static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { // Player's location int pX = 0; int pY = 0;
  • 9. boolean freshGame = false; // Game intro System.out.println("Welcome to Mine Walker. Get the ice cream cone and avoid the mines"); int numberOfMoves = 0; // Setup board for the game Spaces[][] board = new Spaces[BOARD_SIZE][BOARD_SIZE]; // Location of the ice cream Random r = new Random(); int gX = r.nextInt(BOARD_SIZE); int gY = r.nextInt(BOARD_SIZE); // Initialize the game board for (int y = 0; y < board.length; y++) { for (int x = 0; x < board[y].length; x++) { board[x][y] = Spaces.Empty; // System.out.println("Empty space"+Spaces.Empty); } } board[pX][pY] = Spaces.Player; board[gX][gY] = Spaces.Ice_Cream; int mineMax = 10; int mineCount = 0; // Place mines on the board do { int x = r.nextInt(BOARD_SIZE - 1) + 1; // Makes sure mine isn't 0,0 int y = r.nextInt(BOARD_SIZE - 1) + 1; if (board[x][y].equals(Spaces.Empty)) // change { board[x][y] = Spaces.Mines; mineCount++; } } while (mineMax > mineCount); boolean gameOver = false; while (!gameOver) {
  • 10. freshGame=false; for (int y = 0; y < board.length; y++) { for (int x = 0; x < board[y].length; x++) { switch (board[x][y]) { case Empty: System.out.print("_"); break; case Player: System.out.print("X"); break; case Walked_Path: System.out.print("#"); break; case Ice_Cream: System.out.print("^"); break; case Mines: System.out.print("_"); break; default: System.out.print("?"); break; } } System.out.println(" "); } // The player moves System.out.println("Enter either a -1, 0, or 1 in the X direction or 9 to quit"); // Movement in the X direction int dX = scanner.nextInt(); // Or quit if (dX == 9) { System.out.println("Game over"); break; } System.out.println("Enter either a -1, 0, or 1 in the Y direction");
  • 11. // Movement in the Y direction int dY = scanner.nextInt(); // Checks to see if the movement is valid if (dX < -1 || dX > 1) { System.out.println("Invalid input X"); dX = 0; } if (dY < -1 || dY > 1) { System.out.println("Invalid input Y"); dY = 0; } // Sets the player position to a walked path board[pX][pY] = Spaces.Walked_Path; // Moves the player pY += dX; // change pX += dY; // change // Makes sure everything is still in bounds if (pX < 0) { pX = 0; } else if (pX > BOARD_SIZE - 1) { pX = BOARD_SIZE - 1; } if (pY < 0) { pY = 0; } else if (pY > BOARD_SIZE - 1) { pY = BOARD_SIZE - 1; } // Losing condition if (board[pX][pY] == Spaces.Mines) { System.out.println("Boom! Dead!"); gameOver = true; System.out.println("Would you like to play again? Yes or No"); String playAgain = scanner.next(); if (playAgain.equals("yes")) { gameOver = false; } else if (playAgain.equals("no")) {
  • 12. System.out.println("Thanks for playing!"); gameOver = true; } } // Winning condition if (board[pX][pY] == Spaces.Ice_Cream) { System.out.println("You made it to the ice cream cone!"); gameOver = true; System.out.println("Would you like to play again? Yes or No"); String playAgain = scanner.next(); if (playAgain.equals("yes")) { gameOver = false; } else { System.out.println("Thanks for playing!"); gameOver = true; } } board[pX][pY] = Spaces.Player; numberOfMoves++; } } }