Linux街机游戏源码.doc_第1页
Linux街机游戏源码.doc_第2页
Linux街机游戏源码.doc_第3页
Linux街机游戏源码.doc_第4页
Linux街机游戏源码.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

C语言编的街机游戏,全部源代码下载,这个是仿LINUX下KTron的游戏,已有其大部分功能 时间 : 2007-02-13 作者:佚名 编辑:本站 点击: 2650 评论 -综合 资源 电子书 社区 *游戏说明*Trone V0.1仿LINUX下街机游戏KTron。其实写本游戏的动机就是我一个朋友特别喜欢linux下的KTron这个游戏,但在WINDOWS下又没找到,而我朋友又不太熟悉LINUX操作,所以我就花了点时间写了Trone,Trone这个名字也是源于KTron。注意:此游戏需要EGAVGA.BGI文件才能运行,该文件在turboc2目录下可找到。游戏简介这是一个双人玩的策略游戏,游戏有两个点,第一个游戏者可以按R,G,F,D控制第一个点的走向,第两个游戏都可以按四个光标键控制第二个点的走向,谁先碰到边界或已走的路线便输,祝大家玩得开心!有任何问题或建议请与我联系。此游戏可任意复制,作者保留所有权力!如果你想要源代码,那么请发邮件给我。请不要删除此文件,有新功能增加可加在下面:Trone V0.1功能简介游戏者1控制键:R,F,D,G游戏者2控制键:UP,DOWN,LEFT,RIGHTF1:查看帮助信息F2:设定游戏速度等级,0为最快,1为正常,2最慢F3:设定游戏者1的颜色,有15种颜色可以选择,黑色是背景色,不能选F4:设定游戏者2的颜色F5:继续游戏。Author:jadewater(gaowenfeng)email:QQ:182824199如果这里不能下载你可以发邮件给我,其中包括4个文件:Trone.c(源代码),Trone.exe(已编译连接游戏文件),EGAVGA.BGI,游戏说明.txt*这个游戏已编译成可执行文件,可以在附件里找到,如果你不能编译的话可以与我联系,我可以把已编译的程序与源文件全发给你。下面的全是原代码。转载请注明作者,谢谢!共享是这个时代的主题!:)*#include #include #include #include #include #include #include /* 功能键设置 */#define ESC 0x001b /* 退出游戏 */#define F1 0x3b00 /* 查看帮助信息,调用HelpMassage()函数 */#define F2 0x3c00 /* 设定游戏速度等级,调用Set_Level()函数 */#define F3 0x3d00 /* 设定游戏者1的颜色,调用Set_Color()函数 */#define F4 0x3e00 /* 设定游戏者2的颜色,调用Set_Color()函数 */#define F5 0x3f00 /* 以下功能键暂时保留,如果增加功能可使用 */#define F6 0x4000#define F7 0x4100#define F8 0x4200#define F9 0x4300#define F10 0x4400/* Player1 hot key 游戏者1热键上下左右分别用RFDG控制 */#define RIGHT1 71#define LEFT1 68#define UP1 82#define DOWN1 70/* Player2 hot key 游戏者2热键,四个光标键控制方向 */#define RIGHT 0x4d00#define LEFT 0x4b00#define UP 0x4800#define DOWN 0x5000/* 定义画方框的坐标X,Y,以及颜色Color,Draw为是(1)否(0)已走过 */struct information int color,draw; int x,y; ;typedef struct information INFOR;/* 记录游戏者在把在位置,X与Y其实就是全局数组coordinate的两个下标 */struct playerxy int x,y; ;typedef struct playerxy CurrentCoor;/* 此全局数组是记录画每个框的坐标及颜色以及是否已走过 */INFOR coordinate8060;time_t Timeout=1; /* 限制游戏的快慢,可用Set_Level()设定 */int size=8,maxX=79,maxY=56; /* size定义画框的大小,单位为像素,maxX,maxY为数组coordinate下标的最大值 */* BackColor为游戏背景色,Player1Color与Player2Color为游戏者默认颜色,可调用Set_Color()函数设定 */int BackColor=BLACK,Player1Color=WHITE,Player2Color=LIGHTRED; /* 初始化图形模式 */void InitialGraphics(void) int graphdriver=VGA,graphmode=VGAHI; int errorcode; initgraph(&graphdriver,&graphmode,); errorcode=graphresult(); if(errorcode!=grOk) printf(Graphics error:%sn,grapherrormsg(errorcode); GoodBye(); /* 退出游戏显示提示信息,只有不能初始化图形界面才会调用此函数 */int GoodBye(void) printf(Thank you very much!n); printf(If you have any question,n); printf(Please send email to me: or Add QQ:182824199n); GetKey(); exit(0);/* 初始化游戏界面 */void InitFace(void) setbkcolor(BackColor); cleardevice(); setcolor(WHITE); rectangle(0,0,639,479); setcolor(LIGHTGREEN); rectangle(3,3,636,452); setcolor(LIGHTRED); rectangle(3,455,250,476); rectangle(253,455,636,476);/* 初始化全局数组coordinate */void InitCoordinate(void) int x,y; for(x=0;xmaxX;x+) for(y=0;yx=maxX/3; player2-x=maxX/3*2; player1-y=maxY/2; player2-y=maxY/2;/* 画框函数,player为画框位置,who为哪一个游戏者 */void Drawbar(CurrentCoor player,int who) int x,y; /* 根据游戏者所在coordinate的下标位置取出在屏幕上的位置 */ x=coordinateplayer.xplayer.y.x; y=coordinateplayer.xplayer.y.y; if(who=1) setfillstyle(1,Player1Color); coordinateplayer.xplayer.y.color=Player1Color; else setfillstyle(1,Player2Color); coordinateplayer.xplayer.y.color=Player2Color; bar(x,y,x+7,y+7); coordinateplayer.xplayer.y.draw=1;/* 帮助信息,按F1调用此函数 */void HelpMassage(void) setfillstyle(1,WHITE); bar(150,160,500,340); setcolor(LIGHTRED); rectangle(152,162,498,338); setcolor(BLACK); rectangle(154,164,496,180); rectangle(154,182,496,336); setcolor(GREEN); outtextxy(280,170,Trone V0.1); setcolor(BLACK); outtextxy(160,190,Player1 control key:); outtextxy(160,200,Player2 control key:); outtextxy(160,220,Help: Level: Exit:); outtextxy(160,230,Player color:); outtextxy(160,250,Author:); outtextxy(160,260,E_mail:); outtextxy(160,270,OICQ :); setcolor(RED); outtextxy(330,190,r,f,d,g); outtextxy(330,200,up,down,left,right); outtextxy(160,220, F1 F2 Esc); outtextxy(160,230, F3/F4); outtextxy(220,250,GaoWenfeng); outtextxy(220,260,); outtextxy(220,270,182824199); setcolor(BLUE); outtextxy(175,290,If you have any question or modify these); outtextxy(160,300,code,Please send email to me. Thank you); outtextxy(160,310,play this game!); setcolor(BLACK); outtextxy(410,320,02/04/2004);/* 获取按键,如果低八位非0则为ASCII码,如为0则为控制键 */int GetKey(void) int key; key=bioskey(0); if(key Timeout) /* 如果超过游戏间隔则开始画 */ front_time=current_time; if(player1fx=RIGHT1 | player1fx=LEFT1) /* 如果现在方向为左或右则只有按下上下键才改变方向,反之相同 */ if(currentfx1=UP1 | currentfx1=DOWN1) if(currentfx1=UP1) player1.y-=1; else player1.y+=1; player1fx=currentfx1; else if(player1fx=RIGHT1) player1.x+=1; else player1.x-=1; else if(player1fx=UP1 | player1fx=DOWN1) if(currentfx1=RIGHT1 | currentfx1=LEFT1) if(currentfx1=RIGHT1) player1.x+=1; else player1.x-=1; player1fx=currentfx1; else if(player1fx=UP1) player1.y-=1; else player1.y+=1; if(player2fx=RIGHT | player2fx=LEFT) if(currentfx2=UP | currentfx2=DOWN) if(currentfx2=UP) player2.y-=1; else player2.y+=1; player2fx=currentfx2; else if(player2fx=RIGHT) player2.x+=1; else player2.x-=1; else if(player2fx=UP | player2fx=DOWN) if(currentfx2=RIGHT | currentfx2=LEFT) if(currentfx2=RIGHT) player2.x+=1; else player2.x-=1; player2fx=currentfx2; else if(player2fx=UP) player2.y-=1; else player2.y+=1; if(player1.x=maxX |player1.y=maxY | coordinateplayer1.xplayer1.y.draw=1) /* 判断是否到边界或是已走路,如果是则退出,否则画框 */ die1=1; die=1; else Drawbar(player1,1); if(player2.x=maxX | player2.y=maxY | coordinateplayer2.xplayer2.y.draw=1) die2=1, die=2; else Drawbar(player2,2); if(die1 & die2) die=3; return die;/* 设定游戏等级函数 */void Set_Level(void) int key,pass=0,i=0; clock_t front_time,current_time; front_time=clock(); setfillstyle(1,WHITE); bar(180,150,460,300); setcolor(LIGHTRED); rectangle(182,152,458,298); setcolor(BLACK); rectangle(184,154,456,174); rectangle(184,176,456,296); setcolor(RED); outtextxy(260,160,Level Setting); setcolor(BLACK); outtextxy(190,200,Here have three level:); outtextxy(190,260,Please input a number0,1,2:); setcolor(BLUE); outtextxy(200,220,0: fast); outtextxy(200,230,1: normal); outtextxy(200,240,2: slow); while(pass=0) if(bioskey(1) key=GetKey(); if(key=0 | key=1 | key=2) /* 通过设置全局变量Timeout来确定游戏速度 */ pass=1; if(key=0) Timeout=0; else if(key=1) Timeout=1; else Timeout=2; else setcolor(LIGHTRED); outtextxy(190,280,Please input 0,1,2!); else current_time=clock(); if(current_time-front_time6) /* 光标闪动效果,不知谁有更有效的方法? */ front_time=current_time; i=(i+1)%2; if(i=0) setcolor(BLACK); else setcolor(WHITE); outtextxy(420,260,_); /* 设置游戏者颜色,其实就是设置全局变量Player2Color与Player1Color,根据who来判断哪一个游戏者 */void Set_Color(int who) int pass=0,color,key,i=0; int x,y,count; clock_t front_time,current_time; setfillstyle(1,WHITE); bar(150,160,500,340); setcolor(LIGHTRED); rectangle(152,162,498,338); setcolor(BLACK); rectangle(154,164,496,180); rectangle(154,182,496,336); setcolor(LIGHTRED); if(who=1) outtextxy(245,170,Player1); else if(who=2) outtextxy(245,170,Player2); setcolor(GREEN); outtextxy(245,170, Color Setting); setcolor(BLACK); outtextxy(160,190,You can select underside color:); outtextxy(160,300,Please input color number1-f:); for(count=1;count=1& key=A & key6) front_time=current_time; i=(i+1)%2; if(i=0) setcolor(BLACK); else setcolor(WHITE); outtextxy(410,300,_); if(who=1) Player1Color=color; else if(who=2) Player2Color=color;/* 确认退出函数,返回1(退出)与0(继续游戏) */int Exit_Game(void) int Quit=-1; int key,i=0; clock_t front_t ime,current_time; front_time=clock(); setfillstyle(1,WHITE); bar(180,150,460,300); setcolor(LIGHTRED); rectangle(182,152,458,298); setcolor(BLACK); rectangle(184,154,456,174); rectangle(184,176,456,296); setcolor(LIGHTRED); outtextxy(280,160,Exit Trone); setcolor(BLACK); outtextxy(215,190,Thanks play this game! If you); outtextxy(200,205,want to modify this game code,); outtextxy(200,220,please tell me or send email to); outtextxy(200,235,me! Thank you!); setcolor(RED); outtextxy(200,255,Author:GaoWenfeng); outtextxy(200,265,Email: ); setcolor(LIGHTRED); outtextxy(200,280,Really quit game(Y/N)?:); while(Quit=-1) if(bioskey(1) key=GetKey(); if(key=Y) Quit=1; else if(key=N) Quit=0; else current_time=clock(); if(current_time-front_time6) front_time=current_time; i=(i+1)%2; if(i=0) setcolor(BLACK); else setcolor(WHITE); outtextxy(385,280,_); return Quit;/* 游戏控制函数,完成一系列初始化操作,最后调用ManageMove函数,完后便显示谁胜及一些快捷键 */void GameManage(void) int Quit=0,key,die,i=1; int start_game; CurrentCoor player1,player2; /* 记录游戏者下标位置 */ clock_

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论