| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1789 人关注过本帖
标题:自己写的俄罗斯方块程序,大家来看看有没有什么问题
只看楼主 加入收藏
gl88627
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-6-10
收藏
 问题点数:0 回复次数:11 
自己写的俄罗斯方块程序,大家来看看有没有什么问题
#define TOP_X 200
#define TOP_Y 30
#define NUM_X 10
#define NUM_Y 15
#define SIZE 20
#define BEGIN_X 260
#define BEGIN_Y 30
#define TIMER 0x1c
#define VK_RIGHT 0x4d00
#define VK_LEFT 0x4b00
#define VK_UP 0x4800
#define VK_DOWN 0x5000
#define ESC 0x11b
#define UP 1
#define DOWM 2
#define LEFT 3
#define RIGHT 4
#define NONE 0
#define TURE 1
#define FALSE 0
#define MAX_BOX 19
#include<graphics.h>
#include<stdlib.h>
#include<bios.h>
#include<dos.h>
#include<stdio.h>
#include<time.h>
typedef struct BOARD
{
int var;
int color;
}Board;
Board Table_board[NUM_Y][NUM_X];
typedef struct SHAPE
{
char box[2];
int color;
int next;
}Shape;
Shape shapes[MAX_BOX]=
{
{0x88,0xc0,RED,1},
{0xe8,0x0,RED,2},
{0xc4,0x40,RED,3},
{0x2e,0x0,RED,0},
{0x44,0xc0,RED,5},
{0x8e,0x0,RED,6},
{0xc8,0x80,RED,7},
{0xe2,0x0,RED,4},
{0x8c,0x40,RED,9},
{0x6c,0x0,RED,8},
{0x4c,0x80,RED,11},
{0xc6,0x0,RED,10},
{0x4e,0x0,RED,13},
{0x8c,0x80,RED,14},
{0xe4,0x0,RED,15},
{0x4c,0x40,RED,12},
{0x88,0x88,RED,17},
{0xf0,0x0,RED,16},
{0xcc,0x0,RED,18}
};
int standard=128;
int TimerCounter=0;
int flag_newbox=0;
int score=0;
int speed=0;
int level=5;
void interrupt (*oldhandler)();
initialize(int x,int y,int m,int n)
{
int gdriver,gmode,i,j,xr,yr,xl,yl;
gdriver=DETECT;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"");
setbkcolor(0);
cleardevice();
setcolor(WHITE);
for(i=0;i<n;i++)
{
xr=x;
yr=y+i*SIZE;
xl=x+SIZE;
yl=y+SIZE+i*SIZE;
for(j=0;j<m;j++)
{
if(Table_board[i][j].var==0)
{
setfillstyle(1,0);
rectangle(xr,yr,xl,yl);
floodfill(xr+1,yr+1,WHITE);
}
else
{
setfillstyle(0,4);
rectangle(xr,yr,xl,yl);
floodfill(xr+1,yr+1,RED);
}
xr=xr+SIZE;
xl=xl+SIZE;
}
}
}
void ShowScore()
{
char *s="SCORE";
char *c;
outtextxy(120,50,s);
sprintf(c,"%d",score);
outtextxy(135,60,c);
}
void ShowLevel()
{
char *s="LEVEL";
char *c;
outtextxy(120,130,s);
sprintf(c,"%d",speed);
outtextxy(135,140,c);
}
void Help()
{
char *s1="-Roll";
char *s2="-Downwards";
char *s3="-TurnLeft";
char *s4="-TurnRight";
char *s5="Esc-Exit";
char *c1,*c2,*c3,*c4;
sprintf(c1,"%c",24);
sprintf(c2,"%c",25);
sprintf(c3,"%c",27);
sprintf(c4,"%c",26);
rectangle(200,350,450,450);
outtextxy(230,380,c1);
outtextxy(235,380,s1);
outtextxy(350,380,c2);
outtextxy(355,380,s2);
outtextxy(230,400,c3);
outtextxy(235,400,s3);
outtextxy(350,400,c4);
outtextxy(355,400,s4);
outtextxy(230,420,s5);
}
int MoveAble(int x,int y,int box_numb,int direction)
{
int i,j,m,n,pre_n,pre_m,pre_x;
Board RefTable_board[NUM_Y][NUM_X];
n=(x-TOP_X)/SIZE;
m=(y-TOP_Y)/SIZE;
pre_n=n;
pre_m=m;
pre_x=x;
for(i=0;i<NUM_Y;i++)
{
for(j=0;j<NUM_X;j++)
RefTable_board[i][j].var=Table_board[i][j].var;
}
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
RefTable_board[m][n].var=0;
standard=standard/2;
n++;
}
n=pre_n;
m++;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
RefTable_board[m][n].var=0;
standard=standard/2;
n++;
}
n=pre_n;
m++;
}
n=pre_n;
m=pre_m;
if(direction==LEFT)
{
if(x==200)
{
standard=128;
return FALSE;
}
standard=128;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
if(RefTable_board[m][n-1].var==1)
{
standard=128;
return FALSE;
}
}
standard=standard/2;
n=n+1;
}
n=pre_n;
m=m+1;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
if(RefTable_board[m][n-1].var==1)
{
standard=128;
return FALSE;
}
}
standard=standard/2;
n=n+1;
}
n=pre_n;
m=m+1;
}
standard=128;
return TURE;
}
if(direction==RIGHT)
{
standard=128;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
if(RefTable_board[m][n+1].var==1||x+SIZE==400)
{
standard=128;
return FALSE;
}
}
n=n+1;
standard=standard/2;
x=x+SIZE;
}
x=pre_x;
n=pre_n;
m=m+1;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
if(RefTable_board[m][n+1].var==1||x+SIZE==400)
{
standard=128;
return FALSE;
}
}
n=n+1;
standard=standard/2;
x=x+SIZE;
}
x=pre_x;
n=pre_n;
m=m+1;
}
standard=128;
return TURE;
}
if(direction==NONE)
{
standard=128;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
if(y+SIZE==330||RefTable_board[m+1][n].var==1)
{
standard=128;
return FALSE;
}
}
standard=standard/2;
n++;
}
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
if(y+SIZE==330||RefTable_board[m+1][n].var==1)
{
standard=128;
return FALSE;
}
}
standard=standard/2;
n++;
}
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
return TURE;
}
}
show_box(int x,int y,int box_numb,int color)
{
int i,j,pre_x,m,n,pre_n;
pre_x=x;
n=(x-TOP_X)/SIZE;
m=(y-TOP_Y)/SIZE;
pre_n=n;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
rectangle(x,y,x+SIZE,y+SIZE);
setfillstyle(1,color);
floodfill(x+1,y+1,WHITE);
Table_board[m][n].var=1;
Table_board[m][n].color=color;
}
n++;
standard=standard/2;
x=x+SIZE;
}
x=pre_x;
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
rectangle(x,y,x+SIZE,y+SIZE);
setfillstyle(1,color);
floodfill(x+1,y+1,WHITE);
Table_board[m][n].var=1;
Table_board[m][n].color=color;
}
standard=standard/2;
x=x+SIZE;
n++;
}
x=pre_x;
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
}
EraseBox(int x,int y,int box_numb)
{
int i,j,pre_x,m,n,pre_n;
n=(x-TOP_X)/SIZE;
m=(y-TOP_Y)/SIZE;
pre_x=x;
pre_n=n;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
setfillstyle(1,0);
floodfill(x+1,y+1,WHITE);
Table_board[m][n].var=0;
Table_board[m][n].color=0;
}
standard=standard/2;
x=x+SIZE;
n++;
}
x=pre_x;
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
setfillstyle(1,0);
floodfill(x+1,y+1,WHITE);
Table_board[m][n].var=0;
Table_board[m][n].color=0;
}
standard=standard/2;
x=x+SIZE;
n++;
}
x=pre_x;
n=pre_n;
m++;
y=y+SIZE;
}
standard=128;
}
void interrupt newhandler()
{
TimerCounter++;
}
SetTimer(void interrupt(*IntProc)())
{
oldhandler=getvect(TIMER);
disable();
setvect(TIMER,IntProc);
enable();
}
KillTimer()
{
disable();
setvect(TIMER,oldhandler);
enable();
}
int MkNextBox()
{
int box_numb;
long int seed;
seed=time(NULL);
srand(seed);
box_numb=rand()%MAX_BOX;
return box_numb;
}
int EddyAble(int x,int y,int box_numb)
{
int i,j,pre_n,pre_x,pre_m,m,n,current_box;
Board RefTable_board[NUM_Y][NUM_X];
n=(x-TOP_X)/SIZE;
m=(y-TOP_Y)/SIZE;
pre_n=n;
pre_m=m;
pre_x=x;
for(i=0;i<NUM_Y;i++)
{
for(j=0;j<NUM_X;j++)
RefTable_board[i][j].var=Table_board[i][j].var;
}
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
RefTable_board[m][n].var=0;
standard=standard/2;
n++;
}
n=pre_n;
m++;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
RefTable_board[m][n].var=0;
standard=standard/2;
n++;
}
n=pre_n;
m++;
}
n=pre_n;
m=pre_m;
current_box=shapes[box_numb].next;
standard=128;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[current_box].box[0]&standard)
{
if(RefTable_board[m][n].var==1||x==400)
{
standard=128;
return FALSE;
}
}
x=x+SIZE;
n++;
standard=standard/2;
}
x=pre_x;
n=pre_n;
m++;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[current_box].box[1]&standard)
{
if(RefTable_board[m][n].var==1||x==400)
{
standard=128;
return FALSE;
}
}
x=x+SIZE;
n++;
standard=standard/2;
}
x=pre_x;
n=pre_n;
m++;
}
standard=128;
return TURE;
}
int DelFullRow(int y)
{
int i,j,x1,y1,xr,yr,xl,yl,t_boardy;
x1=TOP_X;
y1=TOP_Y;
for(i=0;i<y;i++)
{
for(j=0;j<10;j++)
Table_board[y-i][j]=Table_board[y-i-1][j];
}
for(i=0;i<NUM_Y;i++)
{
xr=x1;
yr=y1+i*SIZE;
xl=x1+SIZE;
yl=y1+SIZE+i*SIZE;
for(j=0;j<NUM_X;j++)
{
if(Table_board[i][j].var==0)
{
setfillstyle(1,0);
rectangle(xr,yr,xl,yl);
floodfill(xr+1,yr+1,WHITE);
}
else
{
setfillstyle(0,4);
rectangle(xr,yr,xl,yl);
floodfill(xr+1,yr+1,RED);
}
xr=xr+SIZE;
xl=xl+SIZE;
}
}
y1=TOP_Y;
for(i=0;i<NUM_Y;i++)
{
for(j=0;j<NUM_X;j++)
{
if(Table_board[i][j].var==1)
return y1;
}
y1=y1+SIZE;
}
}
void setFullRow(int t_boardy)
{
int i,j,count,m,num;
num=0;
count=0;
m=(t_boardy-TOP_Y)/SIZE;
for(i=NUM_Y-1;i>=m;i--)
{
for(j=0;j<NUM_X;j++)
{
if(Table_board[i+num][j].var==1)
count++;
}
if(count==NUM_X)
{
count=0;
t_boardy=DelFullRow(i+num);
num++;
score=score+10;
ShowScore();
ShowLevel();
}
count=0;
m=(t_boardy-TOP_Y)/SIZE;
}
}
void Initialize_box(int box_numb)
{
int i,j,x,y,pre_x,pre_x1,x1,y1;
char *s="Nextbox";
x=100;
y=250;
x1=x+SIZE;
y1=y+SIZE;
pre_x=x;
pre_x1=x1;
standard=128;
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[0]&standard)
{
setfillstyle(1,4);
rectangle(x,y,x1,y1);
floodfill(x+1,y+1,WHITE);
}
else
{
setfillstyle(0,0);
rectangle(x,y,x1,y1);
floodfill(x+1,y+1,WHITE);
}
x1=x1+SIZE;
x=x+SIZE;
standard=standard/2;
}
x=pre_x;
x1=pre_x1;
y=y+SIZE;
y1=y1+SIZE;
}
standard=128;
for(i=2;i<4;i++)
{
for(j=0;j<4;j++)
{
if(shapes[box_numb].box[1]&standard)
{
setfillstyle(1,4);
rectangle(x,y,x1,y1);
floodfill(x+1,y+1,WHITE);
}
else
{
setfillstyle(0,0);
rectangle(x,y,x1,y1);
floodfill(x+1,y+1,WHITE);
}
x1=x1+SIZE;
x=x+SIZE;
standard=standard/2;
}
x=pre_x;
x1=pre_x1;
y=y+SIZE;
y1=y1+SIZE;
}
standard=128;
outtextxy(110,230,s);
}
int main()
{
int i,j,key,current_x,current_y,judge,current_box,next_box;
current_x=BEGIN_X;
current_y=BEGIN_Y;
current_box=MkNextBox();
for(i=0;i<NUM_Y;i++)
{
for(j=0;j<NUM_X;j++)
{
Table_board[i][j].var=0;
Table_board[i][j].color=0;
}
}
initialize(TOP_X,TOP_Y,NUM_X,NUM_Y);
SetTimer(newhandler);
show_box(BEGIN_X,BEGIN_Y,current_box,RED);
next_box=MkNextBox();
ShowScore();
ShowLevel();
Help();
Initialize_box(next_box);
restart:
while(1)
{
while(bioskey(1)==0)
{
if(TimerCounter>level)
{
TimerCounter=0;
judge=MoveAble(current_x,current_y,current_box,NONE);
if(judge)
{
EraseBox(current_x,current_y,current_box);
current_y=current_y+SIZE;
show_box(current_x,current_y,current_box,RED);
}
else
{
flag_newbox=1;
if(score/50==0)
{
level=5;
speed=0;
}
if(score/50==1)
{
level=4;
speed=1;
}
if(score/50==2)
{
level=3;
speed=2;
}
if(score/50==3)
{
level=2;
speed=3;
}
if(score/50==4)
{
level=1;
speed=4;
}
break;
}
}
}
if(flag_newbox)
{
if(current_y==BEGIN_Y)
{
char *s="GAME OVER";
rectangle(260,150,340,230);
outtextxy(280,190,s);
goto end;
}
setFullRow(current_y);
current_x=BEGIN_X;
current_y=BEGIN_Y;
current_box=next_box;
show_box(BEGIN_X,BEGIN_Y,current_box,RED);
next_box=MkNextBox();
Initialize_box(next_box);
flag_newbox=0;
goto restart;
}
key=bioskey(0);
switch(key)
{
case VK_RIGHT:
{
TimerCounter=0;
judge=MoveAble(current_x,current_y,current_box,RIGHT);
if(judge)
{
EraseBox(current_x,current_y,current_box);
current_x=current_x+SIZE;
show_box(current_x,current_y,current_box,RED);
}
break;
}
case VK_LEFT:
{
TimerCounter=0;
judge=MoveAble(current_x,current_y,current_box,LEFT);
if(judge)
{
EraseBox(current_x,current_y,current_box);
current_x=current_x-SIZE;
show_box(current_x,current_y,current_box,RED);
}
break;
}
case VK_UP:
{
TimerCounter=0;
judge=EddyAble(current_x,current_y,current_box);
if(judge)
{
EraseBox(current_x,current_y,current_box);
current_box=shapes[current_box].next;
show_box(current_x,current_y,current_box,RED);
}
break;
}
case VK_DOWN:
{
level=1;
break;
}
case ESC:
{
goto end;
break;
}
}
}
end:
getch();
closegraph();
return 0;
}
搜索更多相关主题的帖子: 俄罗斯方块 
2008-07-16 01:48
菜鸟选手
Rank: 1
等 级:新手上路
帖 子:132
专家分:0
注 册:2008-5-5
收藏
得分:0 
用TC的库 不如学着写SDK ..
 

