Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ HELP WITH MANHUNT!! Your assignment is to develop a manhunt simulator. The manhunt simulator will have two people. The investigator who will be demarked

C++ HELP WITH MANHUNT!!

Your assignment is to develop a manhunt simulator. The manhunt simulator will have two people. The investigator who will be demarked with an I and a target who will be demarked with a T. The target will not be directly visible on the map though.

The application should:

1. Have a starting menu that asks if the user wants to:

a.Load data from a text file

b.Ask the user for details of the investigator and the target. The information for each will include their starting point using an X and Y coordinate system.

2. Have a main menu that asks the user if they want to:

a.Search North

b.Search East

c.Search South

d.Search West

e.Exit

3. The four symbols on the map are: I = Investigator, T = Target, _ = Unsearched Area, and * = Searched Area.

4. You can only search in the four cardinal areas (north, south, east, west) there is no nw, ne, sw, se. It will indicate east/west first then north/south. For example, if the target is north-west of the target, it will tell the investigator to search west first. Then if the investigator is west enough, it will indicate north/south.

5. As part of the search, if the target is not found, it should indicate which direction should continue searching.

6. If the user finds the target, it should indicate that the target was found and exit the program.

7. The map will always have a width of 10 and a height of 10. (no magic numbers!). Additionally, the map must be stored in an array (it is up to you how many dimensions one or more).

8. If the user tries to exit the search area, the program should indicate that search is not allowed and re-prompt the user.

9. The program exits after the target is found.

1. Requirements:

This is a list of the requirements of this application. For this project, it is up to you exactly how you want to implement it. In order for you to earn all of the points, however, you will need to meet all of the defined requirements.

Notice the trailing period is required (it says copy it into this folder).

You must follow the coding standard as defined in the CMSC 202 coding standard (found on Blackboard under course materials). This includes comments as required.

The project must be completed in C++. You may not use any libraries or data structures that we have not learned in class. Libraries we have learned include , , , , , and . You should only use namespace std.

You must use a variety of functions including passing parameters to those functions and returning information from those functions. At least one time, an array must be passed to a function.

Each menu must be implemented with a switch statement.

All user input must be validated. For example, if a menu allows for 1, 2, or 3 to be entered and the user enters a 4, it will re-prompt the user. However, the user is expected to always enter the correct data type. i.e. If the user is asked to enter an integer, they will. If they are asked to enter a character, they will. You do not need to worry about checking for correct data types.

The name of the input file is entered by the user. The input file name is not validated at all. The input file will always be in the same folder as the project file.

2. Recommendations

You are free to implement this with your own functions. While not required, these are some functions that you may want to include:

Start Menu (including validated user input) Welcomes the user to the application and has the user choose between loading the map from a file, entering a new map, or exit. It must validate the choice to be between 1 and 3.

Main Menu (including user input) Once the map is completed or loaded, this menu allows users to search in a particular direction or exit. It must validate the choice to be between 1 and 6.

Load Map Uses file input to load in the text file. The file will always be named test1.txt. The text file will have exactly four inputs. One on each line. They are integers representing the X axis of the investigator, the Y axis of the investigator, the X axis of the target, and the Y axis of the target.

New Map Allows the user to enter the X and Y coordinates of the starting investigator and the X and Y coordinates of the target. Fills the rest with underscores.

Print Map Outputs the entire map including where the investigator currently is. Spaces that are unsearched are an underscore(_), the investigator is an I, and the target is demarked by a T but is not visible in the print map the target is hidden!

Check Search Checks the entire map to make sure that the direction that the user wants to search is legal and is not the target. *This is one of the trickier functions/sets of functions*

The board will be a constant 10 by 10. The test1.txt will be 4 numbers regarding the x and y coordinates of the target and investigator.

This is what the board is supposed to look like with the I as investigator and the target hidden.

Try Searching North

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ I * * * * _ _ _ _

_ _ _ _ _ * _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

_ _ _ _ _ _ _ _ _ _

