植物大战僵尸(字符版)

//包含PVZ从一行到僵王内容 
#include<algorithm>
#include<fstream>
#include<iostream>
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<windows.h>
#include<conio.h>
#include <time.h>
#include <stdlib.h>
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include <windows.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
int x,y;
int Boss=100;
int map1[5][9];
int map2[3][9];
int map3[9];
int kill;
int xrk;
int yg;
int out1() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"1豌豆射手(100阳光)"<<endl;
	cout<<"阳光:"<<yg<<"击杀:"<<kill<<endl;
	for(int i=0; i<2; i++) {
		for(int j=0; j<9; j++) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"O";
		}
		cout<<endl;
	}
	for(int i=0; i<9; i++) {
		if(map3[i]==9) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			cout<<"P";
		} else if(map3[i]==7) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN|FOREGROUND_RED);
			cout<<"Y";
		} else if(i==y) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
			cout<<"8";
		} else {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
			cout<<"O";
		}
	}
	cout<<endl;
	for(int i=0; i<2; i++) {
		for(int j=0; j<9; j++) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"O";
		}
		cout<<endl;
	}
}
int out2() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	cout<<"1豌豆射手(100阳光)2向日葵(50阳光)"<<endl;
	cout<<"阳光:"<<yg<<"击杀:"<<kill<<endl;
	for(int i=0; i<1; i++) {
		for(int j=0; j<9; j++) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"O";
		}
		cout<<endl;
	}
	for(int i=0; i<3; i++) {
		for(int j=0; j<9; j++) {
			if(map2[i][j]==9) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"P";
			} else if(map2[i][j]==7) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN|FOREGROUND_RED);
				cout<<"Y";
			} else if(i==x&&j==y) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
				cout<<"8";
			} else {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"O";
			}
		}
		cout<<endl;
	}
	for(int i=0; i<1; i++) {
		for(int j=0; j<9; j++) {
			SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
			cout<<"O";
		}
		cout<<endl;
	}
}
int out3() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	cout<<"1豌豆射手(100阳光)2向日葵(50阳光)3樱桃炸弹(25阳光)"<<endl;
	cout<<"阳光:"<<yg<<"击杀:"<<kill<<endl;
	for(int i=0; i<5; i++) {
		for(int j=0; j<9; j++) {
			if(map1[i][j]==9) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"P";
			} else if(map1[i][j]==7) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN|FOREGROUND_RED);
				cout<<"Y";
			} else if(i==x&&j==y) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY);
				cout<<"8";
			}else if(map1[i][j]==4){
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
				cout<<"O";
			} else {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"O";
			}
		}
		cout<<endl;
	}
}
int out4() {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
	cout<<"1豌豆射手(100阳光)2向日葵(50阳光)3樱桃炸弹(25阳光)"<<endl;
	cout<<"阳光:"<<yg<<"BOSS血量:"<<Boss<<endl;
	for(int i=0; i<5; i++) {
		for(int j=0; j<9; j++) {
			if(map1[i][j]==9) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"P";
			} else if(map1[i][j]==7) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN|FOREGROUND_RED);
				cout<<"Y";
			} else if(i==x&&j==y) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY|FOREGROUND_BLUE);
				cout<<"8";
			}else if(map1[i][j]==4){
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
				cout<<"O";
			} else {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"O";
			}
		}
		cout<<endl;
	}
}
int x_what(int x) {//取随机数
	srand((unsigned)time(NULL));
	return( rand() % x);
}
int Z1() {
	y--;
	for(int i=0; i<9; i++) {
		if(map3[i]==9&&i<y) {
			y=8;
			x=1;
			kill++;
		}
	}
	map3[y]=0;
}
int Z2() {
	y--;
	for(int i=0; i<9; i++) {
		if(map2[x][i]==9) {
			y=8;
			x=x_what(3);
			kill++;
		}
	}
	map2[x][y]=0;
}
int Z3() {
	y--;
	for(int i=0; i<9; i++) {
		if(map1[x][i]==9) {
			y=8;
			x=x_what(5);
			kill++;
		}
		if(map1[x][i]==4){
			y=8;
			x=x_what(5);
			map1[x][y]=0;
			kill++;
		} 
	}
	for(int i=0;i<5;i++){
		for(int j=0;j<9;j++){
			if(map1[i][j]==4){
				y=8;
				x=x_what(5);
				map1[i][j]=0;
				kill++;
			}
		}
	}
	map1[x][y]=0;
}
int Z4() {
	y--;
	for(int i=0; i<9; i++) {
		if(map1[x][i]==9) {
			Boss-=10;
		}
		if(map1[x][i]==4){
			Boss-=10;
		} 
	}
	for(int i=0;i<5;i++){
		for(int j=0;j<9;j++){
			if(map1[i][j]==4){
				Boss-=10;
			}
		}
	}
	map1[x][y]=0;
}
int first() {
	yg=200;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"--------------"<<endl;
	cout<<"|植物大战僵尸|"<<endl;
	cout<<"| 任意键开始 |"<<endl;
	cout<<"--------------"<<endl;
	y=8;
	x=1;
	while(!kbhit()) {

	}
	system("cls");
	cout<<"玩法:种植植物,打败僵尸。"<<endl;
	cout<<"种植方法:按键种植对应号码植物,输入坐标(第一关0-8,第二关0 0-2 8,第三关0 0-4 8)。"<<endl;
	cout<<"植物能力:豌豆射手:发射子弹打僵尸,樱桃炸弹:炸飞全场僵尸,向日葵:生产阳光。"<<endl;
	cout<<"提示:如果阳光不够种豌豆射手,可以种向日葵生产阳光。种不了的话,就先种个樱桃炸弹。"<<endl;
	Sleep(4500);
	system("cls");
}
int play1() {
	char c;
	int a,b;
	if(kbhit()) {
		c=getch();
		if(c=='1'&&yg>=100) {
			cin>>b;
			map3[b]=9;
			yg-=100;
		}
	}
}
int play2() {
	char c;
	int a,b;
	if(kbhit()) {
		c=getch();
		if(c=='1'&&yg>=100) {
			cin>>a>>b;
			map2[a][b]=9;
			yg-=100;
		}
		if(c=='2'&&yg>=50) {
			yg-=50;
			cin>>a>>b;
			map2[a][b]=7;
			xrk++;
		}
	}
}
int play3() {
	char c;
	int a,b;
	if(kbhit()) {
		c=getch();
		if(c=='1'&&yg>=100) {
			cin>>a>>b;
			map1[a][b]=9;
			yg-=100;
		}
		if(c=='2'&&yg>=50) {
			yg-=50;
			cin>>a>>b;
			map1[a][b]=7;
			xrk++;
		}
		if(c=='3'&&yg>=25){
			yg-=25;
			cin>>a>>b;
			map1[a][b]=4;
		}
	}
}
int main() {
	first();
	int play_num=0;
	int key=0;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"一波攻势来袭!";
	Sleep(2000);
	while(key==0) {
		yg=200;
		kill=0;
		y=8;
		while(true) {
			system("cls");
			out1();
			play1();
			Z1();
			if(y==0) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"僵尸们吃掉了你的脑子!";
				Sleep(2000);
				break;
			}
			if(kill>=10){
				key=1;
				break;
			}
			yg+=25;
			yg+=xrk*25;
			Sleep(500);
		}
	}
	key=0; 
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"一大波攻势!";
	Sleep(2000);
	while(key==0) {
		yg=200;
		kill=0;
		y=8;
		while(true) {
			system("cls");
			out2();
			play2();
			Z2();
			if(y==0) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"僵尸们吃掉了你的脑子!";
				Sleep(2000);
				break;
			}
			if(kill>=30){
				key=1;
				break;
			}
			yg+=25;
			yg+=xrk*25;
			Sleep(500);
		}
	}
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"一大波僵尸来袭!";
	Sleep(2000);
	key=0;
	while(key==0) {
		yg=200;
		kill=0;
		y=8;
		while(true) {
			system("cls");
			out3();
			play3();
			Z3();
			if(y==0) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"僵尸们吃掉了你的脑子!";
				Sleep(2000);
				break;
			}
			if(kill>=50){
				key=1;
				break;
			}
			yg+=25;
			yg+=xrk*25;
			Sleep(500);
		}
	}
	key=0;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"僵王博士的复仇!(这次是改造机甲,因为放僵尸基本没用,要自己上。)";
	Sleep(2000);
	while(Boss>0) {
		Boss=100;
		yg=200;
		kill=0;
		x=2;
		y=8;
		while(true) {
			system("cls");
			out4();
			play3();
			Z4();
			if(y==0) {
				SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
				cout<<"僵尸们吃掉了你的脑子!";
				Sleep(2000);
				break;
			}
			if(Boss<=0){
				key=1;
				break;
			}
			yg+=25;
			yg+=xrk*25;
			Sleep(500);
		}
	}
	key=0;
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
	cout<<"击退僵尸!";
	Sleep(2000);
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值