?? game.h
字號:
#ifndef CLASS_GAME
#define CLASS_GAME
#ifndef _LIST_
#include <list>
using std::list;
#endif
#include "Messages.h"
class CTable;
typedef struct _tagStep {
int x;
int y;
int color;
} STEP;
// 游戲基類
class CGame
{
protected:
CTable *m_pTable;
public:
// 落子步驟
list< STEP > m_StepList;
public:
// 構造函數
CGame( CTable *pTable ) : m_pTable( pTable ) {}
// 析構函數
virtual ~CGame();
// 初始化工作,不同的游戲方式初始化也不一樣
virtual void Init() = 0;
// 處理勝利后的情況,CTwoGame需要改寫此函數完成善后工作
virtual void Win( const STEP& stepSend );
// 發送己方落子
virtual void SendStep( const STEP& stepSend ) = 0;
// 接收對方消息
virtual void ReceiveMsg( MSGSTRUCT *pMsg ) = 0;
// 發送悔棋請求
virtual void Back() = 0;
};
// 一人游戲派生類
class COneGame : public CGame
{
bool m_Computer[15][15][572]; // 電腦獲勝組合
bool m_Player[15][15][572]; // 玩家獲勝組合
int m_Win[2][572]; // 各個獲勝組合中填入的棋子數
bool m_bStart; // 游戲是否剛剛開始
STEP m_step; // 保存落子結果
// 以下三個成員做悔棋之用
bool m_bOldPlayer[572];
bool m_bOldComputer[572];
int m_nOldWin[2][572];
public:
COneGame( CTable *pTable ) : CGame( pTable ) {}
virtual ~COneGame();
virtual void Init();
virtual void SendStep( const STEP& stepSend );
virtual void ReceiveMsg( MSGSTRUCT *pMsg );
virtual void Back();
private:
// 給出下了一個子后的分數
int GiveScore( const STEP& stepPut );
void GetTable( int tempTable[][15], int nowTable[][15] );
bool SearchBlank( int &i, int &j, int nowTable[][15] );
};
// 二人游戲派生類
class CTwoGame : public CGame
{
public:
CTwoGame( CTable *pTable ) : CGame( pTable ) {}
virtual ~CTwoGame();
virtual void Init();
virtual void Win( const STEP& stepSend );
virtual void SendStep( const STEP& stepSend );
virtual void ReceiveMsg( MSGSTRUCT *pMsg );
virtual void Back();
};
#endif // CLASS_GAME
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -