Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

4.12 Lab 5 : Visualizing Wumpus World (using C++) In this lab you are going to e

ID: 3671058 • Letter: 4

Question

4.12 Lab 5 : Visualizing Wumpus World (using C++)

In this lab you are going to explore visualizing a grid-based Wumpus World using ASCII art. We will build this program incrementally.

1.) You need to take as input from the user the number of rows and columns, in that order. You also need to check if the inputs are within the accepted range of 2 to 9 inclusive. If the row size is invalid, output an error message: "Row size is illegal!" and similarly for the column size. For valid sizes, you print the grid.

For example, where the user enters 3 and 5:

Another example, where the user enter 1 and 3:

Each grid element consists of :

'-' for the horizontal (row)

'|' for the vertical (column)

2.) You need to add the user into the grid. We will use '*' to represent the user. The user's starting location should be random. You will output this location in the form "User location: (i, j)", where i is the row and j is the column. When you display the grid, you should output '*' in the user's location. In this lab, we will use a fixed seed value of 13 for the random generator.

For example, where the user enters 2 and 4:

3.) You are probably wondering what in the world is a wumpus. A wumpus is a monster that will devour the poor user! Of course, at the moment, Wumpus World does not actually contain a wumpus. So let's change that! Generate a random location on the grid for the wumpus. The user and the wumpus cannot start at the same location. You will output this location in the form "Wumpus location: (i, j)". For output, use 'W' to represent the wumpus' location.

For example, where the user enters 6 and 3:

4.) The last part of Wumpus World is adding in a pit. Create a random starting location for the pit. Again, ensure that the pit, the wumpus and the user are not starting on the same spot. You will output this location in the form "Pit location: (i, j)". For output, use 'o' to represent the pit.

For example, where the user enters 4 and 5:

It is recommended that you work on this lab in Dev C++. Once you finish step 4, copy and paste your working code into zyBooks. Good luck!

Explanation / Answer

/*HEADERS*/

#include <iostream>

#include <fstream>

#include <cstdlib>

#include <string>

/*METHOD FOR PREVENTING*/

using namespace std;

/*DETAILS GAME*/

struct Game_info

{

//great struct, but what is it for?

char Wumpus;

char Bats;

char Pit;

char Hunter;

int room_num[20];

};

ifstream infile;

/*MAIN METHOD*/

main()

/*INTEGER DECLERATION*/

{

char choice;

int arrows = 10;

/*DEFINED TYPE*/

cout<<"Objective: hunt and kill all wumpuses ";

cout<<"You are in a room ";

cout<<"you can travel to room[ctr] room[ctr] room[ctr]. ";

/*LOOP*/

do

{

cout<<"Can you smell a wumpus nearby? (y/n) ";

/*OPTION*/

cin >> choice;

}

while (!(choice == 'y' || choice == 'Y' || choice == 'n' || choice == 'N'));

/*CONDITION*/

if (choice == 'y' || choice == 'Y')

{

/*INSERTION OPERATOR*/

cout<<"Can you feel a draft from a nearby pit? ";

cout<<"Can you here bats nearby? ";

cout<<"You have " << arrows << " arrows. ";

/*REPEATED LOOP WILL PROVIDE CORRECT OUTPUT*/

do

{

cout<<"Do you want to move or shoot? (y/n) ";

cin >> choice;

}

while (!(choice == 'y' || choice == 'Y' || choice == 'n' || choice == 'N'));

/*CHOOSE THE OPTION*/

if (choice == 'y' || choice == 'Y')

{

/*CLICK OUT*/

arrows = arrows -1;

cout<<"You have " << arrows << " arrows left. ";

}

}

else if (choice == 'n' || choice == 'N')

{

}

return 0;

/*END MAIN*/

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote