修改了几个bug,用了最新的game库,直接让代码少了100多行。
需要下载game库。
代码:
//上72 下80 左75 右77
#include<bits/stdc++.h>//输入输出用的
#include<ctime>//计算时间用的 colok()
#include<conio.h>//_getch()用的
#include<fstream>//存档用的
#include<windows.h>//SLeep等函数
#include<D:\game.h>
using namespace std;
using namespace _game_cl;
using namespace _game_sb;
using namespace _game_hs;
const int jss=4;
int wj1x=3,wj1y=4,wj1jx,wj1jy,wj1xl,wj1Mxl,wj1js/*角色*/,wj1jn=0/*技能*/,wj1kh=0/*刻痕*/;
int wj2x=3,wj2y=3,wj2jx,wj2jy,wj2xl,wj2Mxl,wj2js/*角色*/,wj2jn=0/*技能*/,wj2kh=0/*刻痕*/;
int xxs=0;
string xx[100000];
struct js{
string name;
int xl;//血量
int gj;//攻击
int jh;//技能消耗
string jnm;//技能名
}js[jss+1]={
{"无",1,0,0},
{"剑客",2,1,3,"剑雨"},
{"巫师",1,1,3,"冲刺"},
{"肉盾",3,1,2,"回血"},
{"游侠",2,1,3,"暴击"},
};
void yyzzq();
void gzjs();
void jsr();
void jsw();
void yx();
void xjs();
void Hyx(char s,bool as);
void jn(int x);
void check();
void xxd(bool as);
void out();
void yscsh();
int main(){
system("mode con cols=100 lines=35");
ycbj();
ycgb();
system("cls");
color(15);
yyzzq();
return 0;
}
void yyzzq(){
while(1){
system("cls");
color(14);
zk("主界面",' ',"长度");
color(15);
cout<<"0:退出游戏\t1:开始游戏\t2:游戏规则\n";
cout<<"请选择:";
char s=_getch();
while(s>'2'||s<'0')s=_getch();
cout<<s<<"\n";
Sleep(500);
switch(s){
case '0':{
return;
break;
}
case '1':{
yx();
break;
}
case '2':{
gzjs();
break;
}
}
}
}
void yx(){
xjs();
bool as=1;
while(1){
system("cls");
color(14);
zk("游戏界面",' ',"长度");
color(15);
cout<<"\n";
if(as)cout<<"轮到玩家1走了(w s a d 移动";
else cout<<"轮到玩家2走了(↑↓←→移动";
cout<<" k键查看玩家属性 空格使用技能)\n";
out();
bool jx=1;
while(jx){
char s=_getch();
if(as)while(s!=' '&&s!='w'&&s!='a'&&s!='s'&&s!='d'&&s!='k')s=_getch();
else while(s!=' '&&s!=72&&s!=75&&s!=80&&s!=77&&s!='k')s=_getch();
if(s==' '){
if(as){
if(wj1jn>=js[wj1js].jh){
wj1jn-=js[wj1js].jh;
jn(1);
jx=0;
}
else{
jx=1;
cout<<"技能点不够,无法使用技能\n请重新输入\n";
s=_getch();
while(s!='w'&&s!='a'&&s!='s'&&s!='d'&&s!='k')s=_getch();
}
}
else{
if(wj2jn>=js[wj2js].jh){
wj2jn-=js[wj2js].jh;
jn(2);
jx=0;
}
else{
jx=1;
cout<<"技能点不够,无法使用技能\n请重新输入\n";
s=_getch();
while(s!=72&&s!=80&&s!=75&&s!=77&&s!='k')s=_getch();
}
}
}
if(!jx)
{
check();
continue;
}
jx=0;
if(as==1){
if(wj1x==1&&s=='w')jx=1;
if(wj1x==5&&s=='s')jx=1;
if(wj1y==1&&s=='a')jx=1;
if(wj1y==7&&s=='d')jx=1;
}
if(as==0){
if(wj2x==1&&s==72)jx=1;
if(wj2x==5&&s==80)jx=1;
if(wj2y==1&&s==75)jx=1;
if(wj2y==7&&s==77)jx=1;
}
Hyx(s,as);
if(s=='k'){
jx=1;
system("cls");
color(14);
zk("游戏界面",' ',"长度");
color(15);
cout<<"\n";
if(as)cout<<"轮到玩家1走了(w s a d移动";
else cout<<"轮到玩家2走了(↑↓←→移动";
cout<<" k键查看玩家属性 空格使用技能)\n";
out();
}
check();
if(wj1kh>=3){
system("cls");
color(12);
cout<<"\t玩家二胜利!!!\n";
cout<<"\t玩家二胜利!!!\n";
cout<<"\t玩家二胜利!!!\n";
color(15);
system("pause");
return;
}
if(wj2kh>=3){
system("cls");
color(12);
cout<<"\t玩家一胜利!!!\n";
cout<<"\t玩家一胜利!!!\n";
cout<<"\t玩家一胜利!!!\n";
color(15);
system("pause");
return;
}
}
as=!as;
}
}
void Hyx(char s,bool as){
if(s=='k'){
system("cls");
color(14);
zk("玩家属性",' ',"长度");
color(12);
cout<<"\n玩家1:";
color(15);
cout<<"\n\t角色:"<<js[wj1js].name<<"\t刻痕数:"<<wj1kh;
cout<<"\n\t血量:"<<wj1xl<<"/"<<wj1Mxl<<"\t技能点数:"<<wj1jn<<"\n";
Sleep(1000);
color(12);
cout<<"\n玩家2:";
color(15);
cout<<"\n\t角色:"<<js[wj2js].name<<"\t刻痕数:"<<wj2kh;
cout<<"\n\t血量:"<<wj2xl<<"/"<<wj2Mxl<<"\t技能点数:"<<wj2jn<<"\n";
cout<<"\n\n\n\t";
system("pause");
return;
}
if(as){
if(s=='w'&&wj1x-1>=1){
if(wj1x-1==wj2x&&wj1y==wj2y&&wj2x==5&&wj2y==7)return;
if(wj1x-1==wj2x&&wj1y==wj2y){
wj2xl--;
}
else
wj1x--,xxd(1);
}
if(s=='s'&&wj1x+1<=5){
if(wj1x+1==wj2x&&wj1y==wj2y&&wj2x==5&&wj2y==7)return;
if(wj1x+1==wj2x&&wj1y==wj2y){
wj2xl--;
}
else
wj1x++,xxd(1);
}
if(s=='a'&&wj1y-1>=1){
if(wj1y-1==wj2y&&wj1x==wj2x&&wj2x==5&&wj2y==7)return;
if(wj1y-1==wj2y&&wj1x==wj2x){
wj2xl--;
}
else
wj1y--,xxd(1);
}
if(s=='d'&&wj1y+1<=7){
if(wj1y+1==wj2y&&wj1x==wj2x&&wj2x==5&&wj2y==7)return;
if(wj1y+1==wj2y&&wj1x==wj2x){
wj2xl--;
}
else
wj1y++,xxd(1);
}
}
else{
if(s==72&&wj2x-1>=1){
if(wj2x-1==wj1x&&wj2y==wj1y&&wj1x==1&&wj1y==1)return;
if(wj2x-1==wj1x&&wj2y==wj1y){
wj1xl--;
}
else
wj2x--,xxd(0);
}
if(s==80&&wj2x+1<=5){
if(wj2x+1==wj1x&&wj2y==wj1y&&wj1x==1&&wj1y==1)return;
if(wj2x+1==wj1x&&wj2y==wj1y){
wj1xl--;
}
else
wj2x++,xxd(0);
}
if(s==75&&wj2y-1>=1){
if(wj2y-1==wj1y&&wj2x==wj1x&&wj1x==1&&wj1y==1)return;
if(wj2y-1==wj1y&&wj2x==wj1x){
wj1xl--;
}
else
wj2y--,xxd(0);
}
if(s==77&&wj2y+1<=7){
if(wj2y+1==wj1y&&wj2x==wj1x&&wj1x==1&&wj1y==1)return;
if(wj2y+1==wj1y&&wj2x==wj1x){
wj1xl--;
}
else
wj2y++,xxd(0);
}
}
}
void jn(int x){
if(x==1){
switch(wj1js){
case 1:{
if(wj2x==wj1x-1&&wj2y==wj1y-1)wj2xl--;
if(wj2x==wj1x-1&&wj2y==wj1y)wj2xl--;
if(wj2x==wj1x-1&&wj2y==wj1y+1)wj2xl--;
if(wj2x==wj1x&&wj2y==wj1y-1)wj2xl--;
if(wj2x==wj1x&&wj2y==wj1y+1)wj2xl--;
if(wj2x==wj1x+1&&wj2y==wj1y-1)wj2xl--;
if(wj2x==wj1x+1&&wj2y==wj1y+1)wj2xl--;
xxs++;
xx[xxs]="【剑客】发动了技能【剑雨】";
break;
}
case 2:{
cout<<"请【巫师】输入冲刺的方向(wasd上下左右 冲刺三格)\n";
char s=_getch();
while(s!='w'&&s!='a'&&s!='s'&&s!='d')s=_getch();
if(s=='w'){
for(int i=1;i<=3;i++){
if(wj1x-1<=0||wj1x-1==wj2x&&wj1y==wj2y)break;
wj1x--;
}
}
if(s=='a'){
for(int i=1;i<=3;i++){
if(wj1y-1<=0||wj1y-1==wj2y&&wj1x==wj2x)break;
wj1y--;
}
}
if(s=='d'){
for(int i=1;i<=3;i++){
if(wj1x+1>=8||wj1x+1==wj2x&&wj1y==wj2y)break;
wj1x++;
}
}
if(s=='s'){
for(int i=1;i<=3&&wj1y+1<=7;i++){
if(wj1y+1>=6||wj1y+1==wj2y&&wj1x==wj2x)break;
wj1x--;
}
}
xxd(x==1);
xxs++;
xx[xxs]="【巫师】发动了技能【冲刺】";
break;
}
case 3:{
wj1xl++;
if(wj1xl>wj1Mxl)wj1xl=wj1Mxl;
xxs++;
xx[xxs]="【肉盾】发动了技能【回血】";
break;
}
case 4:{
if(wj1x+1==wj2x&&wj1y==wj2y||wj1y-1==wj2y&&wj1x==wj2x||wj1x-1==wj2x&&wj1y==wj2y||wj1y+1==wj2y&&wj1x==wj2x){
cout<<"您对玩家2造成了暴击,他扣了三滴血\n";
wj2xl-=3;
xxs++;
xx[xxs]="【游侠】发动了技能【暴击】\n";
}
else{
cout<<"您身边并未发现玩家,技能失效\n";
wj1jn+=js[4].jh;
}
system("pause");
break;
}
}
}
else{
switch(wj2js){
case 1:{
if(wj1x==wj2x-1&&wj1y==wj2y-1)wj1xl--;
if(wj1x==wj2x-1&&wj1y==wj2y)wj1xl--;
if(wj1x==wj2x-1&&wj1y==wj2y+1)wj1xl--;
if(wj1x==wj2x&&wj1y==wj2y-1)wj1xl--;
if(wj1x==wj2x&&wj1y==wj2y+1)wj1xl--;
if(wj1x==wj2x+1&&wj1y==wj2y-1)wj1xl--;
if(wj1x==wj2x+1&&wj1y==wj2y+1)wj1xl--;
xxs++;
xx[xxs]="【剑客】发动了技能【剑雨】";
break;
}
case 2:{
cout<<"请【巫师】输入冲刺的方向(↑↓←→上下左右 冲刺三格)\n";
char s=_getch();
while(s!=72&&s!=75&&s!=80&&s!=77)s=_getch();
if(s==72){
for(int i=1;i<=3;i++){
if(wj2x-1<=0||wj2x-1==wj1x&&wj2y==wj1y)break;
wj2x--;
}
}
if(s==75){
for(int i=1;i<=3;i++){
if(wj2y-1<=0||wj2y-1==wj1y&&wj2x==wj1x)break;
wj2y--;
}
}
if(s==77){
for(int i=1;i<=3;i++){
if(wj2y+1>=8||wj2y+1==wj1y&&wj2x==wj1x)break;
wj2y++;
}
}
if(s==80){
for(int i=1;i<=3;i++){
if(wj2x+1>=6||wj2x+1==wj1x&&wj2y==wj1y)break;
wj2x++;
}
}
xxd(x==1);
xxs++;
xx[xxs]="【巫师】发动了技能【冲刺】";
break;
}
case 3:{
wj2xl++;
if(wj2xl>wj2Mxl)wj2xl=wj2Mxl;
xxs++;
xx[xxs]="【肉盾】发动了技能【回血】";
break;
}
case 4:{
if(wj2x+1==wj1x&&wj2y==wj1y||wj2y-1==wj1y&&wj2x==wj1x||wj2x-1==wj1x&&wj2y==wj1y||wj2y+1==wj1y&&wj2x==wj1x){
cout<<"您对玩家1造成了暴击,他扣了三滴血\n";
wj1xl-=3;
xxs++;
xx[xxs]="【游侠】发动了技能【暴击】";
}
else{
cout<<"您身边并未发现玩家,技能失效\n";
wj2jn+=js[4].jh;
}
system("pause");
break;
}
}
}
return;
}
void xxd(bool as){
if(wj1x==3&&wj1y==4&&as){
cout<<"玩家1到了星星点\n请玩家1选择一项:\n1:回家 2:加一格技能点";
char s1=_getch();
while(s1!='1'&&s1!='2')s1=_getch();
if(s1=='1')wj1x=1,wj1y=1;
if(s1=='2')wj1jn++;
}
if(wj2x==3&&wj2y==4&&as==0){
cout<<"玩家2到了星星点\n请玩家1选择一项:\n1:回家 2:加一格技能点";
char s1=_getch();
while(s1!='1'&&s1!='2')s1=_getch();
if(s1=='1')wj2x=5,wj2y=7;
if(s1=='2')wj2jn++;
}
return;
}
void gzjs(){
while(1){
system("cls");
color(14);
zk("规则界面",' ',"长度");
color(15);
cout<<"0:退出界面\t1:介绍角色\t2:介绍玩家\n";
cout<<"请选择:";
char s=_getch();
while(s<'0'||s>'2')s=_getch();
cout<<s<<"\n";
Sleep(500);
switch(s){
case '0':{
return;
break;
}
case '1':{
jsw();
break;
}
case '2':{
jsr();
break;
}
}
}
return;
}
void jsr(){
system("cls");
color(14);
zk("介绍玩家",' ',"长度");
color(15);
colorout(" 1:",12);
out("每位玩家都有自己的家和重生点。\n",30);Sleep(200);
colorout(" 2:",12);
out("当一名玩家到达对方的家时对方家里的刻痕会加1。\n",30);Sleep(200);
colorout(" 3:",12);
out("当玩家偷到对方家时会传送回自己的家。\n",30);Sleep(200);
colorout(" 4:",12);
out("玩家不能走到对方已经在的格子上,如果这么走则会对它造成1滴伤害。\n",30);Sleep(200);
colorout(" 5:",12);
out("若玩家在自己的家里时无视一切伤害。\n",30);Sleep(200);
colorout(" 6:",12);
out("当一名玩家的刻痕数达到3则输掉这场比赛。\n",30);Sleep(200);
colorout(" 7:",12);
out("当玩家被打死时会传送到自己的重生点。\n",30);Sleep(200);
colorout(" 8:",12);
out("地图中间的点为星星点,玩家到达那里可以选择一项:1 回家\t2 加一格技能点。\n",30);Sleep(200);
colorout(" 9:",12);
out("玩家1W A S D 移动,\n",30);Sleep(200);
colorout("10:",12);
out("玩家2↑←↓→移动,\n",30);Sleep(200);
colorout("11:",12);
out("按k键查看玩家属性,按空格使用技能。\n",30);Sleep(200);
colorout("12:",12);
out("当玩家的技能点数大于4时,会变成4。\n",30);Sleep(200);
cout<<"\n";
system("pause");
return;
}
void jsw(){
system("cls");
color(14);
zk("介绍角色",' ',"长度");
color(15);
cout<<"编号 名称 血量 技耗 技能名\n";Sleep(200);
cout<<"1: 剑客 2滴 3格 剑雨\n";Sleep(200);
cout<<"2: 巫师 1滴 3格 冲刺\n";Sleep(200);
cout<<"3: 肉盾 3滴 2格 回血\n";Sleep(200);
cout<<"4: 游侠 2滴 3格 暴击\n";Sleep(200);
cout<<"\n";
Sleep(1000);
color(14);
zk("技能解释",'-',"长度");
color(15);
cout<<"\n";
cout<<"【剑雨】:对周围八个方向的所有玩家造成1点伤害。\n";Sleep(200);
cout<<"【冲刺】:向一个方向冲刺三格。\n"; Sleep(200);
cout<<"【回血】:回一滴血。\n";Sleep(200);
cout<<"【暴击】:对周围四个方向的一名玩家造成3点伤害。\n";Sleep(200);
cout<<"\n";
system("pause");
return;
}
void pd(string s){
if(s.substr(0,4)=="玩家"){
char s1=s[11];
if(s1=='1')color(11);
if(s1=='2')color(14);
if(s1=='3')color(12);
}
return;
}
void check(){
if(wj1xl<=0){
wj1x=1;
wj1y=4;
xxs++;
xx[xxs]="玩家1被打死了!!!";
wj1xl=wj1Mxl;
}
if(wj1xl>wj1Mxl)
wj1xl=wj1Mxl;
if(wj2xl<=0){
wj2x=5;
wj2y=4;
xxs++;
xx[xxs]="玩家2被打死了!!!";
wj2xl=wj2Mxl;
}
if(wj2xl>wj2Mxl)
wj2xl=wj2Mxl;
if(wj1x==5&&wj1y==7){
wj2kh++;
xxs++;
string s="玩家2被偷了",k="";
k+=char(wj2kh+'0');
k+="次";
s+=k;
xx[xxs]=s;
wj1x=1,wj1y=1;
}
if(wj2x==1&&wj2y==1){
wj1kh++;
xxs++;
string s="玩家1被偷了",k="";
k+=char(wj1kh+'0');
k+="次";
s+=k;
xx[xxs]=s;
wj2x=5,wj2y=7;
}
if(wj1jn>4)wj1jn=4;
if(wj2jn>4)wj2jn=4;
return;
}
void xjs(){
system("cls");
color(14);
zk("选角色界面",' ',"长度");
color(12);
zc("轮到玩家1选角色了",' '," ");
cout<<"\n\n\n";
color(15);
for(int i=1;i<=jss;i++)
{
cout<<i<<":"<<js[i].name<<" ";
}
cout<<"\n\n请输入需要选择的角色编号\n";
char s;
s=_getch();
while(s<'0'||s>char(jss+'0'))s=_getch();
wj1js=s-'0';
cout<<"选择成功!!!选择的是";
color(12);
cout<<js[wj1js].name<<"\n";
color(15);
wj1x=1,wj1y=1;
wj1Mxl=js[wj1js].xl;
wj1xl=js[wj1js].xl;
system("pause");
system("cls");
color(14);
zk("选角色界面",' ',"长度");
color(12);
zc("轮到玩家2选角色了",' '," ");
cout<<"\n\n\n";
color(15);
for(int i=1;i<=jss;i++)
{
cout<<i<<":"<<js[i].name<<" ";
}
cout<<"\n\n请输入需要选择的角色编号\n";
s=_getch();
while(s<'0'||s>char(jss+'0')||s==wj1js+'0')
{
if(s==wj1js+'0'){
system("cls");
cout<<"\n不能选择和玩家1一样的角色\n\n";
system("pause");
system("cls");
color(14);
zk("选角色界面",' ',"长度");
color(12);
zc("轮到玩家1选角色了",' '," ");
cout<<"\n\n\n";
color(15);
for(int i=1;i<=jss;i++)
{
cout<<i<<":"<<js[i].name<<" ";
}
cout<<"\n\n请输入需要选择的角色编号\n";
}
s=_getch();
}
wj2js=s-'0';
cout<<"选择成功!!!选择的是";
color(12);
cout<<js[wj2js].name<<"\n";
color(15);
system("pause");
wj2x=5,wj2y=7;
wj2Mxl=js[wj2js].xl;
wj2xl=js[wj2js].xl;
return;
}
void out(){
int xxt=xxs;
cout<<"-------------------------------------------------- --------------------------------\n";
for(int i=1;i<=5;i++){
for(int j=1;j<=7;j++){
cout<<"|";
if(i==1&&j==1){
cout<<"xl:"<<wj1xl<<" ";
}
else
if(i==5&&j==7){
cout<<"xl:"<<wj2xl<<" ";
}
else
if((i==1||i==5)&&j==4){
cout<<"重 ";
}
else
if(i==3&&j==4){
cout<<"☆☆☆";
}
else
cout<<" ";
}
cout<<"| |";
if(xxt>0)
pd(xx[xxt]),zc(xx[xxt],' '," ");
else
cout<<" ";
color(15);
cout<<"|\n";
xxt--;
for(int j=1;j<=7;j++){
cout<<"|";
if(i==1&&j==1){
if(wj1x==1&&wj1y==1)color(13);
cout<<" A ";
color(15);
}
else
if(i==5&&j==7){
if(wj2x==5&&wj2y==7)color(13);
cout<<" B ";
color(15);
}
else
if((i==1||i==5)&&j==4){
bool as=1;
if(i==1&&j==4){
if(wj1x==1&&wj1y==4){
cout<<"生 ";
color(13);
cout<<"A ";
color(15);
as=0;
}
else
if(wj2x==1&&wj2y==4){
cout<<"生 ";
color(13);
cout<<"B ";
color(15);
as=0;
}
}
if(i==5&&j==4){
if(wj2x==5&&wj2y==4){
cout<<"生 ";
color(13);
cout<<"B ";
color(15);
as=0;
}
else
if(wj1x==5&&wj1y==4){
cout<<"生 ";
color(13);
cout<<"A ";
color(15);
as=0;
}
}
if(as)
cout<<"生 ";
}
else
if(i==3&&j==4){
if(wj1x==3&&wj1y==4)
{
cout<<"☆ ";
color(13);
cout<<"A";
color(15);
cout<<"☆";
}
else
if(wj2x==3&&wj2y==4)
{
cout<<"☆ ";
color(13);
cout<<"B";
color(15);
cout<<"☆";
}
else
cout<<"☆☆☆";
}
else
if(wj1x==i&&wj1y==j){
color(13);
cout<<" A ";
color(15);
}
else
if(wj2x==i&&wj2y==j){
color(13);
cout<<" B ";
color(15);
}
else
cout<<" ";
}
cout<<"| |";
if(xxt>0)
pd(xx[xxt]),zc(xx[xxt],' '," ");
else
cout<<" ";
color(15);
cout<<"|\n";
xxt--;
for(int j=1;j<=7;j++){
cout<<"|";
if(i==1&&j==1){
cout<<"Mxl:"<<wj1Mxl<<" ";
}
else
if(i==5&&j==7){
cout<<"Mxl:"<<wj2Mxl<<" ";
}
else
if(i==1&&j==4){
cout<<"点A ";
}
else
if(i==5&&j==4){
cout<<"点B ";
}
else
if(i==3&&j==4){
cout<<"☆☆☆";
}
else
cout<<" ";
}
cout<<"| |";
if(xxt>0)
pd(xx[xxt]),zc(xx[xxt],' '," ");
else
cout<<" ";
color(15);
cout<<"|\n";
xxt--;
if(i==5){
cout<<"-------------------------------------------------- --------------------------------\n";
continue;
}
cout<<"|------------------------------------------------| |";
if(xxt>0)
pd(xx[xxt]),zc(xx[xxt],' '," ");
else
cout<<" ";
color(15);
cout<<"|\n";
xxt--;
if(xxt<0)xxt=0;
}
return;
}