俄罗斯方块1

这个作业要求在哪里|https://edu.cnblogs.com/campus/fzu/2020OOP/homework/10759
:-😐:-|-:
这个作业的目标| 汇报目前进度
作业正文 |如下
设计者|031903141 陈莉莹 031903142 郭婧滢 031903143 胡源芮

一、 主函数中部分函数的实现

1. 初始化函数init() ---绘制初始界面并调用NewGame()函数

void init()
{
srand((unsigned)time(NULL)); //设置随机种子
setbkmode(TRANSPARENT); //设置背景颜色为透明
setorigin(0, 0); //设置坐标原点
cleardevice(); //清屏
//显示文字
settextstyle(14, 0, L"宋体");
...
...
outtextxy(20, 440, L"esc: 退出程序");
//画两个矩形
setorigin(220, 20);
setlinecolor(WHITE);
rectangle(-1, -1, WIDTHPIX, HEIGHTPIX);
rectangle((WIDTH + 1)PIX - 1, 0, (WIDTH + 6)PIX, 6 * PIX);
NewGame();
}

2.void NewGame() ---初始化界面

void NewGame()
{
//随机产生图形
setfillcolor(BLACK);
ZeroMemory(g_map, WIDTH*HEIGHT * sizeof(int));
g_NextBlock.id = rand() % 7; //七种图形中随机一个
g_NextBlock.dir = rand() % 4; //四个方向中随机一个
g_NextBlock.x = WIDTH + 1;
g_NextBlock.y = HEIGHT - 2;
NewBlock();
}

3. void DrawUnit() ---绘制小方块

void DrawUnit(int x, int y, COLORREF color, FLAG flag)
{
int left = x * PIX ;
int right = (x + 1) * PIX - 1;
int top = (HEIGHT - y - 1) * PIX;
int bottom = (HEIGHT - y) * PIX - 1;
switch (flag)
{
case SHOW: //显示
setfillcolor(color);
setlinecolor(LIGHTGRAY);
fillrectangle(left, top, right, bottom);
break;
case CLEAR://擦除
setfillcolor(BLACK);
solidrectangle(left, top, right, bottom);
break;
case FIX: //固定
setfillcolor(RGB(GetRValue(color) * 2 / 3, GetGValue(color) * 2 / 3, GetBValue(color) * 2 / 3));
setlinecolor(DARKGRAY);
fillrectangle(left, top, right, bottom);
break;
}
}

二、 功能实现之下沉函数OnSink

下沉函数是俄罗斯方块的除原理之外的又一个重点,也是难点

void OnSink()
{
int i, x, y;
/第一部分/
//连续下移方块
DrawBlock(g_CurBlock, CLEAR);
BLOCKINFO temp = g_CurBlock;
temp.y--;
while (CheckBlock(temp))
{
g_CurBlock.y--;
temp.y--;
}
DrawBlock(g_CurBlock, FIX);
/第二部分/
// 固定方块在游戏区
int b = g_Blocks[g_CurBlock.id].dir[g_CurBlock.dir];
for (i = 0; i < 16; i++, b <<= 1)
if (b & 0x8000)
{
if (g_CurBlock.y - i / 4 >= HEIGHT)
{ //如果方块的固定位置超出高度,结束游戏
if (MessageBox(GetHWnd(), L"是否重新开始?", L"提醒", MB_OKCANCEL | MB_ICONQUESTION) == IDOK){
init();
return;
}
else{
closegraph();
exit(0);
}
}
else
g_map[g_CurBlock.y - i / 4][g_CurBlock.x + i % 4] = 1;
}
/第三部分/
// 检查是否需要消掉行,并标记
int remove = 0; // 低 4 位用来标记方块涉及的 4 行是否有消除行为
for (y = g_CurBlock.y; y >= g_CurBlock.y - 3, y>=0; y--)
{
i = 0; //统计一行格子数量
for (x = 0; x < WIDTH; x++)
if (g_map[y][x] == 1)
i++;
if (i == WIDTH)
{
remove |= (1 << (g_CurBlock.y - y));
setfillcolor(GREEN); //绿色
setlinecolor(GREEN);
fillrectangle(0, (HEIGHT - y - 1) * PIX , WIDTH * PIX - 1, (HEIGHT - y) * PIX - 1 );
g_score += 10; //消除一行成绩加10
}
}
/第四部分/
if (remove) //如果产生整行消除
{
Sleep(300);
// 擦掉刚才标记的行
IMAGE img;
for (i = 0; i < 4; i++, remove >>= 1)
{
if (remove & 1)
{
for (y = g_CurBlock.y - i + 1; y < HEIGHT; y++)
for (x = 0; x < WIDTH; x++)
{
g_map[y - 1][x] = g_map[y][x];
g_map[y][x] = 0;
}
getimage(&img, 0, 0, WIDTH * PIX, (HEIGHT - (g_CurBlock.y - i + 1)) * PIX);
putimage(0, PIX, &img);
}
}
}
//产生新方块
NewBlock();
}

开发进度:

上次作业中一共分为四个类:玩家类,方块类,游戏类,渲染类

已完成代码:如上

开发遇到的问题:

我们没有接触过渲染,对其具体操作不太清楚,正在学习中

posted @ 2020-05-22 22:36  小偶  阅读(344)  评论(1编辑  收藏  举报