⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 +

📁 一个用C编的小游戏
💻
字号:
#include "graphics.h"
#include "bios.h"
#include "conio.h"
#include "stdlib.h"
#include "conio.h"

#define UP 0x4800
#define DOWN 0x5000
#define LEFT 0x4600
#define RIGHT 0x4d00
#define ESC 0x0016

static int u=290;
static int j=0;
static int zy=0;
static int f=0;
static int t=30;
static int r=0;
static int one=0;
static int two=0;
static int three=0;
static int four=0;
static int five=0;
static int six=0;

void road()
{ int k=1;
setbkcolor(7);
setcolor(15);
cleardevice();
setlinestyle(0,0,3);
while(k)
{
line(k*200,0,k*200,479);
k++;
if(k==3)
k=0;
}
setlinestyle(3,0,1);
line(300,0,300,479);
setcolor(RED);
settextstyle(0,0,1);
outtextxy(500,50,"Speed:256.75Km");
outtextxy(500,100,"Time: 0 s");

}

void car()
{
if(f==0)
{
setlinestyle(0,0,2);
setcolor(BLUE);
line(u,400,u+20,400); /*车头*/
line(u+20,400,u+30,410);
line(u+30,410,u-10,410);
line(u-10,410,u,400);
rectangle(u-10,411,u+30,461); /*车身*/
/*setfillstyle(1,BLUE);
bar(u-10,411,u+30,461);*/
}
if(j==1)
{
if(zy==19200)
{

line(u,400,u+20,400);
line(u+20,400,u+30,410);
line(u+30,410,u-10,410);
line(u-10,410,u,400);
rectangle(u-10,411,u+30,461);
/*setfillstyle(1,BLUE);
bar(u-10,411,u+30,461);*/
delay(100);

u-=5;
if(u==205)
u=210;
line(u,400,u+20,400);
line(u+20,400,u+30,410);
line(u+30,410,u-10,410);
line(u-10,410,u,400);
rectangle(u-10,411,u+30,461);
/*setfillstyle(1,BLUE);
bar(u-10,411,u+30,461);*/
j=0;
}
else if(zy==19712)
{

line(u,400,u+20,400);
line(u+20,400,u+30,410);
line(u+30,410,u-10,410);
line(u-10,410,u,400);
rectangle(u-10,411,u+30,461);
/*setfillstyle(1,BLUE);
bar(u-10,411,u+30,461);*/
delay(300);
u+=5;
if(u==375)
u=370;
line(u,400,u+20,400);
line(u+20,400,u+30,410);
line(u+30,410,u-10,410);
line(u-10,410,u,400);
rectangle(u-10,411,u+30,461);
/*setfillstyle(1,BLUE);
bar(u-10,411,u+30,461); */
j=0;
}
}
}
void tree()
{ int w,r=0;

for(w=0;w<6;w++)
{
switch(w)
{
case 0:r=one;break; /*随机画树木的位置,更具有真实感,妈的想了两个小时。*/
case 1:r=two;break;
case 2:r=three;break;
case 3:r=four;break;
case 4:r=five;break;
case 5:r=six;break;
}
line(170,t+w*100+r,150,t+30+w*100+r);
line(150,t+30+w*100+r,190,t+30+w*100+r);
line(190,t+30+w*100+r,170,t+w*100+r);
rectangle(165,t+31+w*100+r,175,t+71+w*100+r);
}
for(w=0;w<4;w++)
{
switch(w)
{
case 0:r=one;break;
case 1:r=two;break;
case 2:r=three;break;
case 3:r=four;break;
}
line(470,t+w*100+r-50,450,t+30+w*100+r-50);
line(450,t+30+w*100+r-50,490,t+30+w*100+r-50);
line(490,t+30+w*100+r-50,470,t+w*100+r-50);
rectangle(465,t+31+w*100+r-50,475,t+71+w*100+r-50);
}
}


