What is the best way to make a text-based game using C++? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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 Respostas
+ 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
Kinshuk Vasisht
Kinshuk Vasisht - 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