该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include
#include
#include
#include
#include
#include
void main()
{
void welcome();
void over(int x);
void state();
void score(int x);
void hp(int x);
welcome();
state();
char key;
int x, y,a,m;
int sc = 0,wc = 0;
srand(time(NULL));
while (1)
{
x = rand() % 6*70 ;
if(x/70%2==1){a=0x54FC54;}
else a=0xFC54FC;
for(y = 0;y < 360; y++)
{
setcolor(0xA80000);
setfillstyle(a);
bar(x,y,x+60,y+30);
setcolor(0xA80000);
setfillstyle(BLACK);
bar(x,y-30,x+60,y);
if (kbhit())
{
key=getch();
if(key=='s')m=0;
else if(key=='d')m=1;
else if(key=='f')m=2;
else if(key=='j')m=3;
else if(key=='k')m=4;
else if(key=='l')m=5;
else m=6;
if(m == x/70)
{
setfillstyle(BLACK);
bar(x , y , x + 60, y + 30);
sc += 10;
score(sc);
break;
}
else if(key == 27)
goto loop;
else
{
wc++;
hp(wc);
}
}
if (y == 359)
{
setfillstyle(BLACK);
bar(x , y , x + 60, y + 30);
}
if (wc == 7)
goto loop;
Sleep(1);
}
}
loop:
over(sc);
closegraph();
}
void welcome()
{
initgraph(420, 480);
setcolor(YELLOW);
setfont(60, 40, "宋体");
outtextxy(45, 35, " " );
setfont(20, 10, "宋体");
outtextxy(150, 150, "by 韩伟");
int c=255;
while (!kbhit())
{
setcolor(RGB(c, 0, 0));
setfont(40, 15, "宋体");
outtextxy(120, 200, "按任意键继续");
c-=8;
Sleep(1);
}
cleardevice();
getch();
}
void over(int x)
{
char str[100];
cleardevice();
setcolor(YELLOW);
setfont(50, 50, "宋体");
itoa(x, str, 10);
outtextxy(20 , 150, "游戏结束!" );
setfont(20, 15, "宋体");
outtextxy(50 , 220, "你的得分为:" );
outtextxy(100 + textwidth("你的得分为:"), 220, str );
getch();
}
void state()
{
setcolor(YELLOW);
setfont(20, 15, "宋体");
line(0, 480 - textheight("测")-30, 420, 480 - textheight("测")-30);
loadimage(NULL,"beijing\\beijing.jpg");
outtextxy(0 , 440, "当前分数:" );
outtextxy(230, 440, "生命值");
setfillstyle(RED);
bar(320, 430, 420, 480);
setcolor(BLUE);
rectangle(320, 430, 419, 479);
}
void score(int x)
{
char str[100];
setfont(20, 20, "宋体");
setcolor(LIGHTMAGENTA);
bar(textwidth("当前分数:"), 440, 150, 480);
itoa(x, str, 10);
outtextxy(130,440, str);
}
void hp(int x)
{
setfillstyle(BLACK);
bar(320, 430, 420, 480);
setfillstyle(RED);
bar(320, 430, 420 - x * 15, 480);
setcolor(BLUE);
rectangle(320, 430, 420, 479);
setcolor(WHITE);
}