Creating a simple text-based game is really easy. All we need to do is to create some rules and logic and we will have ourselves a game. Of course, as the game gets more complex we need to add more functions. When the game reaches a point where there are multiple behaviors and states of objects and enemies, we should use classes and inheritance to achieve the desired result.
To work through this recipe, you will need a machine running Windows. You also need to have a working copy of Visual Studio installed on your Windows machine. No other prerequisites are required.
In this recipe, we will learn how to create a simple luck-based lottery game:
Open Visual Studio.
Create a new C++ project.
Select Win32 Console Application.
Add a
Source.cpp
file.Add the following lines of code to it:
#include <iostream> #include <cstdlib> #include <ctime> int main(void) { srand(time(NULL)); // To not have the same numbers over and over...