Using classes for data encapsulation and abstraction
A class is used to organize information into meaningful states and behaviors. In games, we deal with so many different types of weapon, player, enemy, and terrain, each with its own type of state and behavior, so an object-oriented design with classes is a must.
Getting ready
To work through this recipe, you will need a machine running Windows. You need to have a working copy of Visual Studio installed on your Windows machine. No other prerequisites are required.
How to do it…
In this recipe, we will see how easy it is to create a game framework using object-oriented programming in C++:
Open Visual Studio.
Create a new C++ project.
Select Win32 Console Application.
Add source files called
Source.cpp
,CEnemy.h
, andCEnemy.cpp
.Add the following lines of code to
Souce.cpp
:#include "CEnemy.h" #include <iostream> #include <string> #include <conio.h> #include "vld.h" using namespace std; int main() { CEnemy* pEnemy = new CEnemy...