c语言炉石传说测试数据库,炉石传说(示例代码)

#include #include

using namespacestd;intmain()

{structattendant{int exist; //是否存在空位

int health; //随从生命值

int attack; //随从攻击力

};

attendant player1[8],player2[8];for(int i = 1;i <= 7;i++)

{

player1[i].exist= 0;

}for(int i = 1;i <= 7;i++)

{

player2[i].exist= 0;

}int n,Player1 = 30,Player2 = 30,flag = 1,pos,attack,health;stringsymbol;

cin>>n;while(n--)

{

cin>>symbol;if(flag % 2 == 1)

{if(symbol=="summon")

{

cin>>pos;

cin>>attack;

cin>>health;if(Player1 <= 0 || Player2 <= 0) //判断游戏是否已经结束

{continue;

}if(player1[pos].exist == 0)

{

player1[pos].exist= 1;

player1[pos].attack=attack;

player1[pos].health=health;

}else{for(int i = 6;i >= pos;i--)

{

player1[i+ 1].exist =player1[i].exist;

player1[i+ 1].attack =player1[i].attack;

player1[i+ 1].health =player1[i].health;

}

player1[pos].exist= 1;

player1[pos].attack=attack;

player1[pos].health=health;

}

}else if(symbol == "attack")

{intgong,sou;

cin>>gong;

cin>>sou;if(Player1 <= 0 || Player2 <= 0)

{continue;

}if(sou != 0)

{

player1[gong].health= player1[gong].health -player2[sou].attack;

player2[sou].health= player2[sou].health -player1[gong].attack;if(player1[gong].health <= 0 && gong == 7)

{

player1[gong].exist= 0;

}else if(player1[gong].health <= 0 && gong < 7)

{for(int i = gong + 1;i <= 7;i++)

{

player1[i- 1].exist =player1[i].exist;

player1[i].exist= 0;

player1[i- 1].health =player1[i].health;

player1[i- 1].attack =player1[i].attack;

}

}if(player2[sou].health <= 0 && sou == 7)

{

player2[sou].exist= 0;

}else if(player2[sou].health <= 0 && sou < 7)

{for(int i = sou + 1;i <= 7;i++)

{

player2[i- 1].exist =player2[i].exist;

player2[i- 1].health =player2[i].health;

player2[i- 1].attack =player2[i].attack;

}

}

}else{

Player2= Player2 -player1[gong].attack;

}

}else if(symbol == "end")

{

flag= flag + 1;

}

}

// 玩家二回合else if(flag % 2 == 0)

{if(symbol=="summon")

{

cin>>pos;

cin>>attack;

cin>>health;if(Player1 <= 0 || Player2 <= 0)

{continue;

}if(player2[pos].exist == 0)

{

player2[pos].exist= 1;

player2[pos].attack=attack;

player2[pos].health=health;

}else{for(int i = 6;i >= pos;i--)

{

player2[i+ 1].exist =player2[i].exist;

player2[i].exist= 0;

player2[i+ 1].attack =player2[i].attack;

player2[i+ 1].health =player2[i].health;

}

player2[pos].exist= 1;

player2[pos].attack=attack;

player2[pos].health=health;

}

}else if(symbol == "attack")

{intgong,sou;

cin>>gong;

cin>>sou;if(Player1 <= 0 || Player2 <= 0)

{continue;

}if(sou != 0)

{

player2[gong].health= player2[gong].health -player1[sou].attack;

player1[sou].health= player1[sou].health -player2[gong].attack;if(player2[gong].health <= 0 && gong == 7)

{

player2[gong].exist= 0;

}else if(player2[gong].health <= 0 && gong < 7)

{for(int i = gong + 1;i <= 7;i++)

{

player2[i- 1].exist =player2[i].exist;

player2[i- 1].health =player2[i].health;

player2[i- 1].attack =player2[i].attack;

}

}if(player1[sou].health <= 0 && sou == 7)

{

player1[sou].exist= 0;

}else if(player1[sou].health <= 0 && sou < 7)

{for(int i = sou + 1;i <= 7;i++)

{

player1[i- 1].exist =player1[i].exist;

player1[i- 1].health =player1[i].health;

player1[i- 1].attack =player1[i].attack;

}

}

}else{

Player1= Player1 -player2[gong].attack;

}

}else if(symbol == "end")

{

flag= flag + 1;

}

}

}int count1 = 0,count2 = 0; //记录随从数量

for(int i = 1;i <= 7;i++)

{if(player1[i].exist == 1)

{

count1++;

}

}for(int i = 1;i <= 7;i++)

{if(player2[i].exist == 1)

{

count2++;

}

}if(Player1 <= 0)

{

cout<< "-1" << "";

}else if(Player2 <= 0)

{

cout<< "1" << "";

}else{

cout<< "0" << "";

}

cout<< Player1 << "";

cout<< count1 << " ";if(count1 > 0)

{for(int i = 1;i <= 7;i++)

{if(player1[i].exist == 1)

{

cout<< player1[i].health <

}

}

cout<< "";

}else{

cout<< "";

}

cout<< Player2 << "";

cout<< count2 << " ";if(count2 > 0)

{for(int i = 1;i <= 7;i++)

{if(player2[i].exist == 1)

{

cout<< player2[i].health <

}

}

cout<< "";

}else{

cout<< "";

}return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值