i have a java problem.
i'm trying to write the hunt the wumpus game with simple conditions: (check-marked the ones i already accomplished)
[x]the pits will be placed randomly
[x] the wumpus is placed in the maze randomly (not sure if i did that one correctly)
[x] the player starts on the lower left of the maze row 3 col 0
-the player will only have 1 chance to shoot the Wumpus
[x]if the player is close to the Wumpus then there would be a prompt saying there is stench around
[x]if the player is close to a pit then she/he will be prompted that there is a breeze.
-if the player falls in a pit or gets eaten by the wumpus the game will be over and the map of the maze will be shown. I used 0 for empty cells and p for pits and w for wumpus in the array.

There is some problem with the program i've written so far but i don't know how to fix it. also, i don't know how to check if the wumpus will be in the direction the player wants to shoot. i'd appreciate any suggestions

Code: ( text )

import java.util.*;
public class playWumpus
//initMaze METHOD
//put the pits and wumpus into the world
public static void initMaze(char [][] maze)
Random r = new Random();

for (int row = 0; row <4; row ++)
maze[row][col] = 'O'; <<<<<<there is a problem here
int pitRow, pitCol;
for (int pitNum = 0; pitNum <4; pitNum++)
pitRow = r.nextInt(4); //randomly choose row
pitCol = r.nextInt(6); //randomly choose column
if (pitRow == 3 && pitCol == 0)//start location
maze [pitRow][pitCol] = 'p'; //places the pits in the maze randomly
maze [r.nextInt(4)][r.nextInt(6)] = 'w'; //places the wumpus randomly in the maze
}// end of Maze method

//CHECKMOVE method
//possible outcomes: run into the wall , fall into the pit, eaten by wumpus,
//feel breeze, smell stench, nothing.
public static int checkMove(char [] [] maze, int newRow, int newCol)
//checks if they run into a wall
if (newRow<0 || newRow>3 || newCol<0 || newCol>5)
System.out.println("You hit a wall");
return 0;
// it will return to the main method and places 0 in the state variable
else if (maze[newRow][newCol] == 'p')
//this checks the maze if there is a P in that location
System.out.println("You fall into a pit");
return 2;
// it will return to the main method and places 2 in the state variable
else if (maze[newRow][newCol] == 'w')//checks for the wumstem.out.println("You've eaten by the Wumpus!!");
//checks for the breeze (right,left,down,up) //<<is the following if-statement correct?>>>
if (
(newCol>0 && maze[newRow][newCol-1] == 'p') ||
(newCol<5 && maze[newRow][newCol+1] =='p') ||
(newRow>0 && maze[newCol][newRow-1] == 'p') ||
(newRow<3 && maze[newCol][newRow+1] =='p')
System.out.println("You feel a breeze");
return 1;

}//end of the maze method

public static void main(String [ ] args)
char [ ] [ ] maze = new char [4][6]; //the actual map of the game
int playerRow=3, playerCol=0; // player location aka lat/long
Scanner in= new Scanner(; //<<there is something wrong with my scanner>>>
int move, state;
// state of the game
// state 0= illegal move, 1= legal move, 3= end game
initMaze (maze); // calling the initMaze method
System.out.println("What would you like to do? 1=up, 2=down, 3=right 4=left, 5=shoot");
move = in.nextInt(; //<<for some reason eclipse is telling me that the type is incorrect>>
if (move ==1) // move up in the world
state = checkMove(maze, playerRow-1,playerCol); //these are coordinates
if ( state >0 ) // legal move
playerRow = playerRow-1;
if (move ==2) // move down in the world
state = checkMove(maze, playerRow+1,playerCol);
if ( state >0 ) // legal move
playerRow = playerRow+1;
if (move ==3) // move right in the world
state = checkMove(maze, playerRow,playerCol+1);
if ( state >0 ) // legal move
playerCol = playerCol+1;
if (move ==4) // move left in the world
state = checkMove(maze, playerRow,playerCol-1);
if ( state >0 ) // legal move
playerRow = playerCol-1;
if (move == 5) // shoot the wumpus in the world
System.out.println("Which direction would you like to shoot? 1=up, 2=down, 3=right, 4=left");
int shootDir = in.nextInt(;

// check if the wumpus gets killed
if ( shootDir == 1 )
System.out.println("You shot the Wumpus!");

}while (state!=2);
}//end of main

}//end of class

  1. 👍
  2. 👎
  3. 👁

Respond to this Question

First Name

Your Response

Similar Questions

  1. Algebra A

    write a short story problem that can be solved in one step. Write an equation that represents the problem. Name the property used to solve the problem, and then solve the problem. PLEASE HELP WITH THIS ASAP!!!

  2. ASVAB Arithmetic

    In Tim's last 5 games here's the number of three-point field goals scored per game. 9 6 0 9 3 How many three-point field goals would Tim have to kick in the next game to bring his average (arithmetic mean) to six points per game?

  3. java programming

    write a java program using arrays function for hotel bill calculation?

  4. algebra 1

    the deepest point in elevation in the indian ocean is the java trench, which is 25,344 feet below sea level. elevations below sea level are represented by negative numbers. can you help write the elevation of the Java Trench?

  1. Technology

    Which of the following is one way to assess whether or not a learning game is effective? A.Being able to win the game B.Doing the quiz before and after the game to see what you have learned.*** C.Making it difficult to win the

  2. math

    Jeff made 2 baskets in his first basketball game and 1 more basket in his next game. Assuming he scores 1 more basket each game, write a recursive formula to generate the sequence representing the total number of baskets Jeff made

  3. Algebra

    Jake scored x points in the first basketball game. He scored 2 fewer points in the next game. His teammate, Jack, scored 2y points in the first game and 4 more than twice as many points in the next game. Write and simplify an

  4. English

    How is Zaroff’s defeat in “The Most Dangerous Game” caused by his own arrogance? A) He is tricked by Rainsford. B) Zaroff is wounded by Rainsford’s trap. C) He lets Rainsford go to prolong the hunt. D) He watched Rainsford

  1. MaTh

    A square game board measures 16 inches on each side. The game board is divided into smaller squares measuring 2 inches on a side. How many small squares are there on the game board? My answer is 16x16 = 256 x 2=512, then I 16/2 =

  2. Math

    Martin has scored an average of 12 points per game this season Game 1 he scored 8 points, game 2 he scored 11 points, game 3 he scored 12 points, and game 4 he scored 16 points. Use numbers from the box (2,3,4,5,8,11,12,13,16,n)

  3. Math

    To play a game you spin a spinner like the one shown. You win if the arrow lands in one of the areas marked "WIN". Lee played this game many times and recorded her results. She won 8 times and lost 40 times. Use Lee's data to

  4. Programming

    I need to write a code in java based on an alrgorithm, the alrgorithm and it’s problem are below: The Sieve of Eratosthenes is “a simple, ancient algorithm for finding all prime numbers up to any given limit,” which you can

You can view more similar questions or ask a new question.