谁有turbo c 编的俄罗斯方块游戏源代码 我急用~~200都给你!
如题! 问题点数:100、回复次数:11Top
1 楼comptometer(valor)回复于 2003-04-09 15:48:33 得分 0
你的email地址
我给你发一个,保管有用:)Top
2 楼comptometer(valor)回复于 2003-04-09 16:02:25 得分 0
这个有一个很好的,包括了说明的文档和源代码
http://shchenchang.top263.net/download/Russia_Doc/Russia_Doc.zipTop
3 楼yizhenfeng(一阵风)回复于 2003-04-09 16:04:33 得分 0
这个:
http://www.coboo.com/softdown/download.asp?downid=1&id=400Top
4 楼lifanxi(Byron)回复于 2003-04-09 19:58:52 得分 100
给你个能用的,不是不是我写的。
#include "stdio.h"
#include"stdlib.h"
#include"dos.h"
#include"conio.h"
#define ENTER 0x1c0d
#define ESC 0x011b
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define UP 0x4800
#define DOWN 0x5000
#define HOME 0x4700
#define END 0x4f00
#define EMPTY 0
#define BRICK 1
#define WALL 2
#define MOVE_DOWN 0
#define MOVE_LEFT 1
#define MOVE_RIGHT 2
#define REVOLVE 3
#define YES 1
#define NO 0
#define GET 0
#define PUT 1
#define CAL 2
#define BACKGROUND 19
#define SHADE_ATTR 8
#define BAR_ATTR 0x6e
#define BOARD_WIDTH 10
#define BOARD_HEIGHT 18
#define BOARD_LEFT 16
#define BOARD_TOP 3
#define BOARD_ATTR 0x7e
#define BOARD_BACK 7
#define SCORE_LEFT 49
#define SCORE_TOP 14
#define SCORE_WIDTH 14
#define SCORE_HEIGHT 6
#define SCORE_ATTR 46
#define SCORE1 1
#define SCORE2 100
#define NEXT_LEFT 49
#define NEXT_TOP 4
#define NEXT_WIDTH 14
#define NEXT_HEIGHT 6
#define NEXT_ATTR 0x7e
#define TIME 0x1c
void new_game();
void generate();
void show_next(int,int);
void draw(int,int);
int moveable(int);
void move(int);
void brick_reach_bottom();
int game_over();
void score(int);
int cale(int);
void interrupt newtimer(void);
void interrupt(*oldtimer)(void);
void install(void interrupt(*)(),int);
void clrkey();
void closecur();
void opencur();
int brick_set[6][6]=
{1,1,1,1,0,0,
1,1,1,0,1,0,
1,1,1,0,0,1,
1,1,0,0,1,1,
0,1,1,1,1,0,
1,1,0,1,1,0,};
int array[BOARD_HEIGHT+2][BOARD_WIDTH+2],row_down_offset[BOARD_HEIGHT];
int xp,yp,brick_no,down_speed,ticket,time_set,over;
int next_brick_no,next_set=2,reach_bottom= NO;
unsigned int key,current_score,high_score=0,level=10000;
void main()
{
clrscr();
closecur();
score(GET);
textattr(SCORE_ATTR);
gotoxy(SCORE_LEFT+3,SCORE_TOP+4);
cprintf("0");
oldtimer=getvect(TIME);
install(newtimer,TIME);
while(1)
{
new_game();
do
{
generate();
over=1;
reach_bottom=NO;
while(over||!reach_bottom)
{
if(bioskey(1)!=0)
key=bioskey(0);
else
key=0;
clrkey();
switch(key)
{
case ESC:
textattr(7);
clrscr();
install(oldtimer,TIME);
opencur();
exit(0);
case HOME:
new_game();
generate();
reach_bottom=YES;
break;
case END:
bioskey(0);
break;
case LEFT:
if(moveable(MOVE_LEFT))
move(MOVE_LEFT);
break;
case RIGHT:
if(moveable(MOVE_RIGHT))
move(MOVE_RIGHT);
break;
case UP:
case ENTER:
if(moveable(REVOLVE))
move(REVOLVE);
break;
case DOWN:
while(moveable(MOVE_DOWN))
move(MOVE_DOWN);
reach_bottom=YES;
break;
default:
reach_bottom =!moveable(MOVE_DOWN);
if(!reach_bottom)
{
while(bioskey(1)==0 && time_set<(10-down_speed));
if(time_set>=(10-down_speed))
{
move(MOVE_DOWN);
time_set=0;
}
}
if(time_set>(10-down_speed))
over=0;
break;
}
}
brick_reach_bottom();
score(CAL);
}
while(!game_over());
score(PUT);
}
}
Top
5 楼lifanxi(Byron)回复于 2003-04-09 19:59:14 得分 0
void clrkey()
{
union REGS r;
r.h.ah=0x0c;
intdos(&r,&r);
}
void interrupt newtimer(void)
{(*oldtimer)();
time_set++;
if(time_set>1000) time_set=0;
}
void install(void interrupt(*int_add)(),int int_num)
{
disable(); setvect(int_num,int_add);
enable();}
void new_game()
{
int i,j;
randomize();
current_score=0;
for(i=0;i<BOARD_HEIGHT+2;i++)
for(j=0;j<BOARD_WIDTH+2;j++)
array[i][j]=EMPTY;
next_set=1;
gotoxy(SCORE_LEFT+3,SCORE_TOP+6);
cprintf("%-12ld",(long)0);
time_set=0;
down_speed=0;
textattr(SCORE_ATTR);
gotoxy(SCORE_LEFT+3,SCORE_TOP+4);
cprintf("0");
draw(WALL,15);
}
void generate()
{
int i,j;
if(next_set)
{
if(next_set==1) show_next(next_brick_no,BOARD_BACK);
next_brick_no=random(7);
next_set=0;
}
brick_no=next_brick_no;
next_brick_no=random(7);
show_next(next_brick_no,next_brick_no+8);
if(brick_no<6)
{
for (i=0;i<2;i++)
for(j=4;j<7;j++)
array[i][j]=brick_set[brick_no][i*3+j-4];
xp=5;
yp=0;
}
else
{
for(j=3;j<7;j++)
array[0][j]=BRICK;
xp=4;
yp=0;
ticket=1;
}
draw(BRICK,15);
}
void show_next(int no,int color)
{
int i,j;
textattr(BAR_ATTR);
textcolor(0);
for(i=0;i<2;i++)
for(j=0;j<4;j++)
{
gotoxy(NEXT_LEFT+4+j*2,NEXT_TOP+4+i);
cprintf("%c%c",0xdb,0xdb);
}
textattr(BAR_ATTR);
textcolor(color);
if(no<6)
{
for(i=0;i<2;i++)
for(j=0;j<3;j++)
if(brick_set[no][i*3+j])
{
gotoxy(NEXT_LEFT+5+j*2,NEXT_TOP+4+i);
cprintf("%c%c",0xdb,0xdb);
}
}
else
for(i=0;i<4;i++)
{
gotoxy(NEXT_LEFT+4+i*2,NEXT_TOP+4);
cprintf("%c%c",0xdb,0xdb);
}
}
void draw(int mode,int color)
{
int i,j;
textattr(BOARD_ATTR);
textcolor(color);
switch(mode)
{
case WALL:
for(i=0;i<BOARD_HEIGHT;i++)
for(j=0;j<BOARD_WIDTH;j++)
{
gotoxy(BOARD_LEFT+j*2+1,BOARD_TOP+i+1);
if(array[i][j]>=mode)
{textcolor(array[i][j]);
cprintf("%c%c",0xdb,0xdb);}
if (array[i][j] ==EMPTY)
cprintf(" ");}
break;
case BRICK:
if(color!=BOARD_BACK) textcolor(brick_no+8);
for(i=-1;i<3;i++)
for(j=-1;j<3;j++)
if (xp+j>=0&& yp+i>=0)
{gotoxy(BOARD_LEFT+(xp+j)*2+1,BOARD_TOP+yp+i+1);
if(array[yp+i][xp+j]==mode)
cprintf("%c%c",0xdb,0xdb);}
break;}
gotoxy(1,25);}
int moveable(int mode)
{
int i,j,moveable=YES;
switch(mode)
{
case MOVE_DOWN:
for(j=0;j<BOARD_WIDTH && moveable;j++)
moveable=!(array[BOARD_HEIGHT-1][j]==BRICK);
for(i=BOARD_HEIGHT-2;i>=0 && moveable;i--)
for(j=0;j<BOARD_WIDTH && moveable;j++)
moveable=!(array[i][j]==BRICK && array[i+1][j]>=WALL);
break;
case MOVE_LEFT:
for(i=0;i<BOARD_HEIGHT && moveable;i++)
moveable=!(array[i][0]==BRICK);
for(i=0;i<BOARD_HEIGHT && moveable;i++)
for(j=1;j<BOARD_WIDTH && moveable;j++)
moveable=!(array[i][j]==BRICK && array[i][j-1]>=WALL);
break;
case MOVE_RIGHT:
for(i=0;i<BOARD_HEIGHT && moveable;i++)
moveable=!(array[i][BOARD_WIDTH-1]==BRICK);
for(i=0;i<BOARD_HEIGHT && moveable;i++)
for(j=1;j<BOARD_WIDTH-1&& moveable;j++)
moveable=!(array[i][j]==BRICK && array[i][j+1]>=WALL);
break;
case REVOLVE:
switch(brick_no)
{
case 0:
case 1:
case 2:
case 3:
case 4:
if(yp==0||yp==BOARD_HEIGHT-1||xp==0||xp==BOARD_WIDTH-1)
moveable=NO;
else
for(i=-1;j<2&&moveable;i++)
for(j=-1;j<2&&moveable;j++)
moveable=!(array[yp+i][xp+j]==BRICK&&array[yp+j][xp-i]>=WALL);
break;
case 5:
moveable=NO;
break;
case 6:
if((yp==0||yp==BOARD_HEIGHT-2)&&ticket||(xp==0||xp>=BOARD_WIDTH-2)&&!ticket)
moveable=NO;
else
for(i=-1;i<3&&moveable;i++)
moveable=!(array[yp][xp+i]+array[yp+i][xp]>=BRICK+WALL);
break;
}
break;
}
return moveable;
}
void move(int mode)
{
int i,j;
draw(BRICK,BOARD_BACK);
switch(mode)
{
case MOVE_DOWN:
for(i=BOARD_HEIGHT-2;i>=0;i--)
for(j=0;j<BOARD_WIDTH;j++)
if(array[i][j]==BRICK)
{
array[i][j]=EMPTY;
array[i+1][j]=BRICK;
}
yp++;
break;
case MOVE_LEFT:
for(i=0;i<BOARD_HEIGHT;i++)
for(j=0;j<BOARD_WIDTH;j++)
if(array[i][j]==BRICK)
{
array[i][j]=EMPTY;
array[i][j-1]=BRICK;
}
xp--;
break;
case MOVE_RIGHT:
for(i=0;i<BOARD_HEIGHT;i++)
for(j=BOARD_WIDTH-2;j>=0;j--)
if(array[i][j]==BRICK)
{
array[i][j]=EMPTY;
array[i][j+1]=BRICK;
}
xp++;
break;
case REVOLVE:
switch(brick_no)
{
case 0:
case 1:
case 2:
case 3:
case 4:
for(i=-1;i<2;i++)
for(j=-1;j<2;j++)
if((array[yp+i][xp+j]&0x0f)==BRICK)
array[yp+j][xp-i]|=0x10;
for(i=-1;i<2;i++)
for(j=-1;j<2;j++)
array[yp+i][xp+j]>>=4;
break;
case 5:
break;
case 6:
if(ticket)
for(i=-1;i<3;i++)
{
array[yp][xp+i]=EMPTY;
array[yp+i][xp]=BRICK;
}
else
for(i=-1;i<3;i++)
{
array[yp+i][xp]=EMPTY;
array[yp][xp+i]=BRICK;
}
ticket=!ticket;
break;
}
break;
}
draw(BRICK,15);
}
void brick_reach_bottom()
{
int i,j,row_brick_num,down_offset=0;
for(i=BOARD_HEIGHT-1;i>=0;i--)
{
row_brick_num=0;
for(j=0;j<BOARD_WIDTH;j++)
{
if (array[i][j]==BRICK)
array[i][j]=brick_no+8;
if (array[i][j])
row_brick_num++;
}
if(row_brick_num==(BOARD_WIDTH))
{
down_offset++;
row_down_offset[i]=0;
}
else
row_down_offset[i]=down_offset;
}
for(i=BOARD_HEIGHT-1;i>=0;i--)
if((down_offset=row_down_offset[i])>0)
{
for(j=0;j<BOARD_WIDTH;j++)
{
array[i+down_offset][j]=array[i][j];
array[i][j]=EMPTY;
}
}
if(down_offset>0)
draw(WALL,15);
}
int game_over()
{
int i,j,game_over=NO;
for(i=0;i<2 && !game_over;i++)
for(j=0;j<BOARD_WIDTH&&!game_over;j++)
game_over=(array[0][j]>=WALL);
return game_over;
}
Top
6 楼lifanxi(Byron)回复于 2003-04-09 19:59:19 得分 0
void score(int mode)
{
FILE *fp;
textattr(SCORE_ATTR);
switch(mode)
{
case GET:
if((fp=fopen("score","rb"))!=NULL)
{
fscanf(fp,"%d",&high_score);
fclose(fp);
}
gotoxy(SCORE_LEFT+3,SCORE_TOP+2);
cprintf("%d",high_score);
break;
case PUT:
if(current_score>high_score)
{
high_score=current_score;
if((fp=fopen("score","wb+"))!=NULL)
{
fprintf(fp,"%d",high_score);
fclose(fp);
}
}
break;
case CAL:
current_score+=calc(row_down_offset[0])*SCORE2+SCORE1;
gotoxy(SCORE_LEFT+3,SCORE_TOP+6);
cprintf("%d",current_score);
if(current_score>high_score)
{
gotoxy(SCORE_LEFT+3,SCORE_TOP+2);
cprintf("%d",current_score);
}
if(current_score>level)
{
down_speed++;
level+=1000;
textattr(SCORE_ATTR);
gotoxy(SCORE_LEFT+2,SCORE_TOP+4);
cprintf("%2d",down_speed);
}
break;
}
}
int calc(int lines)
{
int i,r=1;
for(i=0;i<lines;i++)
r*=2;
return(r-1);
}
void closecur()
{
union REGS r;
r.h.ah=1;
r.h.ch=0x20;
int86(0x10,&r,&r);
}
void opencur()
{
union REGS r;
r.h.ah=1;
r.h.ch=12;
r.h.cl=13;
int86(0x10,&r,&r);
}
Top
7 楼fiveyes(天才的剽窃如羚羊挂角无迹可寻)回复于 2003-04-09 20:09:48 得分 0
这里有个文档,是关于如何使用TC2编写俄罗斯方块游戏的详细讨论,后面还附有一个完整的源码:
http://like.nease.net/c/els.txt
它来自这个C站点:
http://like.nease.net/tc.htm
我是用google搜索到的,建议你也用一下,会有你需要的东西。Top
8 楼yizhenfeng(一阵风)回复于 2003-04-09 20:56:50 得分 0
to lifanxi(Byron) :
太狠了吧,几分钟没来看,原码都贴出来了,抢饭碗哪!Top
9 楼fangrk(加把油,伙计!)回复于 2003-04-09 21:04:27 得分 0
你去google搜索一下怕没有吗?Top
10 楼yizhenfeng(一阵风)回复于 2003-04-09 21:06:54 得分 0
看看这个:
http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=16967
如下:
http://www.coboo.com/softdown/download.asp?downid=1&id=400
http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=16967
http://www.csdn.net/cnshare/soft/openfile.asp?kind=1&id=17390
tc源码:
http://llf.hanzify.org/llf/studio/game.zipTop
11 楼Frank001(Frank)回复于 2003-04-09 23:04:29 得分 0
这东西网上太多了,估计我的lib里搜出来都不止一个。
Top




