#include<stdio.h>
#include<windows.h>//基本型态定义。支援型态定义函数。使用者界面函数 图形装置界面函数。
#include<conio.h> //用户通过按键盘产生的对应操作 (控制台)
#include<stdlib.h>
#include<time.h> //日期和时间头文件
//闯关模式、比赛模式、暴走闯关模式、暴走比赛模式、练习模式(包括教程)、设置
#define WID 25
#define LEN 50
clock_t nowtime;
clock_t Nowtime;
int bullet[7][10][10];
//0是纵坐标,1是横坐标,2是子弹类型,3是分值,4??,5是行进方式,6是速度,7是进度,8以上待定
int gun[7][2];
int enemy[99][10];
//0是纵坐标,1是横坐标,2是颜色,3是分值,4是生命值,5是行进方式,6是速度,7是进度,8是攻击方式,9是攻击力
//颜色:1红色是打不掉的攻击者,2蓝色是能打掉的攻击者,3绿色是能打掉的防御者,4黄色是打不掉的防御者,5白色是boss
//行进方式:0循环,1往复,2进位,3进位往复,-1消失
char message[10][48];
char name[2][20];
HANDLE hconsole = GetStdHandle(STD_OUTPUT_HANDLE); //获取标准输出的句柄 <windows.h>
int yourlife,enemylife,stage,btnumber,field;
double timer,supertimer;
int gold,spart[6],ot;//spart是否还能进入对应的菜单选项
void prepare(void),buyitem(int n),gettrophy(int n),changeitem(void),getfield(void);//为了函数套嵌而作的声明
void beforestage(int i),train(int i),Stage(int i);//为了函数套嵌而作的声明
void gotoyx(int y, int x)//设置光标位置
{
COORD pos = {x,y}; //定义一个字符在控制台屏幕上的坐标POS
SetConsoleCursorPosition(hconsole, pos); //定位光标位置的函数<windows.h>
}
void Hide_Cursor()//隐藏光标 固定函数
{
CONSOLE_CURSOR_INFO cursor_info = {1, 0};
SetConsoleCursorInfo(hconsole, &cursor_info);
}
int real;
int random(int a,int b)//同一时间产生的随机数不同
{
if(real<0||real>999)real=0;
srand((unsigned)time(NULL));
int k;
for(k=0;k<=real;k++)rand();
if(a>b)
{
k=a;
a=b;
b=k;
}
k=b-a+1;
real++;
return (rand()%k+a);
}
int shock=0;
void delay(int t)//推迟约0.001*t秒
{
int i,j,k;
if(shock==1)t=t*2/5;
for(i=1;i<=t;i++)
{
for(j=1;j<=730;j++)
{
for(k=1;k<=730;k++);
}
}
}
void setcolor(int Bcolor)//设置背景颜色0黑色,1红,2蓝,3绿,4黄,5白色,6品红,7青,8灰,9绿色字,10红色字,11蓝色字
{
SetConsoleTextAttribute(hconsole,Bcolor);//是API设置字体颜色和背景色的函数 格式:SetConsoleTextAttribute(句柄,颜色);
if(Bcolor==0)SetConsoleTextAttribute(hconsole,FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
if(Bcolor==1)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_RED | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
if(Bcolor==2)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
if(Bcolor==3)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_GREEN | FOREGROUND_INTENSITY);
if(Bcolor==4)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED | FOREGROUND_INTENSITY);
if(Bcolor==5)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE);
if(Bcolor==6)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_BLUE | FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN);
if(Bcolor==7)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_GREEN | BACKGROUND_BLUE | FOREGROUND_INTENSITY);
if(Bcolor==8)SetConsoleTextAttribute(hconsole,BACKGROUND_INTENSITY | BACKGROUND_INTENSITY | FOREGROUND_INTENSITY | FOREGROUND_RED);
if(Bcolor==9)SetConsoleTextAttribute(hconsole,FOREGROUND_INTENSITY | FOREGROUND_GREEN);
if(Bcolor==10)SetConsoleTextAttribute(hconsole,FOREGROUND_INTENSITY | FOREGROUND_RED);
if(Bcolor==11)SetConsoleTextAttribute(hconsole,FOREGROUND_INTENSITY | FOREGROUND_BLUE);
}
void next()
{
int i=1;
while(i)
{
if(kbhit())
{
switch(getch())
{
case 13:i=0;//回车
case 44:i=0;//逗号
default:break;
}
}
}
}
void printgun()
{
int g;
for(g=0;g<7;++g)if(gun[g][0]!=0)
{
gotoyx(gun[g][0],gun[g][1]);
setcolor(0);
printf("△");
}
}
void cleargun()
{
int g;
for(g=0;g<7;++g)if(gun[g][0]!=0||gun[g][1]!=0)
{
gotoyx(gun[g][0],gun[g][1]);
setcolor(0);
printf(" ");
}
}
int btkill;
void control()
{
int g,b;
if(kbhit())
{
switch(getch())
{
case 119://w
{
for(g=0;g<7;++g)if(gun[g][0]==WID-3||gun[g][0]==WID-2)
{
cleargun();
gun[g][0]--;
printgun();
}
break;
}
case 115://s
{
for(g=0;g<7;++g)if(gun[g][0]==WID-3||gun[g][0]==WID-4)
{
cleargun();
gun[g][0]++;
printgun();
}
break;
}
case 97://a
{
for(g=0;g<7;++g)if(gun[g][0]!=0&&gun[g][1]>0)
{
cleargun();
gun[g][1]--;
printgun();
}
break;
}
case 100://d
{
for(g=0;g<7;++g)if(gun[g][0]!=0&&gun[g][1]<LEN-1)
{
cleargun();
gun[g][1]++;
printgun();
}
break;
}
case 44://,
{
if(btnumber>=1||spart[1]==0)for(g=0;g<7;++g)for(b=0;b<20;++b)if(bullet[g][b][0]==0)
{
bullet[g][b][0]=gun[g][0]-1;
if(btnumber<=0)bullet[g][b][0]=gun[g][0]+1;
bullet[g][b][1]=gun[g][1];
bullet[g][b][6]=13;
break;//break应该只跳出一个for
}
if(btnumber>=9999);
else if(btnumber>=1)btnumber--;
else if(spart[1]==0)yourlife=yourlife-btkill;
break;
}
default:break;
}
}
}
void printenemy(int e)
{
gotoyx(enemy[e][0],enemy[e][1]);
setcolor(enemy[e][2]);
switch(enemy[e][3])
{
case 0:printf("0");break;
case 1:printf("1");break;
case 2:printf("2");break;
case 3:printf("3");break;
case 4:printf("4");break;
case 5:printf("5");break;
case 6:printf("6");break;
case 7:printf("7");break;
case 8:printf("8");break;
case 9:printf("9");break;
default:printf("%d",enemy[e][3]);break;
}
}
int timekill,timexx;
void printfigure()
{
int i,p;
if(clock()-Nowtime>=100)//每0.1秒判定一次
{
Nowtime=clock();
if(timer>=9999);
else if(timer>0)timer-=0.1;/////////////////////////////////////这里是时间设定
else if(timekill==20){yourlife--;yourlife--;}
else if(timekill==10)yourlife--;
else if(timekill==5){timexx++;if(timexx==2){timexx=0;yourlife--;}}
else timexx++;
if(timexx==10){timexx=0;yourlife-=timekill;}
gotoyx(2,LEN+15);
printf(" ");
gotoyx(4,LEN+15);
printf(" ");
gotoyx(6,LEN+15);
printf(" ");
gotoyx(8,LEN+15);
printf(" ");
gotoyx(2,LEN+15);
printf("%d",enemylife);
gotoyx(4,LEN+15);
printf("%d",yourlife);
gotoyx(6,LEN+15);
if(timer>=9999)printf("无限");
else printf("%.1f",timer);
gotoyx(8,LEN+15);
if(btnumber>=9999)printf("无限");
else printf("%d",btnumber);
setcolor(0);
gotoyx(3,LEN+1);printf(" ");//29
gotoyx(5,LEN+1);printf(" ");//29
gotoyx(7,LEN+1);printf(" ");//29
gotoyx(9,LEN+1);printf(" ");//29
gotoyx(3,LEN+1);setcolor(2);p=0;if(enemylife>=400){p=400;printf("★");}if(enemylife>=800){p=800;printf("★");}for(i=1;i<=(enemylife-p)/15&&i<=26;i++)printf(" ");
gotoyx(5,LEN+1);setcolor(2);p=0;if(yourlife>=400){p=400;printf("★");}if(yourlife>=800){p=800;printf("★");}for(i=1;i<=(yourlife-p)/15&&i<=26;i++)printf(" ");
gotoyx(7,LEN+1);setcolor(3);p=0;if(timer>=9999||timer<=0);
else{if(timer>=130){p=130;printf("●");}if(timer>=260){p=260;printf("●");}for(i=1;i<=(timer-p)/5&&i<=26;i++)printf(" ");}
gotoyx(9,LEN+1);SetConsoleTextAttribute(hconsole,FOREGROUND_INTENSITY | FOREGROUND_GREEN | BACKGROUND_RED);
if(btnumber>=9999||btnumber<=0);
else if(btnumber>=112)printf("●●●");
else if(btnumber>=70)
{
p=btnumber/8;for(i=1;i<=p;i++)printf("█");
if(btnumber-p*8==7)printf("▉");
if(btnumber-p*8==6)printf("▊");
if(btnumber-p*8==5)printf("▋");
if(btnumber-p*8==4)printf("▌");
if(btnumber-p*8==3)printf("▍");
评论0