T-Rex Dinosaur - a replica of the hidden game from Chrome offline mode. Press Space to start the game online and jump your Dino, use down arrow (↓) to duck.
Just an organisational point - do not put implementation code (the function definitions) into header files.
Put your class declaration into the header file, and your code for the function definitions into a .cpp file. When I use my IDE, it automatically puts the class declaration into the header file and I can get it to create function stubs in the .cpp file. Also Dinosaur should be a class of it's own with TRex & other classes inheriting from it. That way a Trex and other dinosaurs can be an objects of their own, rather than being a function inside a dinosaur object. If you do this you can start to take advantage of OOP ideas - like inheritance & polymorphism. Finally, by now I think you should get out of the habit of usingnamespace std; . Either put std:: before each std namespace thing or have using std::cout; as example, for each std thing. I do a mixture - I use the first one for things that appear infrequently, and the second for things that are used all the time.If you can make all these changes - then we will see if you still have problems. HTH - have fun !!!! Dinosaur Game In C++ Code![]()
Dinosaur Game In Dev C Pdf
Inside player() you call TRex(), and TRex() calls player(). You just have loops within loops.
TRex() shouldn't have a loop in it, which means it doesn't need a 'turn'. Also make sure to not call player. Then you get back to the original player(), but the loop doesn't ask for a choice again, so you need to move the start of the while up a little. (to line 50). The loop in player can be while(true), only ending via break when health is too low. But, when the game is over, you call Entrance, which is going to make another game inside the game you are playing. Rather, simply have those conditions break the loop so that the function ends. Then you get back to entrance, and it is done with so the program ends. You could make a loop in entrance that only continues while choice is 'Go'. Make sure to cin >> choice from within the loop, otherwise it can't update. Something that is hiding these errors is that Player and TRex health is a global variable. Consider having the health's within player() and then pass the player's health as a reference variable to TRex. Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2020
Categories |