What would you like to do?

1. Search North

2. Search East

3. Search South

4. Search West

5. See Map

6. Exit

Enter 1-6:

My Code:

#include

#include #include #include #include

using namespace std ;

const int ROWS = 10 ; const int COLS = 10 ;

int Start_Menu(string file_name, char array[ROWS][COLS]) ; char Main_Menu(int num, char array[ROWS][COLS]) ; void Print_Board(char board[ROWS][COLS]) ; int *Load_Map(string f_string, char array[ROWS][COLS]) ; double New_Map(char board[ROWS][COLS]) ;

int main() {

char board[ROWS][COLS] ; int num = 0 ; string file_name ;

Start_Menu(file_name, board) ;

board = Main_Menu(num, board) ;

Load_Map(file_name, board) ;

Print_Board(board) ;

New_Map(board) ;

}

char Main_Menu(int num, char board[ROWS][COLS]) {

int i ; int j ; int user_choice = 0 ; int coords[4]; int xI_coordinate ; int yI_coordinate ; int xT_coordinate ; int yT_coordinate ; string file_name ; char array[ROWS][COLS] ;

cout << "What would you like to do? " << endl ; cout << "1) Load simulation from file? " << endl ; cout << "2) Start a new simulation. " << endl ; cout << "3) Exit. " << endl ; cout << "Enter 1-3 " << endl ;

cin >> user_choice ; switch(user_choice) { case 1:

coords = Load_Map(file_name, array) ;

break ;

case 2:

coords = New_Map(array) ;

break ;

case 3:

cout << "Exiting Game mode! " << endl ;

break ;

default: cout << "Please enter a number between 1-3. " << endl ; // Checks validity of user_choice.

break ;

} return 0 ;

//Handle movements and changing of the board in Main_Menu //Send new board to print_board every time while((board[i][j] != board[2][3]) || (board[i][j] == '6')) { // This while loop processes user choice unless promted to exit or the target has been found.

cout << "1) Search North " << endl ; cout << "2) Search East " << endl ; cout << "3) Search South " << endl ; cout << "4) Search West " << endl ; cout << "5) See Map " << endl ; cout << "6) Exit " << endl ; cout << "Enter 1-6: " << endl ;

cin >> user_choice ; // takes in user input.

}

switch(user_choice) { // This group of swith statements process the direction of the Investigator towards the target. case 1:

for(int i = 0 ; i < ROWS ; i++) { // Case one is if the user promts the program to search north. If the target is found it exits if not I moves up one position. for(int j = 0 ; j < COLS ; j++) { if((board[i][j] == board[2][3]) || (board[i][j] == board[xT_coordinate][yT_coordinate])) { // Checks to see if target has been found. break ; } else if((board[i][j] == board[0][1]) || (board[i][j] == board[xI_coordinate][yI_coordinate])) { // Checks the position of Investigator. board[i][j+1] = board[i][j] ; // Moves Invesitgator one position up. board[i][j] = '*' ; // Changes previous position of investigator to *.

} } }

case 2:

for(int i = 0 ; i < ROWS ; i++) { // Case two promts the program to serach east. If target is found program exits. If not I moves to the right one position. for(int j = 0 ; j < COLS ; j++) { if((board[i][j] == board[i][j] || board[i][j] == board[xT_coordinate][yT_coordinate])) { // Checks to see if target has been found. break ; } else if((board[i][j] == board[0][1]) || (board[i][j] == board[xI_coordinate][yI_coordinate])) { // Checks for position of I. board[i+1][j] = board[i][j] ; // Moves investigator one position up. board[i][j] = '*' ; // Changes previous position of I to a *. } } }

case 3:

for(int i = 0 ; i < ROWS ; i++) { // Case three promts the program to search south. If target is found program exits. If not I moves down one position. for(int j = 0 ; j < COLS ; j++) { if((board[i][j] == board[2][3]) || (board[i][j] == board[xT_coordinate][yT_coordinate])) { // Checks to see if target is found. break ; } else if((board[i][j] == board[0][1]) || (board[i][j] == board[xT_coordinate][yT_coordinate] )) { // Checks to see if position is the investigator. board[i][j-1] = board[i][j] ; // Moves position of investigator one position down. board[i][j] = '*' ; // Replaces previous position of I with a *.

} } }

