1. Engineering
  2. Computer Science
  3. a s implement a position module consisting ofah and a...

Question: a s implement a position module consisting ofah and a...

Question details

A. [S%) Implement a Position module consisting ofa.h and a .cpp file. The Position ppe will have the following associated functions Position toPosition (int row, int column): bool areEqual (const Positioni pl, const Positions p2) . bool isValid (const Position&pl) . double calculateDistance (const Position& pl, const Position& p2) 1. 2. 3. Define Position as a record (struct) with row and column fields. Both of these are ints Implement the toPosition function that takes two ints as parameters and retums a Position containing the provided values. Implement the areEqual function that takes two Positions as parameters and returns a bool indicating whether or not they refer to the same position. Two Positions refer to the same position if and only if their row values are equal and their column values are equal. 4. Implement the isvValid function that takes a Position as a parameter and returns a bool indicating whether or not it is inside the level. Use the RONS and COLUMNS constants associated with the Level class. You will need to include Level·h. Implement the calculateDistance function that takes two Positions as parameters and returns a double indicating the Euclidean distance between the two. 5. Suggestion: You may want to copy and modify your calculateDistance function from Assignment 1 o 6. Add documentation to the Position.h file in the same style as in Monster.h and Player.h. See Section 4c of the online notes for further explanation of the B. [1296]Implementa Player module, having the functionality described in the Player .h file, in a file named Player.cpp. As well as the implementations of the functions, the Player.cpp file should also include constants named STARTING HEALTH and DAMAGE with the respective values of 40 and 2. These constants should not be visible from outside the Player.cpp file. . . In the playerInit function, set the players health to STARTING HEALTH, its damage to DAMAGE, and its score and total move cost to 0 The player is dead if and only if its health value is less than or equal to 0 . C. [13%) Implement a Monster module, having lhe functionality described in the Monster. h file, in a file named Monster.cpp MO As well as the implementations of the functions, the Monster.cpp file should also include constants named STARTING HEALTH, DAMAGE, and POINTS with the .
respective values of 20, 3, and 50. These constants should not be visible from outside the Monster.cpp file In the monsterInit function, the Monsters health should be set to STARTING HEALTH, damage to DAMAGE, and points to POINTS. The monster is dead if and only if its health value is less than or equal to 0. The monsters next move should be calculated the same way as in Assignment 1, except that the monster should move towards the players position instead of the target position. The monster is only capable of attacking the player if it would otherwise be capable of moving to the position currently occupied by the player . . . Optionally, you can change the Level module (Leve1.h and Level.cpp) to use the Position type instead of the combination of a row and a column. In this case findMonsterStart and findPlayerStart can be changed to return a Position instead of having a row and a column as pass-by-reference parameters. D. [20%] Modify the mainfunctionfrom Assignment/ 1. Remove the calculateDistance function frommain.cpp (see Assignment I), but keep the one in the Position module. Modify (or replace) the main function from Assignment 1 to be a grid-based combat game with a player and a monster in it. First, the level should be loaded as before. The starting positions of the monster and the player should be determined and stored in position variables. The player and a monster should be declared and initialized using those positions. Then the program should enter a loop until either the player has entered a command or is killed. Inside the loop, the program should display the level, get player input, move the player, and move the monster. When the loop is exited, the program should print some final information and exit. Details are given below 2. The commands are as follows: First CharacterAction Q or N or n S or s E or e exit the 1 move the player one position north move the player one position south move the player one position east move the player one position west wait for the monster to move In more detail, the program should do the following each time through the loop: Print the level, including the player and monster positions. Note: If the monster is dead when the level is to be printed, specify the monsters position as outside the level. This will cause the monster not to be displayed Print the players health, total movement cost so far, and current score. You do NOT have to print the monster information from Assignment I Ask the user for a command and read in the next line of input. of the line as the command. Optionally, if the line is empty (user just pressed ENTER]) or not a valid command, ask the user for another command . Use the first character
If the player entered a qor Q, immediately stop the main loop. You may want to use break or continue If the player waits or attempts to move to an invalid position, no values are updated for the player If the player moves to a valid position that does not contain the monster, the players total movement cost should be increased according to the type of terrain at the destination. If the player attempts to move to the same position as the monster, the monster should lose health equal to the players damage. The player should not be moved and its move cost should not be changed. If the monster is killed, the players score should be increased by the points value of the monster If the monster is not dead, it should make a move. If the monster moves attempts to move to the same position as the player, the player should lose health equal to the monsters damage and the monster should not be moved Note: It is not possible for the player and the monster to pass through each other instead they will both damage the other and not move After the loop exits, the program should display the level, print the players final health total movement cost, and score, and then terminate. Note: If the player or the monster is dead when the final level is to be printed, specify its position as outside the level. This will cause it not to be displayed You may use helper functions to simplify your main function.
Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution