0
What is the best way to make a text-based game using C++?
Hi! I am a beginner in using C++, and I intend to make a text-based game that does certain actions when the player inputs commands. What is the best way to do this?
2 odpowiedzi
+ 2
The logic is conditional, so you can design a class and implement the stats and actions using members and methods (member functions), and then execute the actions using ifs calling a particular method.
Then, in main, you initialize your player with the required attributes, and run a loop. In the loop, you simply request an input and execute commands based on that. You can also provide an option to exit anytime, or exit the game when a particular condition is satisfied (health == 0, etc.)
You can later add up more features and variants using derived classes and polymorphism.
There are several users who have created excellent text based games here on SoloLearn. You can search those games in the code section for hints and improvements.
+ 1
OOP, and Logical syntax will make you a basic Text based game,
Else if u wanna do a real game, like fortnite, U might need some UE4.
Conditionals are a basic thing to, Randomness is fun to play with in text based games,
you need your functions to function into your code.
functions will help u if like “if text is “Hello, world!” then u might need a function that will return Hello, world.