今天给大家带来一个射击游戏(不是人机哦),
直接上代码:
#include<algorithm>
#include<cmath>
#include<vector>
#include<stdio.h>
#include<iostream>
#include<string>
#include<cstring>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
#include<ctime>
#include<fstream>
#define /*白色*/white SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define /*初始色*/original SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE);
#define /*红色*/red SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED);
#define /*绿色*/green SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN);
#define /*蓝色*/blue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE);
#define /*黄色*/yellow SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_GREEN);
#define /*粉色*/pink SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED |FOREGROUND_BLUE);
#define /*淡蓝*/lightblue SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN |FOREGROUND_BLUE);
#define /*灰色*/gray SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY);
using namespace std;
void gotoxy(int y,int x)
{
COORD coord;
coord.X=x;
coord.Y=y;
HANDLE a=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(a,coord);
}
void coutwhat(int a,int b,int c,int d,string n)
{
int i,j;
for(i=a;i<=c;i++)
for(j=b;j<=d;j++)
{
gotoxy(i,j);
cout<<n;
}
}
void color(int x)
{
switch(x)
{
case 0:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);break;
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_GREEN);break;
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_GREEN);break;
case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE);break;
case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_BLUE |FOREGROUND_RED);break;
case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED);break;
case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_GREEN);break;
case 9:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |FOREGROUND_RED|FOREGROUND_BLUE);break;
case 10:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_RED);break;
default:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);break;
}
}
int random(int n,int m)
{
int s;
s=rand()%(m-n+1);
s+=n;
return s;
}
void cls()
{
system("cls");
}
struct Player
{
string name;
int hp;
int HP;
int attack;
int defence;
int fw;//0,1,2,3
int energy;
int kill;
int x;
int y;
int sc;
int zl;
int cs;
};
Player player[5];
void printfssbh(int n)
{
int i,j,k;
for(i=1;i<=4;i++)
{
gotoxy(0,i*25);
cout<<player[i].energy<<"("<<player[i].energy/10.0<<"%)"<<player[i].kill<<"kill ";
}
//计算生命百分比
float a[5];
int b[5];
for(i=1;i<=n;i++)
a[i]=(player[i].hp*1.0)/(player[i].HP*1.0);
for(i=1;i<=n;i++)
b[i]=a[i]*100;
for(i=1;i<=n;i++)
if (b[i]>10000)
b[i]=0;//死者
else
if (b[i]>100)
b[i]=100;//血量溢出但还没死
//输出
for(i=1;i<=n;i++)
{
gotox