void bustree()
{
int key=0,y=100,life=1,x,i=120,o=0;

while(key!=283 && life!=0)
{ f=1;
while(bioskey(1)==0 && life!=0)
{
rectangle(201+i,y,251+i,y+50); /*卡车轮廓*/
rectangle(191+i,y+55,261+i,y+150);
/*while(1)
{
line(i+o+200,y+56,i+o+200,y+149);
o+=10;
if(o>50)
break;
}*/
line(i+o+200,y+56,i+o+200,y+149); /*画卡车的车身上的线条*/
line(i+o+10+200,y+56,i+o+10+200,y+149);
line(i+o+20+200,y+56,i+o+20+200,y+149);
line(i+o+30+200,y+56,i+o+30+200,y+149);
line(i+o+40+200,y+56,i+o+40+200,y+149);
line(i+o+50+200,y+56,i+o+50+200,y+149);

if(t==-480)
{
randomize();
one=random(35);
two=random(35);
three=random(35);
four=random(35);
}
tree();
delay(50); /*停顿50毫秒,接下来用异或方式擦除原图*/

rectangle(201+i,y,251+i,y+50);
rectangle(191+i,y+55,261+i,y+150);

/*while(1)
{
line(i+o+200,y+56,i+o+200,y+149);
o+=10;
if(o>50)
break;
}*/
line(i+o+200,y+56,i+o+200,y+149); /*画卡车的车身上的线条*/
line(i+o+10+200,y+56,i+o+10+200,y+149);
line(i+o+20+200,y+56,i+o+20+200,y+149);
line(i+o+30+200,y+56,i+o+30+200,y+149);
line(i+o+40+200,y+56,i+o+40+200,y+149);
line(i+o+50+200,y+56,i+o+50+200,y+149);
tree();

y+=2;
t=t+3;
if(y==480) /*判断卡车是否已经在屏幕下方,让他重新出现在屏幕上方*/
{
y=-150;
i=random(120);

}
if(t==480)
{
t=-480;
}
if((y+150-400)>0 && abs((u+10)-(226+i))<56) /*判断是否撞车*/
life=0;
}
key=bioskey(0);
if(key==19200 || key==19712)
{
j=1; /*判断是否按左右键*/
zy=key;
key=0;
car();
}

}
}


main()
{ int x=0,y,i=1,key,c=0;
int gdriver=DETECT,gmode;
registerbgidriver(EGAVGA_driver);
initgraph(&gdriver,&gmode,"f:\turboc\turboc2");
setbkcolor(BLACK);
setcolor(WHITE);
settextstyle(0,0,4);
outtextxy(100,20,"TIAN YU SOFT");
setcolor(RED);
outtextxy(101,20,"TIAN YU SOFT");
settextstyle(1,0,1);
outtextxy(70,60,"This game is TianYu designed,maybe this game not good,");
outtextxy(50,80,"but the game is my first game programe.Welcome play my");
outtextxy(50,100,"game,and make friend.");
outtextxy(301,250,"Emainmicrozhujie@citiz.net");
outtextxy(301,300,"http://angel24.51.net");


getch();
cleardevice();
setcolor(GREEN);
while(i)
{
settextstyle(1,0,5);
setwritemode(XOR_PUT);
outtextxy(x,200,"MAD CAR");
delay(1000);
outtextxy(x,200,"MAD CAR");
x+=2;
if(x>200)
i=0;

}
outtextxy(x,200,"MAD CAR");
while(!kbhit())
{
setcolor(c);
outtextxy(x,200,"MAD CAR");
c++;
if(c>16)
c=0;
}
getch();
road();
car();
bustree();


setcolor(RED);
settextstyle(1,0,5);
outtextxy(20,200,"Thanks play my game");
setcolor(1);
settextstyle(0,0,6);
outtextxy(50,350,"Tian Yu Soft");
settextstyle(0,0,2);
outtextxy(400,460,"2002/9/25");
getch();
getch();
getch();
closegraph();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -