| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4183 人关注过本帖
标题:[原创]250行代码的俄罗斯方块游戏
只看楼主 加入收藏
LOVELOVE
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2005-5-12
收藏
得分:0 
你的坦克和方块都是同一个错误啊,都好像是说没有驱动
2005-06-26 13:00
softwarelan
Rank: 1
等 级:新手上路
帖 子:209
专家分:0
注 册:2005-6-1
收藏
得分:0 
what sad???

Not a hero until you reach The Greatwall!
2005-07-09 18:02
softwarelan
Rank: 1
等 级:新手上路
帖 子:209
专家分:0
注 册:2005-6-1
收藏
得分:0 
what side.

Not a hero until you reach The Greatwall!
2005-07-16 18:03
kvabbst
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-7-21
收藏
得分:0 
好象运行不起来也
2005-07-21 21:28
qiqi0120
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2004-8-3
收藏
得分:0 
我对你的程序很感兴趣,可以讲一下定义方块矩阵时的具体地实现方法,我不懂是怎么定义了矩阵就会和相应的方块形状相对应了。谢谢

2005-07-31 10:43
『银狼』
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2005-8-12
收藏
得分:0 
楼主加上写注释可以吗``````代码好多`````

這近一年來,沉迷于夢幻西游``````付出了太多太多,但是得到了些什麽?
2005-08-13 01:42
x86
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2005-8-30
收藏
得分:0 

楼主做得不错,,只是在画面显示上,,建议使用直接写内存的技术,,这样画面会比较清晰,不会闪烁! 发一个我自己写的贪吃蛇游戏,turbo c 2.0编译通过! #include<bios.h> #include <dos.h> #include<stdio.h> #include<conio.h> #include<stdlib.h>

#define UP 18432 #define DOWN 20480 #define LEFT 19200 #define RIGHT 19712 #define ESC 283

#define TRUE 1 #define FALSE 0

/*设置显示模式的函数*/ #define VGA256 0x13 #define TXT16 0x03 void Set_video_mode(int mode) { union REGS inregs,outregs; inregs.h.ah=0; inregs.h.al=(unsigned char)mode; int86(0x10,&inregs,&outregs); }

/*画竖线的函数VLine*/ void VLine(int y1,int y2,int x,unsigned int color){ unsigned int LineOffset,index; unsigned char far *video_buffer=(char far *)0xA0000000L; LineOffset=((y1<<8)+(y1<<6))+x; for(index=0;index<=y2-y1;index++){ video_buffer[LineOffset]=color; LineOffset+=320; }}

/*画方块的函数*/ void draw(int x,int y,int color) { unsigned char far *video_buffer=(char far *)0xA0000000L; int i,j=0; for((i=((((y<<8)+(y<<6))+x)-2));j<=4;i++) {video_buffer[i]=color; j++; } j=0; for((i=(((((y-1)<<8)+((y-1)<<6))+x)-2));j<=4;i++) {video_buffer[i]=color; j++; } j=0; for((i=(((((y+1)<<8)+((y+1)<<6))+x)-2));j<=4;i++) {video_buffer[i]=color; j++; } j=0; for((i=(((((y-2)<<8)+((y-2)<<6))+x)-2));j<=4;i++) {video_buffer[i]=color; j++; } j=0; for((i=(((((y+2)<<8)+((y+2)<<6))+x)-2));j<=4;i++) {video_buffer[i]=color; j++; } }

/*清空键盘缓冲区的函数*/ void Clear_Key_Buffer(void) {int offset; offset=peek(0x40,0x1a); pokeb(0x40,0x1c,offset); }

main(void) { unsigned int LineOffset; unsigned char far *video_buffer=(char far *)0xA0000000L; int flag=90000; int i=0; int j; int count=2; int exit=FALSE; int key; int keydown=0 ; int rax; int ray;

struct kuai {int x; int y; };

struct first {int x; int y; int left; int right; int up; int down; };

struct first head[103]={232,167,0,0,0,0, 232,172,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0, 0,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,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0}; struct first temp;

Set_video_mode(VGA256);/*设置为320*200 256色的图形模式*/

/*画游戏界面外框*/ for(i=59;i<=260;i++) {VLine(19,19,i,111); VLine(180,180,i,111); } VLine(19,180,59,111); VLine(19,180,260,111);

draw(232,167,234); draw(232,172,234); draw(232,132,222);/*an egg*/

/*游戏大循环开始!!!*/ while (!exit) {

keydown=0; if (kbhit()) { key = bioskey(0); switch(key) { case UP: if( (head[0].down!=1)&& !keydown) {head[0].up = 1; head[0].down=0; head[0].left=0; head[0].right=0; Clear_Key_Buffer(); keydown = TRUE; break;} case DOWN: if( (head[0].up!= 1)&& !keydown) {head[0].up = 0; head[0].down=1; head[0].left=0; head[0].right=0; Clear_Key_Buffer(); keydown = TRUE; break;} case LEFT: if( (head[0].right!=1)&& !keydown) {head[0].up = 0; head[0].down=0; head[0].left=1; head[0].right=0;; Clear_Key_Buffer(); keydown = TRUE; break;} case RIGHT: if( (head[0].left!= 1)&& !keydown) {head[0].up = 0; head[0].down=0; head[0].left=0; head[0].right=1; Clear_Key_Buffer(); keydown = TRUE; break;} case ESC: exit = TRUE;break;

} }

if((head[0].up ==0)&&(head[0].down==0)&&(head[0].left==0)&&(head[0].right==0)) {;} else{

temp.x=head[count-1].x;/*擦除尾巴的代码*/ temp.y=head[count-1].y;

i=1; while((count-i-1)!=(-1))/*各个方块依次获取上一个方块的地址*/ {head[count-i].x=head[count-i-1].x; head[count-i].y=head[count-i-1].y; i++; }

if(head[0].left==1) head[0].x=head[0].x-5;

if(head[0].right==1) head[0].x=head[0].x+5;

if(head[0].up==1) head[0].y=head[0].y-5;

if(head[0].down==1) head[0].y=head[0].y+5;

if(((head[0].left==1)||(head[0].right==1))&&((head[0].x<62)||(head[0].x>257))) exit=1; if(((head[0].up==1)||(head[0].down==1))&&((head[0].y<22)||(head[0].y>177))) exit=1; LineOffset=((head[0].y<<8)+(head[0].y<<6))+head[0].x; if(video_buffer[LineOffset]==234) exit=1;

if(exit==1) goto END;

/*吃蛋的代码,确保让蛇离开蛋的时候,带着蛋一起走,并改变蛋的颜色*/ else{ LineOffset=((temp.y<<8)+(temp.y<<6))+temp.x; if(video_buffer[LineOffset]==222) {count++; head[count-1].x=temp.x; head[count-1].y=temp.y;

draw(head[0].x,head[0].y,234); draw(head[count-1].x,head[count-1].y,234);

loop: rax=(random(19)+6)*10+2; ray=(random(15)+2)*10+7; for(i=0;i<count;i++) {if((rax==head[i].x)&&(ray==head[i].y)) goto loop; } draw(rax,ray,222); }

/*在遇到蛋的时候继续向前走的代码,并不改变蛋的颜色直到离开蛋!*/ else { for(i=0;i<count;i++) {LineOffset=((head[i].y<<8)+(head[i].y<<6))+head[i].x; if(video_buffer[LineOffset]==222) {draw(head[i].x,head[i].y,222); draw(temp.x,temp.y,0); }

/*没有蛋的时候*/ else {draw(head[i].x,head[i].y,234); draw(temp.x,temp.y,0); } } }

/*延时部分,各种玩家可根据自己电脑的配置来选择时间值,我的是p3 128m 的*/ if((count-2)<10) delay(90000); if(((count-2)>=10)&&((count-2)<20)) delay(85000); if(((count-2)>=20)&&((count-2)<30)) delay(80000); if(((count-2)>=30)&&((count-2)<40)) delay(75000); if(((count-2)>=40)&&((count-2)<50)) delay(70000); if(((count-2)>=50)&&((count-2)<60)) delay(65000); if(((count-2)>=60)&&((count-2)<70)) delay(60000); if(((count-2)>=70)&&((count-2)<80)) delay(55000); if(((count-2)>=80)&&((count-2)<90)) delay(50000); if(((count-2)>=90)&&((count-2)<100)) delay(45000);

if(count==102) {exit=1; flag=1; }

} } }

END: Set_video_mode(TXT16); if(flag==1) {window(26,10,80,15); textcolor(1102); textbackground(000); cprintf(" Congratulation!!!"); window(13,12,80,17); textcolor(0104); cprintf("The snake has eaten 100 eggs, You are the winner!!!"); window(2,14,80,19); textbackground(000); cprintf("----------------------------------------------------------------------"); window(2,15,80,20); textcolor(0102); cprintf("If you have any advice for this game,please tell me by the next email:"); window(10,16,60,21); textcolor(0102); cprintf(" ************** kikix86@163.com ************** "); textcolor(0100);

} else { window(30,10,80,15); textcolor(1111); textbackground(001); textmode(800*600); cprintf("GAME OVER"); window(23,12,80,17); cprintf("The snake has eaten %d eggs!!!",count-2); window(2,14,80,19); textbackground(000); cprintf("----------------------------------------------------------------------"); window(2,15,80,20); textcolor(0102); cprintf("If you have any advice for this game,please tell me by the next email:"); window(10,16,60,21); textcolor(0102); cprintf(" ************** kikix86@163.com ************** "); textcolor(0100); }

getche();

} 

2005-08-30 22:56
健滓
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2005-9-14
收藏
得分:0 
2005-09-14 23:24
wdufo
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-9-15
收藏
得分:0 
Linker Error: Undefined symbol '_EGAVGA_driver' in module RUSSIA.C

???
2005-09-19 16:24
plftzk
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2005-12-27
收藏
得分:0 

那里看不风了

2005-12-27 18:03
快速回复:[原创]250行代码的俄罗斯方块游戏
数据加载中...
 
   



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

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