//// http://dotlive.cnblogs.com/
// TetrisLogic.cpp: implementation of the TetrisLogic class.
//
//////////////////////////////////////////////////////////////////////
#include "TetrisLogic.h"
#include <cstdio>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
TetrisLogic::TetrisLogic(IGameEngine* pGE):GameLogic(pGE)
{
byte nGameBoxCell[10][4][5][5]=
{
{//id = 0
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,1,1,0,0},
{0,0,0,0,0}
}
},
{//id = 1
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{1,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{1,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
}
},
{//id = 2
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,1,1,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,0,0},
{0,1,0,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,1,1,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,0,0},
{0,1,0,0,0},
{0,0,0,0,0}
}
},
{//id = 3
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,1,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,1,1,0},
{0,0,0,1,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,1,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,1,1,0},
{0,0,0,1,0},
{0,0,0,0,0}
}
},
{//id = 4
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,1,0},
{0,1,0,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,1,1,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,1,0},
{0,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,1,1,0},
{0,0,0,0,0}
}
},
{//id = 5
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,1,0},
{0,0,0,1,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,1,1,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,1,0,0,0},
{0,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,1,1,0},
{0,0,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
}
},
{//id = 6
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,1,1,1,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,0,0},
{0,0,1,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,1,0,0},
{0,1,1,1,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,1,1,0},
{0,0,1,0,0},
{0,0,0,0,0}
}
},
{//id = 7
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
}
},
{//id = 8
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
}
},
{//id = 9
{//state =0
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =1
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =2
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
},
{//state =3
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,1,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
}
}
};
memcpy( (void*)m_nGameBoxCell, (void*)nGameBoxCell, 10*4*5*5 );
// Init();
}
TetrisLogic::~TetrisLogic()
{
}
INT TetrisLogic::GameStep( float fTimeEscape )
{
m_nLogicTimer = m_nLogicTimer>100000?m_nLogicTimer-100000:m_nLogicTimer ;
INT n = m_nLogicTimer/m_fFallingSpeed ;
m_nLogicTimer += fTimeEscape*1000;
INT n2 = m_nLogicTimer/m_fFallingSpeed ;
if ( n2>n )
{
GameInput(KeyDown,n2-n);
}
return 0;
}
int TetrisLogic::GetBoxCell(int nBoxid,int nState,int x,int y)
{
if (nBoxid>=0&&nBoxid<10
&&nState>=0&&nState<4
&&x>=0&&x<5
&&y>=0&&y<5
)
{
return m_nGameBoxCell[nBoxid][nState][y][x];
}
return -1;
}
BOOL TetrisLogic::TestHit(TetrisBox stTmpBox)
{
for (int x=0;x<5;x++)
{
for (int y=0;y<5;y++)
{
if (1==GetBoxCell(stTmpBox.m_nBoxID,stTmpBox.m_nState,x,y))
{
if (1==GameStage(stTmpBox.m_ptPosition.x+x-2,stTmpBox.m_ptPosition.y+y-2))
{
return TRUE;
}
}
}
}
return FALSE;
}
INT TetrisLogic::GameInput( INT nKeyCode ,int nStep)
{
TetrisBox tmpBox = m_stFallingBox;
switch(nKeyCode)
{
case KeyTurn:
tmpBox.m_nState = (tmpBox.m_nState+1)%4;
// tmpBox.m_nState = (tmpBox.m_nState+3)%4;
break;
case KeyRight:
tmpBox.m_ptPosition.x ++;
break;
case KeyLeft:
tmpBox.m_ptPosition.x --;
break;
case KeyDown:
tmpBox.m_ptPosition.y ++;
break;
// case KeyDown:
// break;
}
if (!TestHit(tmpBox))
{
m_stFallingBox = tmpBox;
}
else
{
if (KeyDown == nKeyCode)
{
BoxDone();
}
}
return 0;
}
void TetrisLogic::BoxDone()
{
for (int x=0;x<5;x++)
{
for (int y=0;y<5;y++)
{
if (1 == GetBoxCell(m_stFallingBox.m_nBoxID,m_stFallingBox.m_nState, x, y ))
{
int dx = m_stFallingBox.m_ptPosition.x+x-2;
int dy = m_stFallingBox.m_ptPosition.y+y-2;
if(dx<10&&dx>=0&&dy<30&&dy>=0)
m_nGameStage[dx][dy] = 1;
}
}
}
//check record
CheckScore();
//reset fallbox to next
//get next
m_stFallingBox = m_stNextBox;
m_stNextBox.m_nBoxID = GetRadomType();
return;
}
void TetrisLogic::Init()
{
m_nLogicTimer = 0;
m_stFallingBox.m_nBoxID = GetRadomType();
m_stFallingBox.m_nState = 0;
m_stFallingBox.m_ptPosition.y = 0;
m_stFallingBox.m_ptPosition.x = 4;
m_stNextBox.m_nBoxID = GetRadomType();
m_stNextBox.m_nState = 0;
m_stNextBox.m_ptPosition.y = 0;
m_stNextBox.m_ptPosition.x = 4;
memset ( m_nGameStage, 0, 30*10* sizeof(byte) );
m_fFallingSpeed = 1000;
m_nScore = 100;
}
int TetrisLogic::GetRadomType()
{
return m_pGE->IGE_GetRandomInt(0,6);
}
byte TetrisLogic::GameStage( int x,int y ) const
{
if(x<10&&x>=0&&y<30&&y>=0)
return m_nGameStage[x][y];
return 1;
}
void TetrisLogic::CheckScore()
{
int nV = 0;
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
hge俄罗斯方块.rar (34个子文件)
Teris_src_dotlive
GameLogic.h 851B
TetrisLogic.h 2KB
TetrisLogic.cpp 10KB
include
hge.h 15KB
hgecolor.h 2KB
hgesprite.h 2KB
hgevector.h 2KB
hgeparticle.h 4KB
hgeresource.h 2KB
hgegui.h 2KB
hgeanim.h 1KB
hgerect.h 804B
hgedistort.h 2KB
hgeguictrls.h 4KB
hgestrings.h 697B
hgefont.h 2KB
menuitem.cpp 4KB
hge_tut06.dsp 4KB
menuitem.h 1018B
hge_tut06.dsw 541B
hge_tut06.cpp 9KB
output
bg.png 712B
hge.dll 352KB
font1.fnt 2KB
bg2.png 472B
font1.png 10KB
menu.wav 1KB
bass.dll 90KB
cursor.png 1KB
Lib
hge.lib 2KB
hgehelp.lib 151KB
GameWorld.h 550B
GameWorld.cpp 440B
GameLogic.cpp 469B
共 34 条
- 1
资源评论
- tpzon2012-07-10资源还可以啊,可以编译、正常运行!
- londe75152012-06-05资源不怎么好, 下载下来VS编译后, 运行不了;内存出错。
aaron5699
- 粉丝: 14
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功