自创的。。。
代码如下:
#include<iostream>
#include<cmath>
#include<windows.h>
#include<conio.h>
using namespace std;
int start;
int x_red,y_red,x_blue,y_blue;
int i,j;
char fight_red,fight_blue;
int small_red,big_red,small_blue,big_blue;
char ground[10][10];
char red='@',blue='&';
char move_red,move_blue;
bool game=true;
int life_red=400,life_blue=400;
void color(int a)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
void first()
{
small_red=0;
big_red=0;
small_blue=0;
big_blue=0;
red='@';
blue='&';
game=true;
life_red=400;
life_blue=400;
}
void map()
{
system("cls");
color(15);
if(small_red>=2)
{
color(14);
cout<<'!';
color(15);
}
if(big_red>=5)
{
color(12);
cout<<'*';
color(15);
}
cout<<"red: "<<life_red<<" ";
if(small_blue>=3)
{
color(14);
cout<<'!';
color(15);
}
if(big_blue>=4)
{
color(12);
cout<<'*';
color(15);
}
cout<<"blue: "<<life_blue<<endl;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
if(i>1&&i<10&&j>1&&j<10)
{
if(i==x_red&&j==y_red)
{
color(12);
cout<<red;
if(red=='X') red='@';
}
else if(i==x_blue&&j==y_blue)
{
color(11);
cout<<blue;
if(blue=='X') blue='&';
}
else
{
if(i%3==0&&j%3==0) ground[i][j]='#';
else ground[i][j]=' ';
color(10);
cout<<ground[i][j];
}
}
else
{
ground[i][j]='#';
color(10);
cout<<ground[i][j];
}
}
cout<<endl;
}
Sleep(300);
}
void red_move()
{
switch(move_red)
{
case 'w':
if(x_red-1==x_blue&&y_red==y_blue)
break;
else if(ground[x_red-1][y_red]!='#')
x_red--;
break;
case 's':
if(x_red+1==x_blue&&y_red==y_blue)
break;
if(ground[x_red+1][y_red]!='#')
x_red++;
break;
case 'a':
if(x_red==x_blue&&y_red-1==y_blue)
break;
if(ground[x_red][y_red-1]!='#')
y_red--;
break;
case 'd':
if(x_red==x_blue&&y_red+1==y_blue)
break;
if(ground[x_red][y_red+1]!='#')
y_red++;
break;
}
small_red++;
}
void blue_move()
{
switch(move_blue)
{
case 'i':
if(x_blue-1==x_red&&y_blue==y_red)
break;
else if(ground[x_blue-1][y_blue]!='#')
x_blue--;
break;
case 'k':
if(x_blue+1==x_red&&y_blue==y_red)
break;
if(ground[x_blue+1][y_blue]!='#')
x_blue++;
break;
case 'j':
if(x_blue==x_red&&y_blue-1==y_red)
break;
if(ground[x_blue][y_blue-1]!='#')
y_blue--;
break;
case 'l':
if(x_blue==x_red&&y_blue+1==y_red)
break;
if(ground[x_blue][y_blue+1]!='#')
y_blue++;
break;
}
small_blue++;
cout<<endl;
}
void red_fight()
{
switch(fight_red)
{
case 'q':
if(small_red>=2&&abs(x_red-x_blue)<=2&&abs(y_red-y_blue)<=2)
{
life_blue-=5;
blue='X';
if(life_blue<=0)
{
life_blue=0;
game=false;
}
small_red-=2;
big_red++;
}
break;
case 'e':
if(big_red>=5&&abs(x_red-x_blue)<=4&&abs(y_red-y_blue)<=4)
{
life_blue-=25;
blue='X';
if(life_blue<=0)
{
life_blue=0;
game=false;
}
big_red-=5;
small_red++;
}
break;
}
map();
}
void blue_fight()
{
switch(fight_blue)
{
case 'u':
if(small_blue>=3&&abs(x_red-x_blue)<=2&&abs(y_red-y_blue)<=2)
{
life_red-=10;
red='X';
if(life_red<=0)
{
life_red=0;
game=false;
}
small_blue-=3;
big_blue++;
}
break;
case 'o':
if(big_blue>=4&&abs(x_red-x_blue)<=4&&abs(y_red-y_blue)<=4)
{
life_red-=20;
red='X';
if(life_red<=0)
{
life_red=0;
game=false;
}
big_blue-=4;
small_blue++;
}
break;
}
map();
cout<<endl;
}
void doing()
{
char input;
if(kbhit())
{
input=getch();
if(input=='q'||input=='e')
{
fight_red=input;
red_fight();
}
if(input=='a'||input=='s'||input=='d'||input=='w')
{
move_red=input;
red_move();
}
if(input=='u'||input=='o')
{
fight_blue=input;
blue_fight();
}
if(input=='j'||input=='k'||input=='l'||input=='i')
{
move_blue=input;
blue_move();
}
map();
}
}
void choose_play();
void procedure_of_play()
{
x_red=2;
y_red=5;
x_blue=9;
y_blue=5;
system("cls");
color(15);
cout<<"Welcome to Kings' World!"<<endl;
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<"$ # # # # # # # $"<<endl;
cout<<"$ ## # # # # # # $"<<endl;
cout<<"$ # # ### ### ## # # # # ### ### # ### $"<<endl;
cout<<"$ ## # # # # # # # # # # # # # # # # $"<<endl;
cout<<"$ # # # # # ### ## # # ### # # ### $"<<endl;
cout<<"$ # # $"<<endl;
cout<<"$ ### ### $"<<endl;
cout<<"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"<<endl;
cout<<" Made by Peter Winchester"<<endl;
cout<<"Red player uses a, s, d, w to move, and uses q and e to fight."<<endl;
cout<<"Blue player uses j, k, l, i to move, and uses u and o to fight."<<endl;
cout<<"The @ is the red player, the & is the blue player."<<endl;
cout<<"A ! before red or blue means a small fight, use q or u to do it."<<endl;
cout<<"A * before red or blue means a big fight, use e or o to do it."<<endl;
cout<<"Please input 1 to play game."<<endl;
cin>>start;
if(start==1)
{
first();
cout<<endl;
map();
while(game==true)
{
doing();
}
cout<<endl;
color(15);
if(life_red==0&&life_blue>0)
cout<<"Blue wins!"<<endl;
else if(life_blue==0&&life_red>0)
cout<<"Red wins!"<<endl;
else cout<<"Tie!"<<endl;
cout<<"Do you want to play again?"<<endl;
cout<<"1.yes 2.no"<<endl;
choose_play();
}
else cout<<"Game over!";
}
void choose_play()
{
int choose;
cin>>choose;
if(choose==1) procedure_of_play();
else if(choose==2) cout<<"Game over!";
else
{
cout<<"Please choose again:"<<endl;
choose_play();
}
}
int main()
{
procedure_of_play();
return 0;
} 复制到你的编译器上运行下试试。 
京公网安备 11010502036488号