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

📄 car.cpp

📁 一个挺好玩的赛车游戏!
💻 CPP
字号:
#include<stdlib.h>
#include<iostream.h>
#include<dos.h>
#include<conio.h>
#include<graphics.h>
#include"vma.h"
int vmain();
int vmain2(int);
int chance;
void accident();
void main()
{
int gd=DETECT,gm;
int x,y;
initgraph(&gd,&gm,"");
x=getmaxx()/2;
y=getmaxy()/2;

setcolor(RED);
settextstyle(TRIPLEX_FONT,HORIZ_DIR,12);
outtextxy(x-120,y-120,"CAR");
sleep(3);
cleardevice();
settextstyle(SANS_SERIF_FONT,HORIZ_DIR,1);

outtextxy(x-80,y-115,"      KEYS ");
outtextxy(x-80,y-85,"Upper : speed up");
outtextxy(x-80,y-65,"Lower : slow down");
outtextxy(x-80,y-45,"Right  : move right  ");
outtextxy(x-80,y-25,"Left   : move left  ");
outtextxy(x-80,y-5,"Esc   : exit  ");
getch();
cleardevice();
result=vmain2(3);
r3:
if(result==1)
{
chance--;
if(chance==0)
{closegraph();exit(0);}
else
goto r3;
}
closegraph();
exit(0);
}
int m_vmain()
{
int driver=DETECT,mode;
int x,y;
int time=400,velocity;
unsigned long int timer=100000;
int distance=0;
int carter[21];
initgraph(&driver,&mode,"");
// main car
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
if(chance>=2)
bar(x-260,y+150,x-240,y+180);
if(chance>=3)
bar(x-210,y+150,x-190,y+180);
if(chance>=4)
bar(x-160,y+150,x-140,y+180);

setfillstyle(SOLID_FILL,LIGHTGRAY);
if(chance>=2)
bar(x-260+5,y+150+10,x-240-5,y+180-5);
if(chance>=3)
bar(x-210+5,y+150+10,x-190-5,y+180-5);
if(chance>=4)
bar(x-160+5,y+150+10,x-140-5,y+180-5);
	setcolor(RED);
	settextstyle(TRIPLEX_FONT,HORIZ_DIR,3);
	outtextxy(x-257,y-135,"LEVEL - 1");
	outtextxy(x+107,y-135,"Time left ___ ms");
	outtextxy(x+109,y-185,"Speed __ km/h");

delay(3);
for(int rep=0;rep<100;rep++)
{
	//moving cars
	int dodo,mov;
	dodo=rep%8;
	switch(dodo)
	{
	case 0:  mov=-8;break;
	case 1:  mov=-8;break;
	case 2:  mov=+8;break;
	case 3:  mov=+8;break;
	case 4:  mov=+8;break;
	case 5:  mov=+8;break;
	case 6:  mov=-8;break;
	case 7:  mov=-8;break;
	default: break;
	}
	if(rep==99)
	rep=0;
	distance++;
	if(timer>time)
	timer=timer-time;
	if(timer<=0)
	{accident();return 1;}
	gotoxy(69,8);
	cout<<timer;
	velocity=500-time;
	gotoxy(64,5);
	cout<<velocity;


  bar(x-70, y-14900+distance*25,x-50, y-14900+distance*25+30);
  bar(x+48+5+mov, y-1500+distance*25+10,x-5+68+mov,  y-1500+distance*25-5+30);
  bar(x-68+5+mov, y-9500+distance*25+10,x-5-48+mov, y-9500+distance*25-5+30);
bar(x-71+5+mov, y-22500+distance*25+10,x-5-51+mov, y-22500+distance*25-5+30);
  bar(x+28+5+mov, y-30000+distance*25+10,x-5+48+mov, y-30000+distance*25+30-5);
 bar(x-75+5+mov, y-28500+distance*25+10,x-5-55+mov, y-28500+distance*25-5+30);
    bar(x-53+5+mov, y-28100+distance*25+10,x-5-33+mov, y-28100+distance*25-5+30);
  //end lines
  setcolor(WHITE);
  setlinestyle(SOLID_LINE,1,3);
  line(x+75, y-30300+distance*25,x-75, y-30300+distance*25);
  line(x+75, y-30310+distance*25,x-75, y-30310+distance*25);
  line(x+75, y-30320+distance*25,x-75, y-30320+distance*25);
  setlinestyle(SOLID_LINE,1,1);

  for(int h=0;h<24;h++)
  {
  setcolor(8);
  line(x,y-240+h*100+(rep%3)*33,x,y-230+h*100+(rep%3)*33);
  setcolor(0);
  line(x-84,y-235+h*20+(rep%2)*10,x-89,y-235+h*20+(rep%2)*10);
  line(x+84,y-235+h*20+(rep%2)*10,x+89,y-235+h*20+(rep%2)*10);
  }
   //round features
  setcolor(8);
  setfillstyle(SOLID_FILL,8);
  bar(x-78, y-700+distance*25,x-58, y-700+distance*25+30);
  bar(x-38, y-1200+distance*25,x-18,  y-1200+distance*25+30);
  bar(x+48+mov, y-1500+distance*25,x+68+mov,  y-1500+distance*25+30);
  bar(x-70, y-1900+distance*25,x-50, y-1900+distance*25+30);
  bar(x-10,  y-29200+distance*25,x+10, y-29200+distance*25+30);
  bar(x-68, y-29500+distance*25,x-48, y-29500+distance*25+30);
  bar(x+28+mov, y-30000+distance*25,x+48+mov, y-30000+distance*25+30);
  setlinestyle(SOLID_LINE,1,3);
  line(x+75, y-30300+distance*25,x-75, y-30300+distance*25);
  line(x+75, y-30310+distance*25,x-75, y-30310+distance*25);
  line(x+75, y-30320+distance*25,x-75, y-30320+distance*25);
  setlinestyle(SOLID_LINE,1,1);
if(distance==1215)
rep=100;

}
sleep(4);
closegraph();
return 0;
}

⌨️ 快捷键说明

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