目录
前言
使用easyX库,基于c/c++,实现俄罗斯方块小游戏。
作者使用的是VS2010版本,VS2019版本也可用。
一、游戏截图和全部代码
-
1.游戏截图
-
2.源代码
可直接拷贝,并运行俄罗斯方块小游戏
-
头文件代码
#pragma once
#define GAMEMAP1 200 // 预生成方块区域
#define GAMEMAP2 10
#define GAMEMAP3 500
#define GAMEMAP4 610
#define GAMEMAP5 40 // 游戏地图区域
#define GAMEMAP6 50
#define GAMEMAP7 140
#define GAMEMAP8 130
#define GAMEGUIDE1 40 // 按键说明
#define GAMEGUIDE2 300
#define GAMEGUIDE3 150
#define GAMEGUIDE4 440
#define GAMELEVEL1 30 // 游戏等级区域
#define GAMELEVEL2 160
#define GAMERANK1 30 // 游戏rank分数
#define GAMERANK2 190
#define TETRISWIDTH 15 // 游戏地图宽
#define TETRISHEIGHT 30 // 游戏地图高
#define BLOCKTYPE 8 // 方块种类数
#define BLOCKSTYLE 4 // 每种方块的样式数
#define BLOCKSPACE 20 // 方块占用空间 5 x 4
#define SIDELENGTH 20 // 方块边长 20 像素
#define ESC 27
#define CLEARKEY(); { while(_kbhit()) { _getch(); } } // 清除按键输入缓存
enum BLOCKCOLER
{
BLOCKNONE,
BLOCKBLUE,
BLOCKGREEN,
BLOCKCYAN,
BLOCKRED,
BLOCKMAGENTA,
BLOCKBROWN,
BLOCKYELLOW,
};
typedef struct _GAME_TETRIS
{
int ttime; // 计时
int ctime; // 计时
int level; // 当前游戏等级
int rank; // 当前游戏分数
int key; // 玩家按键值
int blockType; // 当前方块类型
int blockStyle; // 当前方块朝向
bool moveFlag; // 移动标识,标识为1时,移动当前方块
bool newBlockFlag; // 载入新方块标识,当标识为真时,将预生成的随机方块载入地图
bool gameOverFlag; // 游戏结束标识
}GAME_TETRIS;
typedef struct _GAME_PREBLOCK
{
int tetrisPreBlock[BLOCKSPACE]; // 预生成的方块数组
int blockType,blockStyle; // 预生成方块的类型和朝向
}GAME_PREBLOCK;
typedef struct _GAME_MOVE_BLOCK
{
int blockSite[4][2]; // 4个方块格坐标
int blockColor; // 方块颜色
}GAME_MOVE_BLOCK;
void tetrisrun(void);
void tetrisInit(void);
void tetrisDraw(void);
void tetrisNewBlock(void);
void tetrisMoveUp(void);
void tetrisMoveDown(void);
void tetrisMoveLeft(void);
void tetrisMoveRight(void);
void tetrisLoadBlock(void);
void tetrisIsOver(void);
void tetrisQuit(void);
void tetrisKeyHandle(void);
void tetrisReset(void);
void tetrisRemove(void);
-
cpp文件代码
#include "stdafx.h"
#include "tetrisnew.h"
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<time.h>
// 所有方块数组库
const int block[BLOCKTYPE][BLOCKSTYLE][BLOCKSPACE] =
{
// 总共有8种方块,每种方块有4种样式
// 'I'形方块
{
{
BLOCKNONE, BLOCKBLUE, BLOCKBLUE, BLOCKBLUE, BLOCKBLUE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE
},
{
BLOCKBLUE, BLOCKBLUE, BLOCKBLUE, BLOCKBLUE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBLUE, BLOCKNONE, BLOCKNONE
}
},
// 'Z'形方块
{
{
BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKGREEN, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKGREEN, BLOCKGREEN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKGREEN, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// 反'Z'形方块
{
{
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKCYAN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// 'T'形方块
{
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// 'T'形方块 X 2 增加T形方块出现概率
{
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKRED, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKRED, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKRED, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// '田'形方块
{
{
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKMAGENTA,BLOCKMAGENTA,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// 'L'形方块
{
{
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKBROWN, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKBROWN, BLOCKBROWN,
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKBROWN, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKBROWN, BLOCKBROWN, BLOCKBROWN, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
},
// 反'L'形方块
{
{
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKYELLOW,BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKYELLOW,BLOCKYELLOW,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKYELLOW,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
},
{
BLOCKNONE, BLOCKYELLOW,BLOCKYELLOW,BLOCKYELLOW,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKYELLOW,BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE,
BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE, BLOCKNONE
}
}
};
// 游戏实时画面
int tetrisMap[TETRISHEIGHT][TETRISWIDTH] =
{
};
GAME_TETRIS player; // 玩家数据
GAME_PREBLOCK preBlock; // 预生成方块数据
GAME_MOVE_BLOCK moveBlock; // 当前控制方块数据
int main(void)
{
tetrisrun();
return 0;
}
void tetrisrun(void)
{
tetrisInit();
while(1)
{
player.ctime = GetTickCount();
if( (player.ctime - 500 + 30*player.level) > player.ttime )
{
player.moveFlag = TRUE;
player.ttime = GetTickCount();
}
if(player.moveFlag)
{
player.moveFlag = FALSE;
tetrisMoveDown();
tetrisDraw();
}
if(_kbhit())
{
player.key = _getch();
tetrisKeyHandle();
}
if(player.newBlockFlag)
{
player.newBlockFlag = FALSE;
tetrisLoadBlock();
tetrisRemove();
tetrisNewBlock();
tetrisIsOver();
}
if(player.gameOverFlag)
{
player.gameOverFlag = FALSE;
break;
}
}
}
void tetrisInit(void)
{
int i,j,k;
HWND window = initgraph(510, 620);
SetWindowText(window, "俄罗斯方块 - by耒阳阿杰");
//SetWindowPos(window,HWND_TOPMOST,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
rectangle(GAMEMAP1 - 2,GAMEMAP2 - 2,GAMEMAP3 + 2,GAMEMAP4 + 2);
rectangle(GAMEMAP5 - 2,GAMEMAP6 - 2,GAMEMAP7 + 2,GAMEMAP8 + 2);
rectangle(GAMEGUIDE1 - 5,GAMEGUIDE2 - 5,GAMEGUIDE3 + 5,GAMEGUIDE4 + 5);
outtextxy(GAMEMAP5 + 10 ,GAMEMAP6 - 26,"下个方块");
settextcolor(GREEN);
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 ,"W :改变形状");
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 + 25 ,"A :方块左移");
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 + 50 ,"S :方块右移");
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 + 75 ,"D :方块下移");
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 + 100 ,"R :重新开始");
outtextxy(GAMEGUIDE1 ,GAMEGUIDE2 + 125 ,"ESC:退出游戏");
memset ( &player, 0, sizeof ( GAME_TETRIS ) );
memset ( &preBlock, 0, sizeof ( GAME_PREBLOCK ) );
memset(tetrisMap,0,sizeof(tetrisMap));
player.ttime = GetTickCount();
srand((unsigned)time(NULL));
i = (rand() + 1) % BLOCKTYPE;
j = rand() % BLOCKSTYLE;
for(k = 0; k < BLOCKSPACE;k++)
{
preBlock.tetrisPreBlock[k] = block[i][j][k];
}
preBlock.blockType = i;
preBlock.blockStyle = j;
tetrisNewBlock();
}
void tetrisDraw(void)
{
int i,j;
int x,y;
char ch[20];
settextstyle(20,12,"宋体");
settextcolor(CYAN);
if(player.level < 10)
{
sprintf_s(ch, "%s%d","LEVEL:", player.level);
}
else
{
sprintf_s(ch, "%s","LEVEL:MAX");
}
outtextxy(GAMELEVEL1,GAMELEVEL2,ch);
settextcolor(LIGHTBLUE);
sprintf_s(ch, "%s%d","RANK:", player.rank);
outtextxy(GAMERANK1,GAMERANK2,ch);
setfillcolor(BLACK);
solidrectangle(GAMEMAP5,GAMEMAP6,GAMEMAP7,GAMEMAP8);
for(i = 0; i < BLOCKSPACE; i++)
{
switch(preBlock.tetrisPreBlock[i])
{
case BLOCKNONE:
continue;
break;
case BLOCKBLUE:
setfillcolor(BLUE);
break;
case BLOCKGREEN:
setfillcolor(GREEN);
break;
case BLOCKCYAN:
setfillcolor(CYAN);
break;
case BLOCKRED:
setfillcolor(RED);
break;
case BLOCKMAGENTA:
setfillcolor(MAGENTA);
break;
case BLOCKBROWN:
setfillcolor(BROWN);
break;
case BLOCKYELLOW:
setfillcolor(YELLOW);
break;
}
fillrectangle(GAMEMAP5 + (i%5) * SIDELENGTH ,GAMEMAP6 + (i/5) * SIDELENGTH ,GAMEMAP5 + ((i%5)+1)*SIDELENGTH ,GAMEMAP6 + ((i/5)+1) * SIDELENGTH );
}
setfillcolor(BLACK);
solidrectangle(GAMEMAP1,GAMEMAP2,GAMEMAP3,GAMEMAP4);
for(i = 0; i < 4; i++)
{
x = moveBlock.blockSite[i][0];
y = moveBlock.blockSite[i][1];
switch(moveBlock.blockColor)
{
case BLOCKNONE:
continue;
break;
case BLOCKBLUE:
setfillcolor(BLUE);
break;
case BLOCKGREEN:
setfillcolor(GREEN);
break;
case BLOCKCYAN:
setfillcolor(CYAN);
break;
case BLOCKRED:
setfillcolor(RED);
break;
case BLOCKMAGENTA:
setfillcolor(MAGENTA);
break;
case BLOCKBROWN:
setfillcolor(BROWN);
break;
case BLOCKYELLOW:
setfillcolor(YELLOW);
break;
}
fillrectangle(GAMEMAP1 + y * SIDELENGTH ,GAMEMAP2 + x * SIDELENGTH ,GAMEMAP1 + (y+1)*SIDELENGTH ,GAMEMAP2 + (x+1) * SIDELENGTH );
}
for(i = 0; i < TETRISHEIGHT; i++)
{
for(j = 0; j < TETRISWIDTH; j++)
{
switch(tetrisMap[i][j])
{
case BLOCKNONE:
continue;
break;
case BLOCKBLUE:
setfillcolor(BLUE);
break;
case BLOCKGREEN:
setfillcolor(GREEN);
break;
case BLOCKCYAN:
setfillcolor(CYAN);
break;
case BLOCKRED:
setfillcolor(RED);
break;
case BLOCKMAGENTA:
setfillcolor(MAGENTA);
break;
case BLOCKBROWN:
setfillcolor(BROWN);
break;
case BLOCKYELLOW:
setfillcolor(YELLOW);
break;
}
fillrectangle(GAMEMAP1 + j * SIDELENGTH ,GAMEMAP2 + i * SIDELENGTH ,GAMEMAP1 + (j+1)*SIDELENGTH ,GAMEMAP2 + (i+1) * SIDELENGTH );
}
}
}
void tetrisNewBlock(void)
{
int i,j,k;
k = 0;
for(i = 0; i < BLOCKSPACE; i++)
{
if(preBlock.tetrisPreBlock[i])
{
moveBlock.blockColor = preBlock.tetrisPreBlock[i];
moveBlock.blockSite[k][0] = i/5;
moveBlock.blockSite[k][1] = 5 + i%5;
k++;
}
}
player.blockType = preBlock.blockType;
player.blockStyle = preBlock.blockStyle;
srand((unsigned)time(NULL));
i = rand