case 4:

for(int i = 0 ; i < ROWS ; i++) { // Case four promts the program to search west. If target is found program exits. If not I moves left one position. for(int j = 0 ; j < COLS ; j++) { if((board[i-1][j] == board[2][3]) || (board[i][j] == board[xT_coordinate][yT_coordinate] )) { // Checks to see if target is found. break ; } else if((board[i][j] == board[0][1]) || (board[i][j] == board[xI_coordinate][yI_coordinate])) { // Checks the position of I. board[i-1][j] = board[i][j] ; // Moves I one space to the left. board[i][j] = '*' ; // Replaces previous positions I with a *.

} } }

case 5:

Print_Board(board) ; // Prints board when promted by user.

break ;

case 6:

cout << "Exiting Game Mode" << endl ; // exits game mode if promted by user.

break ;

default:

cout << "Enter a valid number between 1 and 6 please " << endl ; // Checks validity of user input.

break ; } return 0 ; }

int *Load_Map(string f_string, char board[ROWS][COLS]) {

ifstream test1 ; // Creates file stream for test1.txt. string file_name ; int i, j ; char array[i][j] ; int count = 0 ; int coord[4] ;

cout << "What is the name of the file? " << endl ; // Prompts user for file name. cin >> file_name ; // Reads in file name. test1.open (file_name.c_str() ) ; // Opens test file.

while ( test1.good() ) { // This while loop uses a counter to process through each of the coordinates. coord[count] = getline(test1, count) ; // initialazation of the variable coord. count += 1 ; }

array[coord[0]][coord[1]] = 'I'; // Initializes postion of Inspector on the game board. array[coord[2]][coord[3]] = ' '; // Initializes postion of Target on the board.

test1.close() ; // Closes the file.

return 0 ; }

double New_Map(char board[ROWS][COLS]) { int i = 0 ; int j = 0 ; char array[i][j] ; // The four integers are each of the coordinates for the target and investigator being initialized. int xI_coordinate = 0 ; int yI_coordinate = 0 ; int xT_coordinate = 0 ; int yT_coordinate = 0 ;

cout << "What is the X axis of the investigator?: " << endl ; // Promts user for X coord of I.

cin >> xI_coordinate ; // Reads in X coord for I.

cout << "What is the Y axis of the investigator?: " << endl ; // Promts user for Y coord of I.

cin >> yI_coordinate ; // Reads in Y coord for I.

cout << "What is the X axis of the target?: " << endl ; // Promts user for X coord of T.

cin >> xT_coordinate ; // Reads in X coord for T.

cout << "What is the Y axis of the target?: " << endl ; // Promts user for Y coord of T.

cin >> yT_coordinate ; // Reads in Y coord for T.

for(int i = 0 ; i < ROWS ; i++) { // The nested for loops check the board to find the positions of the target and investigator. for(int j = 0 ; j < COLS ; j++) { if (array[xI_coordinate][yI_coordinate] == array[i][j]) { return array[xI_coordinate][yI_coordinate] ; } else if(array[xT_coordinate][yT_coordinate] == array[i][j]) { return array[xT_coordinate][yT_coordinate] ; } else if(array[i][j] == array[i][j]) { array[i][j] = '_' ; return array[i][j] ; } } } }

void Print_Map(char board[ROWS][COLS]) {

const int ROWS = 10 ; const int COLS = 10 ;

// char board[ROWS][COLS] = {0, 0} ;

for(int i = 0 ; i < ROWS ; i++) { cout << " " ; for(int j = 0 ; j < COLS ; j++) { if(board[i][j] == 0) { cout << "_" ; } else { cout << "_" ; } cout << " " ; } } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago