Ở bước này, ta tao 2 file CFifteenPuzzle.h và CFifteenPuzzle.cpp chứa nội dung lớp CFifteenPuzzle. Lưu ý:
Lớp CFifteenPuzzle sẽ thừa kế từ CGame.
CFifteenPuzzle.h
#ifndef _CFIFTEENPUZZLE_
#define _CFIFTEENPUZZLE_
#include "gametutor.h"
class CFifteenPuzzle:public CGame
{
public:
CFifteenPuzzle();
~CFifteenPuzzle();
bool OnControllerEvent(SControllerEvent Event);
protected:
void Init();
void Destroy();
};
#endif
CFifteenPuzzle.cpp
#include "CFifteenPuzzle.h"
CFifteenPuzzle::CFifteenPuzzle():CGame() {}
CFifteenPuzzle::~CFifteenPuzzle() {}
bool CFifteenPuzzle::OnControllerEvent(SControllerEvent Event)
{
return false; //pass event to state if any
}
void CFifteenPuzzle::Init()
{
Log("Init");
}
void CFifteenPuzzle::Destroy()
{
Log("Destroy");
}
Trong main.h, sửa lại giá trị cnf để khởi động game với lớp CFifteenPuzzle:
main.h
#include "gametutor.h"
#include "CFifteenPuzzle.h"
int main()
{
SGameConfig cnf = {
800,
600,
false,
"Fifteen Puzzle",
CGLPipelineDriver::GetInstance(),
CALAudioDriver::GetInstance(),
new CFifteenPuzzle(),
};
GameTutor::StartApp(cnf);
GameTutor::FinalizeApp();
}
Tiến hành build và run, kết quả hiện ra màn hình là một cửa sổ trắng: