www.pudn.com > HGE_game_damo.rar > TetrisLogic.h


////  http://dotlive.cnblogs.com/  
// TetrisLogic.h: interface for the TetrisLogic class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#if !defined(AFX_TETRISLOGIC_H__71D2CBE5_C7D5_4DEA_987D_6C23218131E1__INCLUDED_) 
#define AFX_TETRISLOGIC_H__71D2CBE5_C7D5_4DEA_987D_6C23218131E1__INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
#include "windows.h" 
#include "GameLogic.h" 
 
enum TerisBoxType{ 
	TerisBoxType1, 
	TerisBoxType2, 
	TerisBoxType3, 
	TerisBoxType4, 
	TerisBoxType5, 
	TerisBoxType6, 
	TerisBoxType7, 
	TerisBoxType8, 
}; 
 
struct TetrisBox  
{ 
	POINT m_ptPosition; 
	INT m_nState; 
	INT m_nBoxID; 
	TetrisBox(){ 
		memset(this,0,sizeof(TetrisBox)); 
// 		m_nBoxID = 0; 
// 		m_nState = 0; 
// 		m_ptPosition.x = 0; 
// 		m_ptPosition.y = 0; 
	} 
} ; 
 
class TetrisLogic : public GameLogic   
{ 
public: 
	enum TLKEYCODE 
	{ 
		KeyNothing, 
		KeyRight, 
		KeyLeft, 
		KeyDown, 
		KeyTurn, 
		KeyPause, 
		KeyEsc, 
		KeyOption, 
	}; 
	TetrisLogic(IGameEngine* m_pGE); 
	virtual ~TetrisLogic(); 
 
	void Init(); 
 
	INT GameStep(float fTimeEscape); 
	INT GameInput(INT nKeyCode, int nStep = 1); 
	TetrisBox GetFallingBox() const { return m_stFallingBox; } 
 	byte GameStage(int x,int y) const; 
 	int GetBoxCell(int nBoxid,int nState,int x,int y); 
	void Render(); 
 
private: 
 
	int GetRadomType(); 
	void BoxDone(); 
	void CheckScore(); 
	BOOL TestHit(TetrisBox stTmpBox); 
	 
	void PrintScore(); 
	void DrawLandEdge(); 
	void DrawLand(); 
	void DrawBox (); 
	void DrawNextBox (); 
 
	double m_nLogicTimer; 
 
	TetrisBox m_stFallingBox; 
	TetrisBox m_stNextBox; 
	byte m_nGameStage[10][30]; 
	double m_fFallingSpeed; 
 
	LONG m_nScore; 
	byte m_nGameBoxCell[10][4][5][5]; 
	//  [BoxId][State][x][y] 
 
}; 
 
#endif // !defined(AFX_TETRISLOGIC_H__71D2CBE5_C7D5_4DEA_987D_6C23218131E1__INCLUDED_)