改掉了已知BUG 还是只能用豌豆,向日葵和樱桃TNT
#include<bits/stdc++.h>
#include<windows.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? (1) : (0))
using namespace std;
int a[14][16]={
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,2,0,3,0,3,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
};int x=4,y=4,i,j,word=1;
string plantname[8]={"0","豌豆射手","向日葵","像素豌豆","樱桃TNT","雪球花","荆棘树桩","辐射路灯花"};
int plantsum[8]={5,5,5,5,1,1,1,1},sunshine=1000;
struct diren{
string name;
int gon;
int bao;
int xue;
int sun;
}
zombie={"普通僵尸",30,0,250,15},
zhizhang={"路障僵尸",30,10,330,20},
tietong={"铁桶僵尸",30,20,380,25},
guai={"\0",0,0,0};
struct plant{
string name;
int xue;
int sun;
int once;
int gong;
int slow;
int fire;
int gongsun;
}
wandou={"豌豆射手",120,100,999999,30,1,0,0},
sunflower={"向日葵",120,50,999999,25,1,0,3},
tnt={"樱桃TNT",1,150,0,500,1,10,0},
zhiwu={"\0",0,0,0,0,0,0,0},
zhiwu2={"\0",0,0,0,0,0,0,0};
int dayin2(){
for(i=y-4;i<=y+4;i++){
for(j=x-4;j<=x+4;j++){
if(i>=0&&i<=15&&j>=0&&j<=15){
if(i==y&&j==x){
cout<<"X";
continue;
}
else if(a[i][j]==1){
cout<<"1";
continue;
}
else if(a[i][j]==2||a[i][j]==3){
cout<<"!";
continue;
}
else
cout<<" ";
}
else
cout<<" ";
}
cout<<endl;
}
}
int zhandou(int leixing){
if(leixing==2)
guai=zombie;
if(leixing==3)
guai=zhizhang;
cout<<"你遇上了"<<guai.name<<"!"<<endl;
int m=0;
while(1){
cout<<"第一张卡:"<<endl;
for(i=word;i<=word*7;i++){
cout<<plantname[i]<<":"<<plantsum[i]<<"张 ";
}
cout<<"(输入"<<word<<"到"<<word*7<<")"<<endl;
cin>>m;
if(plantsum[m]==0)
cout<<"没有"<<plantname[m]<<"!"<<endl;
else if(m>word*7)
cout<<"输入错误!"<<endl;
else if(m<word)
cout<<"输入错误!"<<endl;
else
break;
}
switch(m){
case 1:zhiwu=wandou;plantsum[1]=plantsum[1]-1;break;
case 4:zhiwu=tnt;plantsum[4]-=1;break;
default:zhiwu=sunflower;plantsum[2]=plantsum[2]-1;
}
while(1){
cout<<"第二张卡:"<<endl;
for(i=word;i<=word*7;i++){
cout<<plantname[i]<<":"<<plantsum[i]<<"张 ";
}
cout<<"(输入"<<word<<"到"<<word*7<<")"<<endl;
cin>>m;
if(plantsum[m]==0)
cout<<"没有"<<plantname[m]<<"!"<<endl;
else if(m>word*7)
cout<<"输入错误!"<<endl;
else if(m<word)
cout<<"输入错误!"<<endl;
else
break;
}
switch(m){
case 1:zhiwu2=wandou;plantsum[1]=plantsum[1]-1;break;
case 4:zhiwu2=tnt;plantsum[4]-=1;break;
default:zhiwu2=sunflower;plantsum[2]=plantsum[2]-1;
}
cout<<"第一张卡:"<<zhiwu.name<<" 第二张卡:"<<zhiwu2.name<<endl;
while(1){
if(zhiwu.xue>0){
cout<<zhiwu.name<<"发起攻击,"<<guai.name<<"受到"<<zhiwu.gong+zhiwu.fire<<"点伤害!"<<endl;
guai.xue-=zhiwu.gong+zhiwu.fire;
sunshine+=zhiwu.gongsun;
if(guai.gon>10)
guai.gon*=zhiwu.slow;
if(zhiwu.once==0)
{
cout<<zhiwu.name<<"死亡!"<<endl;
zhiwu.xue=0;
Sleep(1000);
}
Sleep(1000);
}
if(guai.xue<1){
cout<<guai.name<<"倒下了"<<endl;
Sleep(1000);
cout<<"胜利!获得"<<guai.sun<<"点阳光"<<endl;
sunshine+=guai.sun;
Sleep(1000);
x++;
system("cls");
dayin2();
break;
}
if(zhiwu2.xue>0){
cout<<zhiwu2.name<<"发起攻击,"<<guai.name<<"受到"<<zhiwu2.gong+zhiwu2.fire<<"点伤害!"<<endl;
guai.xue-=zhiwu2.gong+zhiwu2.fire;
sunshine+=zhiwu2.gongsun;
if(guai.gon>10)
guai.gon*=zhiwu2.slow;
if(zhiwu2.once==0)
{
cout<<zhiwu2.name<<"死亡!"<<endl;
zhiwu2.xue=0;
Sleep(1000);
}
Sleep(1000);
}
if(guai.xue<1){
cout<<guai.name<<"倒下了"<<endl;
Sleep(1000);
cout<<"胜利!获得"<<guai.sun<<"点阳光"<<endl;
sunshine+=guai.sun;
Sleep(1000);
x++;
system("cls");
dayin2();
break;
}
else
{
cout<<guai.name<<"发起攻击,";
if(zhiwu.xue>0){
cout<<zhiwu.name<<"受到"<<guai.gon+guai.bao*word<<"点伤害!"<<endl;
zhiwu.xue-=guai.gon+guai.bao*word;
Sleep(1000);
if(zhiwu.xue<1)
{
cout<<zhiwu.name<<"死亡!"<<endl;
Sleep(1000);
}
}
else if(zhiwu2.xue>0){
cout<<zhiwu2.name<<"受到"<<guai.gon+guai.bao*word<<"点伤害!"<<endl;
zhiwu2.xue-=guai.gon+guai.bao*word;
Sleep(10);
if(zhiwu2.xue<1)
{
cout<<zhiwu2.name<<"死亡,失败!"<<endl;
Sleep(1000);
x++;
system("cls");
dayin2();
break;
}
}
}
}
}
int dayin(){
for(i=y-4;i<=y+4;i++){
for(j=x-4;j<=x+4;j++){
if(i>=0&&i<=15&&j>=0&&j<=15){
if(i==y&&j==x){
cout<<"X";
continue;
}
else if(a[i][j]==1){
cout<<"1";
continue;
}
else if(a[i][j]==2||a[i][j]==3){
cout<<"!";
continue;
}
else
cout<<" ";
}
else
cout<<" ";
}
cout<<endl;
}
if(a[y][x]==2){
zhandou(2);
}
if(a[y][x]==3){
zhandou(3);
}
}
int main(){
cout<<"小贴士:WSAD移动,“!”代表这个位置有怪。";
Sleep(2000);
system("cls");
dayin();
while(1){
if(KEY_DOWN(87)&&a[y-1][x]!=1){
y--;
system("cls");
dayin();
Sleep(100);
}
if(KEY_DOWN(83)&&a[y+1][x]!=1){
y++;
system("cls");
dayin();
Sleep(100);
}
if(KEY_DOWN(65)&&a[y][x-1]!=1){
x--;
system("cls");
dayin();
Sleep(100);
}
if(KEY_DOWN(68)&&a[y][x+1]!=1){
x++;
system("cls");
dayin();
Sleep(100);
}
}
}