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

solve in C++ In this lab you are going to explore visualizing a grid-based Wumpu

ID: 3673617 • Letter: S

Question

solve in 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: Row size is illegal! 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: User location: (0, 1) --- --- --- --- | | * | | | --- --- --- --- | | | | | --- --- --- --- 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: User location: (0, 2) Wumpus location: (3, 1) --- --- --- | | | * | --- --- --- | | | | --- --- --- | | | | --- --- --- | | W | | --- --- --- | | | | --- --- --- | | | | --- --- --- 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: User location: (2, 1) Wumpus location: (3, 1) Pit location: (0, 4) --- --- --- --- --- | | | | | o | --- --- --- --- --- | | | | | | --- --- --- --- --- | | * | | | | --- --- --- --- --- | | W | | | | --- --- --- --- --- 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! NOTE: The zyBooks servers are different from your own computer. The example outputs above might not match your outputs. But once you copy-and-paste your code into zyBooks, it will all work out.

Explanation / Answer

main.cpp

#include "WA.h"
using namespace std;
// formation of grid
void MakeGrid()
{
   char grid[4][4] = {
       { '0','1','2','3' },
       { '0','1','2','3' },
       { '0','1','2','3' },
       { '0','1','2','3' } };
   // displays the character within the grid
   char character = '*';
   //position of character.
}

int main() {

   int done = 0;
   char choice;

   cout << "Welcome to:" << endl;
   cout << "Wumpus World!" << endl;
   cout << endl;
   cout << "Choose an Option:" << endl;
   cout << "1 - Play Wumpus World" << endl;
   cout << "2 - Help" << endl;
   cout << "3 - Quit" << endl;
   cout << "";
   cin >> choice;


   //Makes a switch statment for player choice.
   switch (choice)
   {
   case '1':
       system("cls");
       cout << "Thanks for playing Wumpus World " << endl;


       break;
       // A Players Guide to the game and gives tem basic understanding.
   case '2':
       cout << " Controls " << endl;
       cout << " ------------------ - " << endl;
       cout << "W - Moves the Robot Up " << endl;
       cout << "A - Moves the Robot Left " << endl;
       cout << "S - Moves the Robot Down " << endl;
       cout << "D - Moves the Robot Right " << endl;
       cout << "Q - Shoots the Arrow" << endl;
       cout << "" << endl;
       cout << "Instructions On How To Play" << endl;
       cout << "--------------------------" << endl;
       cout << "1. The Robot starts in a 2D grid, which gives the player 16 cells to move around and explore the area." << endl;
       cout << "2. By using the controls listed above, navigate your character around the grid to find Gold and the Wumpus itself." << endl;
       cout << "3. Avoid traveling farther than the grids demensions or it will result in a death and a restart of the game." << endl;
       cout << "4. Once you find the gold, make your way back to the start without running into the Wumpus." << endl;
       system("pause");
       return (choice);
       {
       }
       cout << "" << endl;
       break;
       system("cls");
   case '3':
       return 0;
       break;
   default:
       system("cls");
       cout << "Invalid Choice" << endl;
       return main();
       break;
   }

   int retry;
   cout << "Press r to reset or etc to quit" << endl;
   cin >> retry;
   switch (retry)
   {
       //ASCII code for r
   case 114:
   {
       system("cls");
      
   }
   default:
       //Prints Grid
       MakeGrid();
       int begin = 1;
       switch (begin)
   case 1:
       {
           {Robot Robot(0, 0, 119);
           Robot.WA();
           }
       }
   }

  
   cout << " Where would you like to move? " << endl;
   cin.get();


  


  
   system("pause");
   return 0;

}


WA.h

#ifndef WA_H
#define WA_H
#include <iostream>
#include <string>
using namespace std;
// Gives struct representing player
struct Player
{
   string name;
   bool alive;
   int x_pos = 0;
   int y_pos = 0;
   int dis;

};
// Struct displaying Objects
struct Object
{
   string name;
   bool Exist;
   int e_x_p;
   int e_y_p;

};
class Robot
{
public:
   Robot(int, int, int);
   void WA();

private:
   int x_pos;
   int y_pos;
   int dis;
};
Robot::Robot(int x, int y, int d)
{
   int Pos_X = x;
   int Pos_Y = y;
   int dis = d;
}

void Robot::WA()
{
   Player Robot;
   Robot.alive = true;
   Robot.x_pos = 0;
   Robot.y_pos = 0;
   Robot.dis = 8;
   Object Pit;
   Pit.Exist = true;
   Pit.e_x_p = 1;
   Pit.e_y_p = 3;

   Object Pit2;
   Pit2.Exist = true;
   Pit2.e_x_p = 3;
   Pit2.e_y_p = 1;

   Object Wumpus;
   Wumpus.Exist = true;
   Wumpus.e_x_p = 2;
   Wumpus.e_y_p = 1;
   Object Gold;
   Gold.Exist = true;
   Gold.e_x_p = 3;
   Gold.e_y_p = 3;

   while (Robot.alive = 1)
   {
  
   }

   int input;
   cin >> input;

   switch (input)
   {
   case 119:
   {
       cout << "You Head North." << endl;
       Robot.dis = 119;
       break;
   }
   case 115:
   {
       cout << "You Head South." << endl;
       Robot.dis = 115;
       break;
   }
   case 97:
   {
       cout << "You Head West." << endl;
       Robot.dis = 97;
       break;
   }
   case 100:
   {
       cout << "You Head East." << endl;
       Robot.dis = 100;
       break;
   }
   case 113:
   {
       int arrow = 1;

       if (arrow == 1)
       {
           cout << "You shoot the arrow." << endl;
           arrow = (arrow - 1);
           if (Robot.x_pos == 1)
           {
               if (Robot.y_pos == 1)
               {
                   cout << "You killed the Wumpus" << endl;
                   Wumpus.Exist = false;
               }

           }
           else if (Robot.x_pos == 3)
           {
               if (Robot.y_pos == 0)
               {
                   cout << "You killed the Wumpus" << endl;
                   Wumpus.Exist = false;
               }

           }
           else if (Robot.x_pos == 2)
           {
               if (Robot.y_pos == 3)
               {

                   if (Robot.dis = 8)
                   {
                       cout << "You killed the Wumpus" << endl;
                       Wumpus.Exist = false;
                   }
               }

           }
           else
           {
               cout << "Your arrow misses." << endl;
           }
       }
       else
       {
           cout << "You have no more arrows." << endl;
       }

       break;
   }
   default:
   return Robot::WA();
   }

  


   if (Robot.x_pos == 1)
   {
       if (Robot.y_pos == 3)
       {
           cout << "You Died!" << endl;

       }

   }
   if (Robot.x_pos == 2)
   {
       if (Robot.y_pos == 1)
       {
           cout << "You Died!" << endl;

       }

   }

   if (Robot.x_pos == 3)
   {
       if (Robot.y_pos == 1)
       {
           cout << "You Died!" << endl;

       }

   }
}

#endif WA_H


output


Welcome to:                                                                                                                                                 
Wumpus World!                                                                                                                                               
                                                                                                                                                            
Choose an Option:                                                                                                                                           
1 - Play Wumpus World                                                                                                                                       
2 - Help                                                                                                                                                    
3 - Quit                                                                                                                                                    
1                                                                                                                                                           
sh: cls: command not found                                                                                                                                  
Thanks for playing Wumpus World                                                                                                                             
                                                                                                                                                            
Press r to reset or etc to quit