简易 "植物大战僵尸"

新手上路

#include<iostream>
#include<stdlib.h>
#include<Windows.h>

using namespace std;

int crzn[100];
int crznn=0;
int crcrzn=0;
void getnumber()
{
for(crcrzn=0;crcrzn<100;crcrzn++)
{
	crzn[crcrzn]=rand()%5;
}
}

int map[5][9]=
{
	{0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0},
	{0,0,0,0,0,0,0,0,0},
};

void cw()
{
	cout<<"plant at?"<<endl;
	int a,b;
	cin>>a>>b;
	if((a>0&&a<6)&&(b>0&&b<9))
	{
		if(map[a-1][b-1]!=0)
			cout<<"not empty"<<endl;
		else
		    map[a-1][b-1]=1;
	}
	else cout<<"wrong!"<<endl;
}

void cz()
{
	int line;
	line=crzn[crznn%100];
	crznn++;
	map[line][8]=2;
}

void mz()
{
	int i,j;
	for(i=0;i<5;i++)
	{
		for(j=0;j<9;j++)
		{
			if(map[i][j]==2&&j!=0)
			{
				map[i][j-1]=2;
				map[i][j]=0;
			}
			else if(map[i][j]==2&&j==0)
			{
				system("cls");
				cout<<"zombie eat your brain!!"<<endl;
				break;
			}
		}
	}
}

void kz()
{
	int i,j,k;
	for(i=0;i<5;i++)
	{
		for(j=0;j<9;j++)
		{
			if(map[i][j]==1)
			{	
			    for(k=j;k<9;k++)
				{
					if(map[i][k]==2)
					{
						map[i][k]=0;
						break;
					}
				}
			}
		}
	}
}


		




void print()
{
	int i,j;
	for(i=0;i<5;i++)
	{
		for(j=0;j<9;j++)
		{
			if(map[i][j]==0)
				cout<<"X ";
			else if(map[i][j]==1)
				cout<<"→";
			else if(map[i][j]==2)
				cout<<"♀";

		}
		cout<<endl;
	}
	cout<<"fresh per second.0 is empty,1 is plant,2 is zombie"<<endl<<"one plant kill one zombie in 1 second"<<endl;
}

void main()
{
	getnumber();
	for(int i=0;i<120;i++)
	{
		print();
		
		
		mz();
		cz();
		kz();
		
		cw();
		system("cls");
	}
}



  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值