算法学习群57909089
2008-07-16 02:05
lingluoz
Rank: 2
来 自:苏州科技学院
等 级:新手上路
威 望:4
帖 子:749
专家分:0
注 册:2008-2-2
收藏
得分:0 
顶一下

Murphy's Law :
If there are two or more ways to do something, and one of those ways can result in a catastrophe, then someone will do it.
2008-07-16 10:48
sxby_01
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2008-7-5
收藏
得分:0 
头晕
2008-07-16 11:04
evanstacy
Rank: 1
等 级:新手上路
帖 子:47
专家分:0
注 册:2008-7-13
收藏
得分:0 
好长的程序,现在阶段我还看不懂.

软件设计师 君羊:36405332
2008-07-16 15:01
切忌浮躁
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2008-5-28
收藏
得分:0 
没有注释,我还看到了goto
2008-07-16 16:07
zhao410159858
Rank: 1
来 自:四川
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-7-16
收藏
得分:0 
晕了
2008-07-16 16:22
d8871167
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2008-6-13
收藏
得分:0 
看晕了 ,,
2008-07-16 16:27
学不懂也要学C
Rank: 1
等 级:新手上路
帖 子:31
专家分:0
注 册:2008-7-3
收藏
得分:0 
顶一下
2008-07-16 17:17
gl88627
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2008-6-10
收藏
得分:0 
回复 6# 切忌浮躁 的帖子
你能帮我看看,能否将那个GOTO改进一下? 我是没办法了
2008-07-16 21:11
快速回复:自己写的俄罗斯方块程序,大家来看看有没有什么问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049904 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved