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?

26th Nov 2018, 2:06 AM
Shaan Graal Cariño Dayag
Shaan Graal Cariño Dayag - avatar
2 Answers
+ 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.
26th Nov 2018, 3:38 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 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.
29th Nov 2018, 2:16 AM
Potato Hacker
Potato Hacker - avatar