Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PROGRAM REQUIREMENTS: You must organize your program into three files: cuidHW4func.h This file will contain the include directives for the necessary libraries, any type definitions,

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

PROGRAM REQUIREMENTS: You must organize your program into three files: cuidHW4func.h This file will contain the include directives for the necessary libraries, any type definitions, any structure definitions, and the list of function prototypes (i.e. function declarations). euid HW4main.cpp This file will contain the local include directive for the header file as well as the main function for the program. cuidHW4func.cpp This file will contain the local include directive for the header file as well as all function definitions (except the main) used in the program. Be sure to replace euid with your EUID . Be sure to submit all three files when submitting your assignment. As with all homework programs in this course, your program's output will initially display the department and course number, your name, your EUID, and your email address. This output should be performed through a function you declare and define. Define an enumerated type, and its constants, that stores each of the possible types of tiles in the room (B for box, A for avatar, X for wall, H for home location, and Space for empty spots) Define a structure (i.e. struct) to represent a tile in the room. It should store a variable of your enumerated type to keep track of the tile type, and a Boolean to keep track of whether that tile is on a home location. You will need to declare and define a function, that takes in a dynamic, 2-dimensional array and its size and returns nothing to process the player specified file by: Prompting the player for a file name. If the file does not exist, let the user know this and reprompt until a correct file name is submitted. . Reading from the file and correctly storing all of the characters in their appropriate locations. (Hint: a switch might be effective here) The file will be comma delimited You will need to declare and define a function that takes in a dynamic, 2-dimensional array and its size, and outputs the value of every slot in a grid format. You will need to declare and define a function that takes in a dynamic, 2-dimensional array and its size, and returns a bool indicating whether the game is over. The game is over once every box is in a home location. You will need to declare and define a function, that takes in a dynamic, 2-dimensional array, its size, the x coordinate of the avatar's current location, the y coordinate of the avatar's current location, and the number of moves that have been made and returns a bool indicating if the player has decided to quit the game, to process the player's moves by: Prompting the player for which direction they want to move their avatar (Up, Down, Left, or Right) or if they wish to quit and forfeit the game If the player does not choose one of these five options, they should be reprompted until they choose one of the five options . If the player chooses to quit the game the function immediately return an appropriate Boolean value and an appropriate message should be provided by the game Based on the player's choice of direction, calling the appropriate function to attempt to move the avatar Up, Down, Left, or Right . If the avatar successfully moves, increment the number of moves made . If the avatar does not move due to being blocked by a wall or boxes, do not increment the number of moves made If the user did not quit the game, the function should return an appropriate Boolean value You will need to declare and define four functions (one for each direction, that take in a dynamic, 2- dimensional array, its size, the x coordinate of the avatar's current location, the y coordinate of the avatar's current location, and returns a bool indicating if the avatar was able to be moved, to attempt to move the avatar The avatar can move into a new location if that location is empty The avatar can move into a new location if the location contains a box and the location one tile away in the same direction from the box is empty xxxxxxxxxxxxx . The avatar cannot move into a new location if that location is a wall The avatar cannot move into a new location if that location is outside out of the room The avatar cannot move into a new location if the location contains a box and the location one tile away in the same direction from the box is not empty (i.e. contains a box, is a wall, is outside of the board) XXXXXXXXXXXXX . If the avatar successfully moved the function should update the avatar's location on the room, update their x and y coordinates, and the function should return an appropriate Boolean value If the avatar did not successfully move the function should output an appropriate message and return an appropriate Boolean value Any time a box or the avatar move on to a home tile, their character should appear in the home tile location, and the bool in the struct should be updated to keep track of the home tile's location Once a box is in a home location, it cannot be moved again. Any time the avatar moves off of a home tile, the home tile character should appear in the home tile location Inside your main function you will need to: Declare and dynamically allocate the correct amount of space for a 15x15, two-dimensional, dynamic array of structs representing the room. Create an integer to keep track of the number of moves made, and initialize it to O Create two integers to keep track of the avatar's x and y coordinates: Using the appropriate function, setup the game by reading in the file, storing the locations of all of the characters, and storing the avatar's initial x and y location Output an appropriate introduction, the rules of the game (See the SAMPLE OUTPUT), and the initial state of the room While the game has not ended due to the player winning or forfeiting the game, using the appropriate function repeatedly allow the player to attempt to move the avatar around the room and output the state of the room after each move If the player wins the game, then an appropriate message should be output and the game should end You should not create or use any globally defined variables or macros, though your struct should be globally defined You should not use goto statements. Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code. This means, that in addition to the program printing your information to the terminal, it will also appear in the code in the comments as well. BONUS OPPORTUNITY: Up to 15 Points For students who have completed all requirements for this program, for 5 bonus points, students should implement a reset feature in the game should the player make a mistake and not be able to win. The reset option should be given to the player along with the move direction and quit options, and if they choose to reset the game, the game should revert back to its starting configuration. For 10 bonus points, students should implement the ability to save and load the game, should the user need to pause their playing of it. When saving, the state of the room should be written to a file that has a different name than the initial input file, and the data should be in the same format as the initial input file. When loading, the state of the room should be overwritten with the contents of the saved file. The save and load options should be given to the player along with the move direction and quit options. DESIGN (ALGORITHM): On a piece of paper (or word processor), write down the algorithm, or sequence of steps, that you will use to solve the problem. You may think of this as a "recipe for someone else to follow. Continue to refine your "recipe until it is clear and deterministically solves the problem. Be sure to include the steps for prompting for input, performing calculations, and displaying output. You should attempt to solve the problem by hand first (using a calculator as needed) to work out what the answer should be for a few sets of inputs. Type these steps and calculations into a document i.e., Word, text, or PDF) that will be submitted along with your source code. Note that if you do any work by hand, images (such as pictures) may be used, but they must be clear and easily readable. This document shall contain both the algorithm and any supporting hand calculations you used in verifying your results. TESTING: Test your program to check that it operates as desired with a variety of inputs. Then, compare the answers your code gives with the ones you get from hand calculations. SUBMISSION: Your program will be graded based largely upon whether it works correctly on the CSE machines, so you should make sure your program compiles and runs on the CSE machines. Your program will also be graded based upon your program style. This means that you should use comments (as directed), meaningful variable names, and a consistent indentation style as recommended in the textbook and in class. We will be using an electronic homework submission on Canvas to make sure that all students hand their programming projects on time. You will submit both (1) the program source code file and (2) the algorithm design document to the Homework 4 dropbox on Canvas by the due date and time. Homeworks are meant to be problem-solving exercises and are designed to help you practice your coding on larger projects with various pieces of functionality. While the coding should be primarily your sole work, you are allowed to get assistance from classmates when working on these assignments. However, each student is required to report the name(s) of the students they worked with on the assignment. All students who are part of a group working on the assignment will receive the same grade. Cheating for these assignments is now defined as copying from a fellow student without reporting it or copying from the web. You should not copy someone else's code or let a classmate examine your code if you have not identified as working in a group for your homework As a safety precaution, do not edit your program (using vim or nano) after you have submitted your program where you might accidentally re-save the program, causing the timestamp on your file to be later than the due date. If you want to look for work on it) after submitting, make a copy of your submission and work off of that copy. Should there be any issues with your submission, this timestamp on your code on the CSE machines will be used to validate when the program was completed. SAMPLE OUTPUT: Here is a sample output to help you write and test your code. The item in bold is the information entered by the user. $ ./a.out Computer Science and Engineering CSCE 1e3e - Computer Science I Student Name EUID euiday.unt.edu Please enter the name of the room file:room.txt Welcome to Mr. Mover! The goal is to push each of the boxes (represented by B's) into a hone location (represented by H's). Mr. Mover is represented by an A, and you can move Up(u), Down(D), Left(L), and Right(R). Once a box is in a home location, it cannot be moved again so be careful about how your push the boxes. Good luck! XXXXXXXXXXXXX X HB xxx xxxxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, X X X X X X X X X X X X X X X for Quit:U Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:U XXXXXXXXXXXXXXX Please enter direction to move: U for Up, D for Down, L for Left, R for Right, X X X X X X X X X X X X X X X for Quit:U X X X X X X X X X X X X X X X Please enter direction to move: U for Up, D for Down, L for Left, R for Right. Q for Quit:U X X X X X X X X X X X X X X X Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:U I cannot move up right now! xxxxxxxx xxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:D xxxxxxxxx xxxxxx xxxxxxxxxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:L xxxxxxxxx xxxxxx Please enter direction to move: U for up, D for Down, L for Left, R for Right, Q for Quit:L XXXXXXXXXXXXXXX Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:L XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX Congratulations! You won in 8 moves. PROGRAM REQUIREMENTS: You must organize your program into three files: cuidHW4func.h This file will contain the include directives for the necessary libraries, any type definitions, any structure definitions, and the list of function prototypes (i.e. function declarations). euid HW4main.cpp This file will contain the local include directive for the header file as well as the main function for the program. cuidHW4func.cpp This file will contain the local include directive for the header file as well as all function definitions (except the main) used in the program. Be sure to replace euid with your EUID . Be sure to submit all three files when submitting your assignment. As with all homework programs in this course, your program's output will initially display the department and course number, your name, your EUID, and your email address. This output should be performed through a function you declare and define. Define an enumerated type, and its constants, that stores each of the possible types of tiles in the room (B for box, A for avatar, X for wall, H for home location, and Space for empty spots) Define a structure (i.e. struct) to represent a tile in the room. It should store a variable of your enumerated type to keep track of the tile type, and a Boolean to keep track of whether that tile is on a home location. You will need to declare and define a function, that takes in a dynamic, 2-dimensional array and its size and returns nothing to process the player specified file by: Prompting the player for a file name. If the file does not exist, let the user know this and reprompt until a correct file name is submitted. . Reading from the file and correctly storing all of the characters in their appropriate locations. (Hint: a switch might be effective here) The file will be comma delimited You will need to declare and define a function that takes in a dynamic, 2-dimensional array and its size, and outputs the value of every slot in a grid format. You will need to declare and define a function that takes in a dynamic, 2-dimensional array and its size, and returns a bool indicating whether the game is over. The game is over once every box is in a home location. You will need to declare and define a function, that takes in a dynamic, 2-dimensional array, its size, the x coordinate of the avatar's current location, the y coordinate of the avatar's current location, and the number of moves that have been made and returns a bool indicating if the player has decided to quit the game, to process the player's moves by: Prompting the player for which direction they want to move their avatar (Up, Down, Left, or Right) or if they wish to quit and forfeit the game If the player does not choose one of these five options, they should be reprompted until they choose one of the five options . If the player chooses to quit the game the function immediately return an appropriate Boolean value and an appropriate message should be provided by the game Based on the player's choice of direction, calling the appropriate function to attempt to move the avatar Up, Down, Left, or Right . If the avatar successfully moves, increment the number of moves made . If the avatar does not move due to being blocked by a wall or boxes, do not increment the number of moves made If the user did not quit the game, the function should return an appropriate Boolean value You will need to declare and define four functions (one for each direction, that take in a dynamic, 2- dimensional array, its size, the x coordinate of the avatar's current location, the y coordinate of the avatar's current location, and returns a bool indicating if the avatar was able to be moved, to attempt to move the avatar The avatar can move into a new location if that location is empty The avatar can move into a new location if the location contains a box and the location one tile away in the same direction from the box is empty xxxxxxxxxxxxx . The avatar cannot move into a new location if that location is a wall The avatar cannot move into a new location if that location is outside out of the room The avatar cannot move into a new location if the location contains a box and the location one tile away in the same direction from the box is not empty (i.e. contains a box, is a wall, is outside of the board) XXXXXXXXXXXXX . If the avatar successfully moved the function should update the avatar's location on the room, update their x and y coordinates, and the function should return an appropriate Boolean value If the avatar did not successfully move the function should output an appropriate message and return an appropriate Boolean value Any time a box or the avatar move on to a home tile, their character should appear in the home tile location, and the bool in the struct should be updated to keep track of the home tile's location Once a box is in a home location, it cannot be moved again. Any time the avatar moves off of a home tile, the home tile character should appear in the home tile location Inside your main function you will need to: Declare and dynamically allocate the correct amount of space for a 15x15, two-dimensional, dynamic array of structs representing the room. Create an integer to keep track of the number of moves made, and initialize it to O Create two integers to keep track of the avatar's x and y coordinates: Using the appropriate function, setup the game by reading in the file, storing the locations of all of the characters, and storing the avatar's initial x and y location Output an appropriate introduction, the rules of the game (See the SAMPLE OUTPUT), and the initial state of the room While the game has not ended due to the player winning or forfeiting the game, using the appropriate function repeatedly allow the player to attempt to move the avatar around the room and output the state of the room after each move If the player wins the game, then an appropriate message should be output and the game should end You should not create or use any globally defined variables or macros, though your struct should be globally defined You should not use goto statements. Your code should be well documented in terms of comments. For example, good comments in general consist of a header (with your name, course section, date, and brief description), comments for each variable, and commented blocks of code. This means, that in addition to the program printing your information to the terminal, it will also appear in the code in the comments as well. BONUS OPPORTUNITY: Up to 15 Points For students who have completed all requirements for this program, for 5 bonus points, students should implement a reset feature in the game should the player make a mistake and not be able to win. The reset option should be given to the player along with the move direction and quit options, and if they choose to reset the game, the game should revert back to its starting configuration. For 10 bonus points, students should implement the ability to save and load the game, should the user need to pause their playing of it. When saving, the state of the room should be written to a file that has a different name than the initial input file, and the data should be in the same format as the initial input file. When loading, the state of the room should be overwritten with the contents of the saved file. The save and load options should be given to the player along with the move direction and quit options. DESIGN (ALGORITHM): On a piece of paper (or word processor), write down the algorithm, or sequence of steps, that you will use to solve the problem. You may think of this as a "recipe for someone else to follow. Continue to refine your "recipe until it is clear and deterministically solves the problem. Be sure to include the steps for prompting for input, performing calculations, and displaying output. You should attempt to solve the problem by hand first (using a calculator as needed) to work out what the answer should be for a few sets of inputs. Type these steps and calculations into a document i.e., Word, text, or PDF) that will be submitted along with your source code. Note that if you do any work by hand, images (such as pictures) may be used, but they must be clear and easily readable. This document shall contain both the algorithm and any supporting hand calculations you used in verifying your results. TESTING: Test your program to check that it operates as desired with a variety of inputs. Then, compare the answers your code gives with the ones you get from hand calculations. SUBMISSION: Your program will be graded based largely upon whether it works correctly on the CSE machines, so you should make sure your program compiles and runs on the CSE machines. Your program will also be graded based upon your program style. This means that you should use comments (as directed), meaningful variable names, and a consistent indentation style as recommended in the textbook and in class. We will be using an electronic homework submission on Canvas to make sure that all students hand their programming projects on time. You will submit both (1) the program source code file and (2) the algorithm design document to the Homework 4 dropbox on Canvas by the due date and time. Homeworks are meant to be problem-solving exercises and are designed to help you practice your coding on larger projects with various pieces of functionality. While the coding should be primarily your sole work, you are allowed to get assistance from classmates when working on these assignments. However, each student is required to report the name(s) of the students they worked with on the assignment. All students who are part of a group working on the assignment will receive the same grade. Cheating for these assignments is now defined as copying from a fellow student without reporting it or copying from the web. You should not copy someone else's code or let a classmate examine your code if you have not identified as working in a group for your homework As a safety precaution, do not edit your program (using vim or nano) after you have submitted your program where you might accidentally re-save the program, causing the timestamp on your file to be later than the due date. If you want to look for work on it) after submitting, make a copy of your submission and work off of that copy. Should there be any issues with your submission, this timestamp on your code on the CSE machines will be used to validate when the program was completed. SAMPLE OUTPUT: Here is a sample output to help you write and test your code. The item in bold is the information entered by the user. $ ./a.out Computer Science and Engineering CSCE 1e3e - Computer Science I Student Name EUID euiday.unt.edu Please enter the name of the room file:room.txt Welcome to Mr. Mover! The goal is to push each of the boxes (represented by B's) into a hone location (represented by H's). Mr. Mover is represented by an A, and you can move Up(u), Down(D), Left(L), and Right(R). Once a box is in a home location, it cannot be moved again so be careful about how your push the boxes. Good luck! XXXXXXXXXXXXX X HB xxx xxxxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, X X X X X X X X X X X X X X X for Quit:U Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:U XXXXXXXXXXXXXXX Please enter direction to move: U for Up, D for Down, L for Left, R for Right, X X X X X X X X X X X X X X X for Quit:U X X X X X X X X X X X X X X X Please enter direction to move: U for Up, D for Down, L for Left, R for Right. Q for Quit:U X X X X X X X X X X X X X X X Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:U I cannot move up right now! xxxxxxxx xxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:D xxxxxxxxx xxxxxx xxxxxxxxxxxxx Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:L xxxxxxxxx xxxxxx Please enter direction to move: U for up, D for Down, L for Left, R for Right, Q for Quit:L XXXXXXXXXXXXXXX Please enter direction to move: U for Up, D for Down, L for Left, R for Right, Q for Quit:L XXXXXXXXXXXXXXX XXXXXXXXXXXXXXX Congratulations! You won in 8 moves

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

Step: 3

blur-text-image

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Auditing And Assurance Services

Authors: Timothy Louwers, Penelope Bagley, Allen Blay, Jerry Strawser, Jay Thibodeau

9th Edition

1266796851, 9781266796852

More Books

Students also viewed these Accounting questions

Question

Describe strategic succession planning in todays environment.

Answered: 1 week ago

Question

Explain the various elements of a diverse workforce.

Answered: 1 week ago

Question

Describe the strategic planning process.

Answered: 1 week ago