📄 blockgame.h
字号:
/************************************************************************
*
* linux版仿联众俄罗斯方块
*
* 该软件在GPL(GNU通用公共许可证)下发布
*
* Copyright (C) <codeky@126.com>
*
* This source code is licensed under the GNU General Public License
*
************************************************************************/
/*********************************************************************/
#ifndef _BLOCK_GAME_H
#define _BLOCK_GAME_H
/*********************************************************************/
#define _bS8 char
#define _bU8 unsigned char
#define _bU16 unsigned int
#define _bU32 unsigned long
#define _bBool _bU8
#define _bTrue 1
#define _bFalse 0
/*********************************************************************/
#ifdef _MSC_VER
#define GET_CUR_TIME() (_bU32)time(NULL)
#else
#ifdef __GNUC__
#define GET_CUR_TIME() ({ time_t t; time(&t); (_bU32)t;})
#else
#define GET_CUR_TIME()
#endif
#endif
/********************************************************************/
const _bU8 GAME_ROW = 22;
const _bU8 GAME_COL = 11;
const _bU8 GAME_GRID_ROW = GAME_ROW+6; /*边框: 上下各3行 */
const _bU8 GAME_GRID_COL = GAME_COL+6; /* 左右各3列 */
const _bU8 GAME_FIRST_ROW = 3;
const _bU8 GAME_FIRST_COL = 3;
const _bU8 GAME_LAST_ROW = GAME_GRID_ROW-1-3; //24;
const _bU8 GAME_LAST_COL = GAME_GRID_COL-1-3; //13;
/*********************************************************************/
typedef struct{
struct{
_bS8 bFillBlock:4;
_bS8 nBlockType:4;
} Grid[GAME_GRID_ROW][GAME_GRID_COL];
}GAME_GRID;
typedef struct{
struct{
_bS8 row;
_bS8 col;
}CurFirstBlock;
_bS8 nCurBlockType:4; /*方块的类型(7种)*/
_bS8 nCurBlockStatus:4; /*方块的状态(4种)*/
_bS8 nNextBlockType:4; /*下一方块的类型 */
}GAME_BLOCK;
typedef struct
{
_bS8 nFullRowCount; /* 满行数 */
_bS8 nIdleBankCount; /* 无用的空格数 */
_bS8 nBankCount; /* 空格数 */
_bS8 nHighEdgeCount; /* 高边缘数 */
_bS8 nLastBlockFirstRow;
_bS8 nHighEdgeGridCount; /* 高边缘中的格子总数 */
_bS8 nMostHighEdgeHeight;
}GRID_ATTR;
enum{eGameNormal=1,eGameRun=2,eGamePause=4,eGameWin=8,eGameLost=16};
// eGameNormal 刚开始状态,开机才存在的状态,在init中被设置
// eGameRun 在newgame中被设置
// eGamePause 在 PauseGame中被设置
// eGameWin 在WinGame中被设置
// eGameLost 在GameOver中被设置
typedef struct
{
GAME_GRID GameGrid;
GAME_BLOCK GameBlock;
_bU16 nGameTimer; // 游戏次数计数器
_bU16 nLostTimer; /*输的次数*/
_bU16 nWinTimer;
_bU32 lScore;
_bS8 nGameStatus; // 游戏状态
_bBool bDirty;
}BLOCK_GAME;
/*********************************************************************/
void InitGame( BLOCK_GAME* pGame );
_bS8 NewGame( BLOCK_GAME* pGame );
_bS8 NewBlock( BLOCK_GAME* pGame );
void PauseGame( BLOCK_GAME* pGame, _bBool pause );
void WinGame( BLOCK_GAME* pGame );
void GameOver( BLOCK_GAME* pGame );
enum eMoveMode{eMoveLeft=1, eMoveTurn, eMoveRight, eMoveUp, eMoveDown,eMoveSDown};
_bBool MoveBlock( BLOCK_GAME* pGame, _bS8 type);
_bBool TurnBlock( BLOCK_GAME* pGame );
void FixCurBlock( BLOCK_GAME* pGame );
_bS8 AdjustGrid( BLOCK_GAME* pGame );
_bS8 AddLine( BLOCK_GAME* pGame, _bS8 nLineCount/*加行数*/);
/*********************************************************************/
void CopyGame( BLOCK_GAME* pDestGame, BLOCK_GAME* pSourGame );
void CopyGameGrid( GAME_GRID* pDestGrid, GAME_GRID* pSourGrid );
void CopyGameBlock( GAME_BLOCK* pDestBlock, GAME_BLOCK* pSourBlock );
void CopyGridAttr(GRID_ATTR* pDestAttr, GRID_ATTR* pSourAttr );
/*********************************************************************/
/* 下列函数用于电脑计算最佳状态 */
void GetGridAttr( BLOCK_GAME* pGame , GRID_ATTR* pGridAttr );
void GetFullRow( BLOCK_GAME* pGame , GRID_ATTR* pGridAttr );
void GetIdleBank( BLOCK_GAME* pGame , GRID_ATTR* pGridAttr );
void GetBank( BLOCK_GAME* pGame , GRID_ATTR* pGridAttr );
void GetHighEdge(BLOCK_GAME* pGame, GRID_ATTR* pGridAttr );
/*********************************************************************/
const _bS8 GameBlock[7][4][4][4]={
/*方块0*/
{{{0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0}}, /* status 1 */
{{0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0}}, /* status 2 */
{{0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0}}, /* status 3 */
{{0,0,0,0}, {0,1,1,0}, {0,1,1,0}, {0,0,0,0}}}, /* status 4 */
/*方块1*/
{{{0,0,0,0}, {1,1,1,1}, {0,0,0,0}, {0,0,0,0}},
{{0,1,0,0}, {0,1,0,0}, {0,1,0,0}, {0,1,0,0}},
{{0,0,0,0}, {1,1,1,1}, {0,0,0,0}, {0,0,0,0}},
{{0,1,0,0}, {0,1,0,0}, {0,1,0,0}, {0,1,0,0}}},
/*方块2*/
{{{0,0,0,0}, {0,1,0,0}, {0,1,1,0}, {0,0,1,0}},
{{0,0,0,0}, {0,1,1,0}, {1,1,0,0}, {0,0,0,0}},
{{0,0,0,0}, {0,1,0,0}, {0,1,1,0}, {0,0,1,0}},
{{0,0,0,0}, {0,1,1,0}, {1,1,0,0}, {0,0,0,0}}},
/*方块3*/
{{{0,0,0,0}, {0,0,1,0}, {0,1,1,0}, {0,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,1,0}, {0,1,1,0}, {0,1,0,0}},
{{0,0,0,0}, {0,0,0,0}, {0,1,1,0}, {0,0,1,1}}},
/*方块4*/
{{{0,0,0,0}, {0,1,1,0}, {0,1,0,0}, {0,1,0,0}},
{{0,0,0,0}, {1,0,0,0}, {1,1,1,0}, {0,0,0,0}},
{{0,0,0,0}, {0,1,0,0}, {0,1,0,0}, {1,1,0,0}},
{{0,0,0,0}, {0,0,0,0}, {1,1,1,0}, {0,0,1,0}}},
/*方块5*/
{{{0,0,0,0}, {0,1,1,0}, {0,0,1,0}, {0,0,1,0}},
{{0,0,0,0}, {0,0,0,0}, {0,1,1,1}, {0,1,0,0}},
{{0,0,0,0}, {0,0,1,0}, {0,0,1,0}, {0,0,1,1}},
{{0,0,0,0}, {0,0,0,1}, {0,1,1,1}, {0,0,0,0}}},
/*方块6*/
{{{0,0,0,0}, {0,1,0,0}, {1,1,1,0}, {0,0,0,0}},
{{0,0,0,0}, {0,1,0,0}, {1,1,0,0}, {0,1,0,0}},
{{0,0,0,0}, {0,0,0,0}, {1,1,1,0}, {0,1,0,0}},
{{0,0,0,0}, {0,1,0,0}, {0,1,1,0}, {0,1,0,0}}}
};
/*********************************************************************/
#endif
/*********************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -