标题:[原创]格斗游戏
取消只看楼主
学C中
Rank: 1
等 级:新手上路
帖 子:68
专家分:0
注 册:2005-10-30
 问题点数:0 回复次数:0 
[原创]格斗游戏

/*呵呵,其实这个没什么技术含量,自我感觉就像在放幻灯片一样!呵呵,
我没学过数据结构,所以写得很乱,还望见谅!(不过我准备学了!)
做这个只是放松一下心情,太累了!
以下在TC2.0/XP 通过编译*/
#include <stdio.h>
#include <graphics.h>
#include <math.h>
#include <dos.h>
#include <bios.h>
#include <stdlib.h>
#include <time.h>
#define ESC 0x011b
#define LEFT 0x4b00
#define RIGHT 0x4d00
#define D 0x2064 /* 用手攻击 */
#define F 0x2166 /* 用脚攻击 */
void gameplay()
{
void shiftleft(int move);
void fail();
void win();
void shiftright(int move);
void score(int blood,int blood1);
void onset_by_hand(int move,int j,int k);
void onset_by_leg(int move,int b,int v,int c);
void opponent(int move1,int y,int h,int u,int w,int s,int o,int p);
void drawmap();
int key,move=0,move1=0,j=0,k=0,a=1,t=1,b=0,c=0,v=0,x,e;
int y=520,h=480,u=320,w=490,s=240,o=480,p=260,f1;
int blood=0,blood1=0;
shiftright(move);
score(blood,blood1);
opponent(move1,y,h,u,w,s,o,p);
drawmap();
while(1)
{
f1=random(4);
key=bioskey(0);
if(blood1>=100)
{
cleardevice();
win();
sleep(10);
closegraph();
exit(0);
}
if(key==RIGHT)
{

if(move<410&&move<330+move1)
{
move+=5;
cleardevice();
shiftright(move);
drawmap();
opponent(move1,y,h,u,w,s,o,p);
score(blood,blood1);
}
else
getch();
a=0;
t=0;
}
else if(key==LEFT)
{
if(move>-60)
{
move-=5;
cleardevice();
shiftleft(move);
drawmap();
opponent(move1,y,h,u,w,s,o,p);
score(blood,blood1);
}
else
getch();
a=0;
t=0;
}
else if(key==D)
{
if(a==1)
{
j=130;
k=260;
a=0;
}
else if(a==0)
{
j=160;
k=210;
a=1;
}
cleardevice();
onset_by_hand(move,j,k);
drawmap();
if(((485+move1)-(115+move))<=45)
{
move1+=50;
if(move1>80)
move1=80;
blood1+=1;
}
opponent(move1,y,h,u,w,s,o,p);
score(blood,blood1);
delay(1000);
t=0;

}
else if(key==F)
{
if(t==1)
{
b=80;
v=120;
c=320;
t=0;
}
else if(t==0)
{
b=100;
v=180;
c=240;
t=1;
}
cleardevice();
onset_by_leg(move,b,v,c);
drawmap();
if(((485+move1)-(115+move))<=45)
{
move1+=60;
if(move1>80)
move1=80;
blood1+=2;
}
opponent(move1,y,h,u,w,s,o,p);
score(blood,blood1);
delay(1000);
a=0;
}
else if(key==ESC)
{
cleardevice();
settextstyle(0,0,3);
outtextxy(200,100,"GAME OVER !");
sleep(10);
closegraph();
exit(0);
}
else
getch();
if(f1==2||f1==0) /*对手的移动*/
{
while(!kbhit())
{
if(move1>-390&&((485+move1)-(115+move))>40)
{
move1-=10;
cleardevice();
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
delay(100000);
move1+=5;
cleardevice();
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
}
else
break;
}
}
while(!kbhit()) /* 对手的攻击 */
{
x=random(50);
if(((485+move1)-(115+move))<=40)
{
if(x==11) /* 用手*/
{
w=485;
s=210;
o=440;
p=210;
cleardevice();
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
delay(100000);
cleardevice();
w=490;
s=240;
o=480;
p=260;
move-=40;
if(move<-60)
move=-60;
blood+=1;
if(blood>=100)
{
cleardevice();
fail();
sleep(10);
closegraph();
exit(0);
}
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
}
else if(x==48) /* 用脚*/
{
y=500;
h=420;
u=240;
cleardevice();
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
delay(100000);
cleardevice();
y=520;
h=480;
u=320;
move-=50;
if(move<-60)
move=-60;
blood+=2;
if(blood>=100)
{
cleardevice();
fail();
sleep(10);
closegraph();
exit(0);
}
opponent(move1,y,h,u,w,s,o,p);
shiftright(move);
drawmap();
score(blood,blood1);
}
}
/*if(!kbhit()&&key==ESC||!kbhit()&&key==LEFT||!kbhit()&&key==RIGHT||!kbhit()&&key==D||!kbhit()&&key==F)
break;*/
}
}
}
void shiftright(int move) /*右移*/
{
int i=10;
circle(100+move,180,10); /*head*/
line(100+move,190,100+move,200); /*neck*/
rectangle(85+move,200,115+move,240); /*body*/
line(100+move,240,80+move-i,320); /*left leg*/
line(100+move,240,120+move,320); /*right leg*/
line(100+move,210,130+move,260); /* right hand*/
line(110+move,240,120+move,260); /* left hand*/
i+=30;
if(i>=30)
i=10;
}
void shiftleft(int move) /*左移*/
{
int i=10;
circle(100+move,180,10); /*head*/
line(100+move,190,100+move,200); /*neck*/
rectangle(85+move,200,115+move,240); /*body*/
line(100+move,240,80+move,320); /*left leg*/
line(100+move,240,120+move-i,320); /*right leg*/
line(100+move,210,130+move,260); /*right hand*/
line(115+move,207,160+move,200); /*left hand*/
i+=20;
if(i>=30)
i=10;
}
void onset_by_hand(int move,int j,int k) /* 用手攻击*/
{
int i=10;
circle(100+move,180,10);
line(100+move,190,100+move,200);
rectangle(85+move,200,115+move,240);
line(100+move,240,80+move,320);
line(100+move,240,120+move-i,320);
line(100+move,210,j+move,k);
line(110+move,240,120+move,260);
i+=20;
if(i>=30)
i=10;
}
void onset_by_leg(int move,int b,int v,int c) /* 用脚攻击 */
{
circle(100+move,180,10);
line(100+move,190,100+move,200);
rectangle(85+move,200,115+move,240);
line(100+move,240,b+move,320);
line(100+move,240,v+move,c);
line(100+move,210,130+move,260);
line(110+move,240,120+move,260);
}
void drawmap()
{
bar(0,300,600,320);
bar(600,0,620,320);
}
void opponent(int move1,int y,int h,int u,int w,int s,int o,int p) /* 对手*/
{
circle(500+move1,180,10);
line(500+move1,190,500+move1,200);
rectangle(485+move1,200,515+move1,240);
line(500+move1,240,h+move1,u);
line(500+move1,240,y+move1,320);
line(500+move1,210,470+move1,260);
line(w+move1,s,o+move1,p);
/*line(485,210,440,210);*/
}
void score(int blood,int blood1) /* 生命力 */
{
bar(50,5,150-blood,10);
bar(450,5,550-blood1,10);
}
void fail() /* 输了的画面*/
{
bar(0,300,600,320);
bar(600,0,620,320);
circle(500,180,10);
line(500,190,500,200);
rectangle(480,200,520,240);
line(485,240,485,300);
line(515,240,515,300);
line(450,170,480,210);
line(550,170,520,210);
circle(100,290,10);
line(110,290,120,285);
rectangle(120,270,160,300);
line(130,285,190,285);
line(160,290,220,295);
settextstyle(0,0,3);
outtextxy(200,100,"YOU FAIL !");
}
void win()
{
bar(0,300,600,320);
bar(600,0,620,320);
circle(100,180,10);
line(100,190,100,200);
rectangle(80,200,120,240);
line(85,240,85,300);
line(115,240,115,300);
line(50,170,80,210);
line(150,170,120,210);
circle(500,290,10);
line(490,290,480,285);
rectangle(480,270,440,300);
line(470,285,410,285);
line(440,290,380,295);
settextstyle(0,0,3);
outtextxy(200,100,"YOU WIN !");
}
int main(void)
{
int gd=DETECT,mode;
initgraph(&gd,&mode,"");
gameplay();
}
/* 本来想左右移只做一个函数的,不过为了好区分一点,就分开写了!
实际上是不能这写的!(汗!还好意思说?) */

搜索更多相关主题的帖子: 格斗游戏 include define math 数据结构 
2006-01-04 20:22



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-41634-1-1.html




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

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