1.c?语言源c语言行???Դ??400??
2.求C语言小游戏源程序
c????Դ??400??
============赛车游戏=====================
#include <math.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <graphics.h>
static int c=1;
static int e=0;
static int u=0;
static int v=0;
static int x=1;
static int y=0;
static int j=-;
static int i;
static int b;
void begin(void)
{
int xmax, ymax;
int startx,starty,endx,endy;
setbkcolor(WHITE);
xmax = getmaxx();
ymax = getmaxy();
endx=;endy=;
startx=;starty=;
setcolor(RED);
settextstyle(1,HORIZ_DIR,4);
outtextxy(,,"Bus Bus Bus");
outtextxy(,,"Made by PU BIN.");
setlinestyle(SOLID_LINE,0,3);
setwritemode(XOR_PUT);
setcolor(GREEN);
while(startx<xmax&&starty<ymax)
{
rectangle(startx,starty,endx,endy);
delay(4);
rectangle(startx,starty,endx,endy);
startx+=2;
starty+=startx*startx/;
endx=startx+;
endy=starty+;
sound(startx*);
delay();
nosound();
}
getch();
cleardevice();
}
void road(void)
{
int h;
for(h=0;h<4;h++)
line(+h*,0,+h*,);
for(h=0;h<3;h++)
{
setlinestyle(3,0,1);
line(+h*,0,+h*,);
settextstyle(1,HORIZ_DIR,3);
}
settextstyle(1,HORIZ_DIR,4);
setcolor(RED);
outtextxy(,,"PASS");
outtextxy(,,"1");
setcolor();
setlinestyle(SOLID_LINE,0,3);
rectangle(,,,);
outtextxy(,,"Ready,Begin!");
}
void math(void)
{
settextstyle(1,HORIZ_DIR,4);
setcolor(RED);
if(x==2)
{
outtextxy(,,"1");
outtextxy(,,"2");
}
else if(x==3)
{
outtextxy(,,"2");
outtextxy(,,"3");
}
else if(x==4)
{
outtextxy(,,"3");
outtextxy(,,"4");
}else if(x==5){
outtextxy(,,"4");
outtextxy(,,"5");
}else if(x==6){
outtextxy(,,"5");
outtextxy(,,"6");
}else if(x==7){
outtextxy(,,"6");
outtextxy(,,"7");
}else if(x==8){
outtextxy(,,"7");
outtextxy(,,"8");
}else if(x==9){
outtextxy(,,"8");
outtextxy(,,"9");
}else if(x==){
outtextxy(,,"9");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
}else if(x==){
outtextxy(,,"");
outtextxy(,,"");
y=1; v=1;
}
}
void bus2(void)
{
setcolor(BLUE);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
setcolor(5);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
if((b==0x4b)&&(c>0))
c--;
else if((b==0x4d)&&(c<2))
c++;
else if((b==0x)&&(c<2))
sleep(1);
setcolor(BLUE);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
rectangle(+c*,,+c*,);
setcolor(5);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
line(+c*,,+c*,);
setcolor(BLUE);
}
void light(void)
{
rectangle(,,,);
floodfill(,,BLUE);
setfillstyle(1,RED);
fillellipse(,,,);
sound();
delay();
nosound();
delay();
setfillstyle(1,YELLOW);
fillellipse(,,,);
sound();
delay();
nosound();
delay();
setfillstyle(1,GREEN);
fillellipse(,,,);
sound();
delay();
nosound();
delay();
setcolor();
setlinestyle(SOLID_LINE,0,3);
rectangle(,,,);
outtextxy(,,"Ready,Begin!");
}
void brock(void)
{
if((c==i)&&(j>4)&&(j<))
e=1;
}
void tree(void)
{
int w;
int poly[];
setcolor();
for (w=-3;w<3;w=w+2)
{
line(,-+u*+w*,,+u*+w*);
line(,-+u*+w*,,+u*+w*);
line(,-+u*+w*,,+u*+w*);
line(,-+u*+w*,,+u*+w*);
line(,-9+u*+w*,,+u*+w*);
line(,-9+u*+w*,,+u*+w*);
}
for (w=-2;w<3;w=w+2)
{
poly[0] = ;
poly[1] = u*+w*;
poly[2] =;
poly[3] = +u*+w*;
poly[4] =;
poly[5] =+u*+w* ;
poly[6] =;
poly[7] =u*+w* ;
poly[8] =;
poly[9] =-+u*+w*;
poly[] =;
poly[] =-+u*+w* ;
poly[] = poly[0];
poly[] = poly[1];
drawpoly(7,poly);
}
}
void bus1(void)
{
randomize();
i=random(3);
setlinestyle(SOLID_LINE,0,3);
do
{
do
{
if((x!=7)&&(x!=)&&(x!=))
setcolor(x);
else
setcolor(2);
rectangle(+i*,j*,+i*,+j*);
rectangle(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
tree();
sound(j*);
delay();
nosound();
if((x!=7)&&(x!=)&&(x!=))
setcolor(x);
else
setcolor(2);
rectangle(+i*,j*,+i*,+j*);
rectangle(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
line(+i*,+j*,+i*,+j*);
tree();
u++;
j++;
brock();
if(e==1)
{
j=;
y=1;
u=;
v=0;
}
}while((bioskey(1)==0)&&(j<=)&&(u<=));
if((j<=)&&(u<=))
/* function 0 returns the key that is waiting */
{
b= bioskey(0);
bus2();
}
else if(u<=)
{
j=-;
randomize();
i=rand()%3;
x++;
math();
setcolor(x);
}
else
u=0;
}while(y!=1);
}
void end()
{
if (v==1)
{
for(j=0;j<;j++)
{
rectangle(,j*5,,+j*5);
settextstyle(1,HORIZ_DIR,4);
outtextxy(,+j*5,"STOP! You win!");
sound(+j*);
delay(2);
nosound();
setlinestyle(SOLID_LINE,0,3);
rectangle(,j*5,,+j*5);
outtextxy(,+j*5,"STOP! You win!");
}
closegraph();
printf("\n\nyou win!");
}
else if(v==0 )
{
closegraph();
printf("\n\nYou lose.");
}
printf("\n\n\nCome back again.\n\n Made by YOU LIAO working house. pubingk@citiz.net");
getch();
getch();
}
void car()
{
setcolor(BLUE);
setlinestyle(SOLID_LINE,0,3);
rectangle(,,,);
rectangle(,,,);
rectangle(,,,);
rectangle(,,,);
setcolor(5);
line(,,,);
line(,,,);
line(,,,);
line(,,,);
line(,,,);
setcolor(BLUE);
}
void main(void)
{
int gdriver = DETECT , gmode;
initgraph(&gdriver, &gmode, "");
begin();
setbkcolor(7);
setcolor(WHITE);
setwritemode(XOR_PUT);
road();
car();
light();
bus1();
end();
}
求C语言小游戏源程序
我的楼主可以自己玩一下
试试吧
#define N
#include <graphics.h>
#include <stdlib.h>
#include <dos.h>
#define LEFT 0x4b
#define RIGHT 0x4d
#define DOWN 0x
#define UP 0x
#define ESC 0xb
int i,key;
int score=0;/*得分*/
int gamespeed=;/*游戏速度自己调整*/
struct Food
{
int x;/*食物的横坐标*/
int y;/*食物的纵坐标*/
int yes;/*判断是否要出现食物的变量*/
}food;/*食物的结构体*/
struct Snake
{
int x[N];
int y[N];
int node;/*蛇的节数*/
int direction;/*蛇移动方向*/
int life;/* 蛇的生命,0活着,1死亡*/
}snake;
void Init(void);/*图形驱动*/
void Close(void);/*图形结束*/
void DrawK(void);/*开始画面*/
void GameOver(void);/*结束游戏*/
void GamePlay(void);/*玩游戏具体过程*/
void PrScore(void);/*输出成绩*/
/*主函数*/
void main(void)
{
Init();/*图形驱动*/
DrawK();/*开始画面*/
GamePlay();/*玩游戏具体过程*/
Close();/*图形结束*/
}
/*图形驱动*/
void Init(void)
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tc");
cleardevice();
}
/*开始画面,左上角坐标为(,码行支付控制系统源码),代码优家购源码右下角坐标为(,语言源c语言行p4源码)的码行金瑞币源码围墙*/
void DrawK(void)
{
/*setbkcolor(LIGHTGREEN);*/
setcolor();
setlinestyle(SOLID_LINE,0,THICK_WIDTH);/*设置线型*/
for(i=;i<=;i+=)/*画围墙*/
{
rectangle(i,,i+,); /*上边*/
rectangle(i,,i+,);/*下边*/
}
for(i=;i<=;i+=)
{
rectangle(,i,,i+); /*左边*/
rectangle(,i,,i+);/*右边*/
}
}
/*玩游戏具体过程*/
void GamePlay(void)
{
randomize();/*随机数发生器*/
food.yes=1;/*1表示需要出现新食物,0表示已经存在食物*/
snake.life=0;/*活着*/
snake.direction=1;/*方向往右*/
snake.x[0]=;snake.y[0]=;/*蛇头*/
snake.x[1]=;snake.y[1]=;
snake.node=2;/*节数*/
PrScore();/*输出得分*/
while(1)/*可以重复玩游戏,压ESC键结束*/
{
while(!kbhit())/*在没有按键的情况下,蛇自己移动身体*/
{
if(food.yes==1)/*需要出现新食物*/
{
food.x=rand()%+;
food.y=rand()%+;
while(food.x%!=0)/*食物随机出现后必须让食物能够在整格内,这样才可以让蛇吃到*/
food.x++;
while(food.y%!=0)
food.y++;
food.yes=0;/*画面上有食物了*/
}
if(food.yes==0)/*画面上有食物了就要显示*/
{
setcolor(GREEN);
rectangle(food.x,food.y,food.x+,food.y-);
}
for(i=snake.node-1;i>0;i--)/*蛇的每个环节往前移动,也就是贪吃蛇的关键算法*/
{
snake.x[i]=snake.x[i-1];
snake.y[i]=snake.y[i-1];
}
/*1,2,3,4表示右,左,上,下四个方向,通过这个判断来移动蛇头*/
switch(snake.direction)
{
case 1:snake.x[0]+=;break;
case 2: snake.x[0]-=;break;
case 3: snake.y[0]-=;break;
case 4: snake.y[0]+=;break;
}
for(i=3;i<snake.node;i++)/*从蛇的第四节开始判断是否撞到自己了,因为蛇头为两节,代码溯源码话术第三节不可能拐过来*/
{
if(snake.x[i]==snake.x[0]&&snake.y[i]==snake.y[0])
{
GameOver();/*显示失败*/
snake.life=1;
break;
}
}
if(snake.x[0]<||snake.x[0]>||snake.y[0]<||
snake.y[0]>)/*蛇是语言源c语言行否撞到墙壁*/
{
GameOver();/*本次游戏结束*/
snake.life=1; /*蛇死*/
}
if(snake.life==1)/*以上两种判断以后,如果蛇死就跳出内循环,重新开始*/
break;
if(snake.x[0]==food.x&&snake.y[0]==food.y)/*吃到食物以后*/
{
setcolor(0);/*把画面上的码行食物东西去掉*/
rectangle(food.x,food.y,food.x+,food.y-);
snake.x[snake.node]=-;snake.y[snake.node]=-;
/*新的一节先放在看不见的位置,下次循环就取前一节的位置*/
snake.node++;/*蛇的身体长一节*/
food.yes=1;/*画面上需要出现新的食物*/
score+=;
PrScore();/*输出新得分*/
}
setcolor(4);/*画出蛇*/
for(i=0;i<snake.node;i++)
rectangle(snake.x[i],snake.y[i],snake.x[i]+,
snake.y[i]-);
delay(gamespeed);
setcolor(0);/*用黑色去除蛇的的最后一节*/
rectangle(snake.x[snake.node-1],snake.y[snake.node-1],
snake.x[snake.node-1]+,snake.y[snake.node-1]-);
} /*endwhile(!kbhit)*/
if(snake.life==1)/*如果蛇死就跳出循环*/
break;
key=bioskey(0);/*接收按键*/
if(key==ESC)/*按ESC键退出*/
break;
else
if(key==UP&&snake.direction!=4)
/*判断是代码否往相反的方向移动*/
snake.direction=3;
else
if(key==RIGHT&&snake.direction!=2)
snake.direction=1;
else
if(key==LEFT&&snake.direction!=1)
snake.direction=2;
else
if(key==DOWN&&snake.direction!=3)
snake.direction=4;
}/*endwhile(1)*/
}
/*游戏结束*/
void GameOver(void)
{
cleardevice();
PrScore();
setcolor(RED);
settextstyle(0,0,4);
outtextxy(,,"GAME OVER");
getch();
}
/*输出成绩*/
void PrScore(void)
{
char str[];
setfillstyle(SOLID_FILL,YELLOW);
bar(,,,);
setcolor(6);
settextstyle(0,0,2);
sprintf(str,"score:%d",score);
outtextxy(,,str);
}
/*图形结束*/
void Close(void)
{
getch();
closegraph();
}