俄罗斯方块C语言源代码

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

#include

#include

#include

#include

#include

#define true 1

#define false 0

#define BoardWidth 12

#define BoardHeight 23

#define _INNER_HELPER /*inner helper method */

/*Scan Codes Define*/

enum KEYCODES

{

K_ESC =0x011b,

K_UP =0x4800, /* upward arrow */

K_LEFT =0x4b00,

K_DOWN =0x5000,

K_RIGHT =0x4d00,

K_SPACE =0x3920,

K_P =0x1970

};

/* the data structure of the block */

typedef struct tagBlock

{

char c[4][4]; /* cell fill info array, 0-empty, 1-filled */

int x; /* block position cx [ 0,BoardWidht -1] */ int y; /* block position cy [-4,BoardHeight-1] */ char color; /* block color */

char size; /* block max size in width or height */

char name; /* block name (the block's shape) */

} Block;

/* game's global info */

int FrameTime= 1300;

int CellSize= 18;

int BoardLeft= 30;

int BoardTop= 30;

/* next block grid */

int NBBoardLeft= 300;

int NBBoardTop= 30;

int NBCellSize= 10;

/* score board position */

int ScoreBoardLeft= 300;

int ScoreBoardTop=100;

int ScoreBoardWidth=200;

int ScoreBoardHeight=35;

int ScoreColor=LIGHTCY AN;

/* infor text postion */

int InfoLeft=300;

int InfoTop=200;

int InfoColor=YELLOW;

int BorderColor=DARKGRAY;

int BkGndColor=BLACK;

int GameRunning=true;

int TopLine=BoardHeight-1; /* top empty line */

int TotalScore=100;

char info_score[20];

char info_help[255];

char info_common[255];

/* our board, Board[x][y][0]-isFilled, Board[x][y][1]-fillColor */ unsigned char Board[BoardWidth][BoardHeight][2];

char BufferCells[4][4]; /* used to judge if can rotate block */ Block curBlock; /* current moving block */

Block nextBlock; /* next Block to appear */

/* function list */

int GetKeyCode();

int CanMove(int dx,int dy);

int CanRotate();

int RotateBlock(Block *block);

int MoveBlock(Block *block,int dx,int dy);

void DrawBlock(Block *block,int,int,int);

void EraseBlock(Block *block,int,int,int);

void DisplayScore();

void DisplayInfo(char* text);

void GenerateBlock(Block *block);

void NextBlock();

void InitGame();

int PauseGame();

void QuitGame();

/*Get Key Code */

int _INNER_HELPER GetKeyCode()

{

int key=0;

if(bioskey(1))

{

key=bioskey(0);

}

return key;

}

/* display text! */

void _INNER_HELPER DisplayInfo(char *text)

{

setcolor(BkGndColor);

outtextxy(InfoLeft,InfoTop,info_common);

strcpy(info_common,text);

setcolor(InfoColor);

outtextxy(InfoLeft,InfoTop,info_common);

}

/* create a new block by key number,

* the block anchor to the top-left corner of 4*4 cells

*/

void _INNER_HELPER GenerateBlock(Block *block)

{

int key=(random(13)*random(17)+random(1000)+random(3000))%7;

block->size=3;/* because most blocks' size=3 */

memset(block->c,0,16);

switch(key)

{

case 0:

block->name='T';

block->color=RED;

block->c[1][0]=1;

block->c[1][1]=1, block->c[2][1]=1;

block->c[1][2]=1;

break;

case 1:

block->name='L';

block->color=YELLOW;

block->c[1][0]=1;

block->c[1][1]=1;

block->c[1][2]=1, block->c[2][2]=1;

相关文档
最新文档