c语言数据结构程序设计俄罗斯方块

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

课程名称《数据结构》课程设计指导老师

所在学院

专业年级

提交日期

成绩

小组成员表

课程设计实验

一、需求分析

我们对俄罗斯方块这个游戏一点也不陌生,知道游戏的玩法和实现后,我们很快就着手开干。游戏要有出现场景、方块、消除方块得分、判断游戏结束等几个大功能。结构清晰简洁便于分工。

二、算法原理介绍

游戏主要使用了数组这个数据结构。不过与以往的程序不同,这个游戏有一个大数组包含很多个小数组,大数组不断的吸收小数组内的元素,达到条件得分。

三、概要设计

1、功能块各函数列表

2、场景的设置

int map[28][17]={

{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},

{0,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1},

{0,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1},

{0,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1},

{0,1,1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1},

{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},

{0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}

};

void showmap()

{

int i,j;

for(i=5;i<28;i++)

{

for(j=1;j<17;j++)

{

gotoxy(2*j,i);

if(j==1||j==2||j==15||j==16)

{printf("┃");}

else if(i==26||i==27)

{printf("━");}

else if(map[i][j]==1) printf("■");

else if(map[i][j]==0) printf("□");

}

}

}

3、其余功能的实现(如方块的出现下落旋转得分计算游戏结束条件判断等)

(1)旋转

void roll()

{ int i,j;

p_xnext=p_x;

p_ynext=p_y;

for(i=0;i<5;i++)

for(j=0;j<5;j++)

{

box_next_step[4-j][i]=box[i][j];

}

}

(2)得分计算

void score()

{

int i,j,k;

for(i=25;i>5;i--)

{

for(j=3;j<15;j++)

{

if(map[i][j]==1) flags=1;

else {

flags=0;

break;

}

}

if(flags==1)

{

pointrank++;

for(j=3;j<15;j++)

{

for(k=i;k>5;k--)

{

map[k][j]=map[k-1][j];

}

}

i++;

}

}

switch(pointrank)

{

case 1:

scores=scores+10;break;

case 2:

scores=scores+25;break;

case 3:

scores=scores+40;break;

case 4:

scores=scores+60;break;

default:

scores=scores+0;

}

gotoxy(40,15);

printf("Your Score:%d",scores);

pointrank=0;

showmap();

Sleep(300);

}

(3)游戏结束判断

相关文档
最新文档