SlideShare a Scribd company logo
1 of 12
Download to read offline
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

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

Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfjyothimuppasani1
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfrajkumarm401
 
#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#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.pdfaquacareser
 
#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#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.pdfaquapariwar
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ projectUtkarsh Aggarwal
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212Mahmoud Samir Fayed
 
2nd National ArithmetEQ Challenge Rules
2nd National ArithmetEQ Challenge Rules2nd National ArithmetEQ Challenge Rules
2nd National ArithmetEQ Challenge RulesGomind
 
National ArithmetEQ Challenge Rules 2010
National ArithmetEQ Challenge Rules 2010National ArithmetEQ Challenge Rules 2010
National ArithmetEQ Challenge Rules 2010guest1b4853
 
Problem Solving - Games
Problem Solving - GamesProblem Solving - Games
Problem Solving - GamesKristantoMath
 
Upload
UploadUpload
Uploadvokenn
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word documentrudrapratap61
 
this is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdfthis is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdfarjunstores123
 
TornadoBrickSmasherUserManual
TornadoBrickSmasherUserManualTornadoBrickSmasherUserManual
TornadoBrickSmasherUserManualClayton Schembri
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdfNayanOza
 
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdfC# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdffazalenterprises
 
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdffms12345
 

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

Hello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdfHello!This is Java assignment applet.Can someone help me writing.pdf
Hello!This is Java assignment applet.Can someone help me writing.pdf
 
pptuni1
pptuni1pptuni1
pptuni1
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
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#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
 
#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#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
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
2nd National ArithmetEQ Challenge Rules
2nd National ArithmetEQ Challenge Rules2nd National ArithmetEQ Challenge Rules
2nd National ArithmetEQ Challenge Rules
 
National ArithmetEQ Challenge Rules 2010
National ArithmetEQ Challenge Rules 2010National ArithmetEQ Challenge Rules 2010
National ArithmetEQ Challenge Rules 2010
 
Problem Solving - Games
Problem Solving - GamesProblem Solving - Games
Problem Solving - Games
 
Upload
UploadUpload
Upload
 
New microsoft office word document
New microsoft office word documentNew microsoft office word document
New microsoft office word document
 
this is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdfthis is what i have. i really need help on updating the scores only..pdf
this is what i have. i really need help on updating the scores only..pdf
 
TornadoBrickSmasherUserManual
TornadoBrickSmasherUserManualTornadoBrickSmasherUserManual
TornadoBrickSmasherUserManual
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
Arbetsprov spelmanual
Arbetsprov spelmanualArbetsprov spelmanual
Arbetsprov spelmanual
 
C# using Visual studio - Windows Form. If possible step-by-step inst.pdf
C# using Visual studio - Windows Form. If possible step-by-step inst.pdfC# using Visual studio - Windows Form. If possible step-by-step inst.pdf
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
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
 

More from feelinggift

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

More from feelinggift (20)

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

Recently uploaded

dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningMarc Dusseiller Dusjagr
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17Celine George
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptxJoelynRubio1
 

Recently uploaded (20)

dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 

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++; } } }