Question
Need the code for this Mario Game instructions below. Code in C++, with as many .h and .cpp files as needed, and also a main.cpp.
Need the code for this "Mario Game" instructions below. Code in C++, with as many .h and .cpp files as needed, and also a main.cpp.
**The World**
The world consists of a number of levels, L, which will be provided at runtime. To finish the game, Mario must navigate from level 1 to level L by defeating intermediate bosses, and defeat the final boss in level L. If Mario runs out of lives before this task is accomplished, the game is lost.
**Mario: Our Protagonist**
In our simulation, Mario starts with a number of lives, V, which will be provided at runtime. Mario also has the ability to collect coins. He starts with 0 coins. For every 20 coins collected, he earns an extra life (and the number of coins resets to 0). At any moment, Mario is in one of 3 power levels, PL0, PL1, and PL2. PL0 is the weakest and PL2 is the strongest. Mario can increase power levels by coming in contact with a mushroom (a magic mushroom), and loses a power level if hurt by an enemy. More on that later.
**A Level**
Each level in our game is represented by a NxN grid (think 2D array), with N provided at runtime. Mario may navigate the grid by moving up, down, left, and right only. The grid wraps horizontally and vertically (a torus). For example, if Mario is in the rightmost column and moves right, he will wrap to the same row in the leftmost column. Every position in the grid can be populated with one of the following: - A coin - A mushroom - A Goomba or a Koopa Troopa - The boss of the level (there must be exactly 1 per level) - Nothing Additionally, every level from 1 to L-1 contains a SINGLE warp pipe somewhere on the grid. Note that the final level does not contain a warp pipe.
**Marios Interaction with the Environment**
Mario will begin at a random location in the first level, with power PL0, and starts interacting with the environment immediately. Once he has interacted with the current location, he moves on to the next location by moving up, down, left, or right. The direction is chosen randomly with uniform probability (25% each). Interactions with each position occur as follows: - If the position contains nothing, Mario moves on. - If the position contains a coin, Mario adds the coin to his wallet, and then the position contains nothing. Mario moves on. - If the position contains a mushroom, Marios power level increases by 1, or stays at PL2 if hes already in PL2. Once the mushroom is consumed, the position contains nothing, and Mario moves on. - If the position contains a Goomba or Koopa, Mario engages per the rules of a regular enemy, below. - If the position contains the level boss, Mario engages per the rules of a boss, below. - If Mario encounters the warp pipe, he will immediately jump to a random position in the next level without having to beat the current level boss.
**Marios Interaction with a Regular Enemy**
When Mario encounters a regular enemy, gameplay proceeds as follows: - If the enemy is a Goomba, Mario defeats the enemy with a 80% probability, the position becomes empty, and Mario moves on. If Mario loses (20% probability), his power level is decreased by 1, the Goomba stays in the position, and Mario moves on. The exception is if Mario loses while at PL0, in which case a life is lost. If Mario has another life, he continues at the same location, with PL0. Otherwise, the simulation ends, and the game is lost. - If the enemy is a Koopa, Mario defeats the enemy with a 65% probability, the position becomes empty, and Mario moves on. If Mario loses (35% probability), his power level is decreased by 1, the Koopa stays in the position, and Mario moves on. The exception is if Mario loses while at PL0, in which case a life is lost. If Mario has another life, he continues at the same location, with PL0. Otherwise, the simulation ends, and the game is lost. - If Mario defeats 7 enemies on the same life, he earns another life.
**Marios Interaction with a Boss**
When Mario encounters a level boss, gameplay proceeds as follows: - Mario defeats the enemy with a 50% probability, the position becomes empty, and Mario moves on to the next level. If Mario is in the last level, the princess is saved, the game is won, and the simulation is over. If Mario loses (50% probability), his power level is decreased by 2, and Mario attempts to defeat the boss again. The exception is if Mario loses while at PL0 or PL1, in which case a life is lost. If Mario has another life, he continues at the same location, with PL0. Otherwise, the simulation ends, and the game is lost. #
**The Program**
Your program will take as command line input the name of a plain text file that has the following format:
Sample input txt.file:
2 5 3 20 20 20 20 20
Line # 1 is the number of levels, L (a positive integer) Line # 2 is the dimension of the grid, N (a positive integer) Line # 3 is the number of initial lives, V (a positive integer) Line # 4 is the approximate percentage of the positions in each level with coins (a positive integer) Line # 5 is the approximate percentage of the positions in each level with nothing (a positive integer) Line # 6 is the approximate percentage of the positions in each level with Goombas (a positive integer) Line # 7 is the approximate percentage of the positions in each level with Koopas (a positive integer) Line # 8 is the approximate percentage of the positions in each level with mushrooms (a positive integer) Note that the values on line 4-8 MUST sum to 100. Once the file is read, a world with the appropriate number of levels is constructed. Each level should be populated using the specifications provided. In addition, a level boss should be placed randomly, as well as a warp pipe (for all but the last level). Mario is placed at a random position in the first level with PL0 and the simulation begins until the game is won or lost. The output of your game is a plain text file that represents a log of every move Mario has made. The name of the log should be provided as a command line argument. The log should start by printing a character representation (see below) of each level, prior to Mario being placed and interacting with the environment. There should be a newline after each level representation.
Sample Log output txt.file:
mcccc gwmxg mxxmx cxmbc cgkgg ========== mcmcm bcmxx ccmcc mxxxk xxxmc ========== Mario is starting in position: (3,4) ========== mcccc gwmxg mxxmx cxmbH cgkgg ========== Level: 0. Mario is at position: (3,4). Mario is at power level 0. Mario collected a coin. Mario has 3 lives left. Mario has 1 coins. Mario will move DOWN. ========== mcccc gwmxg mxxmx cxmbx cgkgH ========== Level: 0. Mario is at position: (4,4). Mario is at power level 0. Mario encountered a goomba and won. Mario has 3 lives left. Mario has 1 coins. Mario will move LEFT. ========== mcccc gwmxg mxxmx cxmbx cgkHx ========== Level: 1. Mario is at position: (4,2). Mario is at power level 2. Mario visited an empty space. Mario has 2 lives left. Mario has 4 coins. Mario will move UP. ========== xcxxx bcmxx ccmcc xxHxx xxxxx ========== Level: 1. Mario is at position: (3,2). Mario is at power level 2. Mario visited an empty space. Mario has 2 lives left. Mario has 4 coins. Mario will move UP. ========== xcxxx bcmxx ccHcc xxxxx xxxxx ========== Level: 1. Mario is at position: (2,2). Mario is at power level 2. Mario ate a mushroom. Mario has 2 lives left. Mario has 4 coins. Mario will move RIGHT. ========== xcxxx bcmxx ccxHc xxxxx xxxxx ========== Level: 1. Mario is at position: (2,3). Mario is at power level 2. Mario collected a coin. Mario has 2 lives left. Mario has 5 coins. Mario will move UP. ========== xcxxx bcmHx ccxxc xxxxx xxxxx ========== Level: 1. Mario is at position: (1,3). Mario is at power level 2. Mario visited an empty space. Mario has 2 lives left. Mario has 5 coins. Mario will move LEFT. ========== xcxxx bcHxx ccxxc xxxxx xxxxx ========== Level: 1. Mario is at position: (1,2). Mario is at power level 2. Mario ate a mushroom. Mario has 2 lives left. Mario has 5 coins. Mario will move LEFT. ========== xcxxx bHxxx ccxxc xxxxx xxxxx ========== Level: 1. Mario is at position: (1,1). Mario is at power level 2. Mario collected a coin. Mario has 2 lives left. Mario has 6 coins. Mario will move LEFT. ========== xcxxx Hxxxx ccxxc xxxxx xxxxx ========== Level: 1. Mario is at position: (1,0). Mario is at power level 2. Mario encountered a boss and won. Mario has 2 lives left. Mario has 6 coins. Mario will stay put. WE BEAT THE GAME! :)
Each subsequent line of the file should specify: - The level number - The position location of Mario (a row and column number) - The current power level of Mario before interacting with the position - The action that was taken at that position - Mario collected a coin - Mario ate a mushroom - Mario fought a Goomba and won/lost - Mario fought a Koopa and won/lost - Mario fought the level boss and won/lost - The position is empty - Mario warped - The number of lives Mario has after interacting with the position - The number of coins Mario has after interacting with the position - The direction that Mario will move next (UP, DOWN, LEFT, RIGHT,STAY PUT) After each line a character array representing the current level should be printed, followed by a newline. The last line of the file should specify whether Mario won or lost the game, and the total number of moves it took to reach that point. # **Data Structure** You shall represent your world (textually) as a 3D LxNxN array of characters. For each of the L levels, each of the NxN grid positions are represented by the following characters: - x - nothing - m - a mushroom - c - a coin - g - a Goomba - k - a Koopa Troopa - b - the level boss - w - a warp pipe - H - stands for hero. Marios current position.
Rules of Engagement
You may NOT use any non-primitive data structures (eg. vectors, lists, etc) other than arrays. Of course, to do the file processing you may use any of the standard C++ IO classes.
For this assignment, you may work in groups of NO MORE THAN TWO. Group members will receive the same grade regardless of individual contributions, so choose wisely.
Develop using VSCode and make sure your code runs correctly with g++ using the course docker container.
Feel free to use whatever textbooks or Internet sites you want to refresh your memory with C++ IO operations, just cite them in a README file turned in with your code. All code you write, of course, must be your own. In your README please be sure to include the g++ command for compiling your code.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started