栏目分类:
子分类:
返回
终身学习网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
终身学习网 > IT > 软件开发 > 后端开发 > C/C++/C#

C++实现Kingdomrush小游戏(尚未完结,不断更新)

C/C++/C# 更新时间:发布时间: 百科书网 趣学号

Kingdomrush为本人独立编写48小时产生的C++小游戏,实现效果尚未成熟,愿各位大佬多多帮助。

(Kingdomrush:本为游戏《王国保卫战》的英文名,这里小编作为该小游戏的化用,如有问题,请联系小编)

游戏简介:

Kingdomrush为本人独立编写的一款C++小游戏,以打怪为主题,效果尚未成熟,小编还会继续改进。

注意:游戏内为全英文!!!

先上效果:上图的字体来自某个字体生成网站:

patorjk.com

接下来是游戏代码(以下不是最优成果,小编会继续修改):

#include
#include
#include
#include
using namespace std;
int LOGIN,DIALOGUE,GAME_START;     //LOGIN从标题画面进入游戏   DIALOGUE进入对话   GAME_START正式开始
int location;     //location敌军出现地点
int re;     //re玩家攻击
int secs=10;     //secs系统等待时间
int point=50;     //point交易点数
int buy;     //buy购买武器代号
int hp=30,enemy_hp=20;//hp塔生命值
int rnd=0;
int RandomNumber(){     //随机生成敌人
	srand((unsigned)time(NULL));
	location=rand()%8+1;
    printf("The enemy appeared in area %d .n",location);
}
int isDead(){     //判断是否死亡
	if(hp==0){
		system("cls");
		system("color 75");
		printf("n");
		printf("      ▓██   ██▓ ▒█████   █    ██     ▄▄▄       ██▀███  ▓█████    ▓█████▄ ▓█████ ▄▄▄      ▓█████▄  ▐██▌ n");
		printf("       ▒██  ██▒▒██▒  ██▒ ██  ▓██▒   ▒████▄    ▓██ ▒ ██▒▓█   ▀    ▒██▀ ██▌▓█   ▀▒████▄    ▒██▀ ██▌ ▐██▌ n");
		printf("        ▒██ ██░▒██░  ██▒▓██  ▒██░   ▒██  ▀█▄  ▓██ ░▄█ ▒▒███      ░██   █▌▒███  ▒██  ▀█▄  ░██   █▌ ▐██▌ n");
		printf("        ░ ▐██▓░▒██   ██░▓▓█  ░██░   ░██▄▄▄▄██ ▒██▀▀█▄  ▒▓█  ▄    ░▓█▄   ▌▒▓█  ▄░██▄▄▄▄██ ░▓█▄   ▌ ▓██▒ n");
		printf("        ░ ██▒▓░░ ████▓▒░▒▒█████▓     ▓█   ▓██▒░██▓ ▒██▒░▒████▒   ░▒████▓ ░▒████▒▓█   ▓██▒░▒████▓  ▒▄▄  n");
		printf("         ██▒▒▒ ░ ▒░▒░▒░ ░▒▓▒ ▒ ▒     ▒▒   ▓▒█░░ ▒▓ ░▒▓░░░ ▒░ ░    ▒▒▓  ▒ ░░ ▒░ ░▒▒   ▓▒█░ ▒▒▓  ▒  ░▀▀▒ n");
		printf("       ▓██ ░▒░   ░ ▒ ▒░ ░░▒░ ░ ░      ▒   ▒▒ ░  ░▒ ░ ▒░ ░ ░  ░    ░ ▒  ▒  ░ ░  ░ ▒   ▒▒ ░ ░ ▒  ▒  ░  ░ n");
		printf("       ▒ ▒ ░░  ░ ░ ░ ▒   ░░░ ░ ░      ░   ▒     ░░   ░    ░       ░ ░  ░    ░    ░   ▒    ░ ░  ░     ░ n");
		printf("       ░ ░         ░ ░     ░              ░  ░   ░        ░  ░      ░       ░  ░     ░  ░   ░     ░    n");
		printf("       ░ ░                                                        ░                       ░            n");
		exit(0);
	}
}
void printMap(){
	printf("             ┌──────┐n");
	printf("╔══════════╦═╡ ⊙");
	cout<=i) printf("|");
		else printf(" ");
	printf("╞═╝n");
	printf("  └────────────────────────────┘n");
}
int main(){
	system("chcp 65001");
	system("color 74");
	printf("n");
	printf("     ██╗  ██╗ ██╗ ███╗   ██╗  ██████╗  ██████╗   ██████╗  ███╗   ███╗ ██████╗  ██╗   ██╗ ███████╗ ██╗  ██╗n");
    printf("     ██║ ██╔╝ ██║ ████╗  ██║ ██╔════╝  ██╔══██╗ ██╔═══██╗ ████╗ ████║ ██╔══██╗ ██║   ██║ ██╔════╝ ██║  ██║n");
	printf("     █████╔╝  ██║ ██╔██╗ ██║ ██║  ███╗ ██║  ██║ ██║   ██║ ██╔████╔██║ ██████╔╝ ██║   ██║ ███████╗ ███████║n");
	printf("     ██╔═██╗  ██║ ██║╚██╗██║ ██║   ██║ ██║  ██║ ██║   ██║ ██║╚██╔╝██║ ██╔══██╗ ██║   ██║ ╚════██║ ██╔══██║n");
	printf("     ██║  ██╗ ██║ ██║ ╚████║ ╚██████╔╝ ██████╔╝ ╚██████╔╝ ██║ ╚═╝ ██║ ██║  ██║ ╚██████╔╝ ███████║ ██║  ██║n");
	printf("     ╚═╝  ╚═╝ ╚═╝ ╚═╝  ╚═══╝  ╚═════╝  ╚═════╝   ╚═════╝  ╚═╝     ╚═╝ ╚═╝  ╚═╝  ╚═════╝  ╚══════╝ ╚═╝  ╚═╝n");
	printf("n");
	printf("Press any key to enter the game.n");
	system("pause >nul");
	system("cls");
	system("color 79");
	printf("Look at the map below.n");
	printf("n");
	printf("You have a tower(|+|) on the left of the map. Make sure your tower is not destroyed when attacked.n");
	printf("Your tower has 30 HP. If HP become 0, GAME OVER!!!n");
	printf("So, if the enemy fire to your tower, you'd better protect it with your weapon.n");
	printf("Are you ready? Come on, protect your kingdom!n");
	printf("n");
	printMap();
	printf("MAP NOTE:n");
	printf("area 1   area 2   area 3n");
	printf("tower    area 4   area 5n");
	printf("area 6   area 7   area 8n");
	printf("n");
	printf("Press any key if you are ready.n");
	system("pause >nul");
	system("cls");
	system("color 76");
	printf("Martin: Hey, gay! The Viking is appoarching!n");
	printf("Mary: Go on the tower and get ready for fight!n");
	printf("Martin: It's your turn.There are several types of weapon for you:n");
	printf("         1.crossbow(1)    2.cavalryman(2)    3.cannon(3)    4.incendiary(4)    5.bombardment aircraft(5)n");
    printf("           15 points        30 points          50 points      75 points          100 pointsn");
	printf("Martin: You can get points by killing the enemy. Stick to 30 waves of enemies.n");
	printf("n");
	printMap();
	printf("n");
	printf("Mary: Press any key and start game.n");
	system("pause >nul");
	system("cls");
	system("color 70");
	printf("n");
	printf("1.crossbow(1)    2.cavalryman(2)    3.cannon(3)    4.incendiary(4)    5.bombardment aircraft(5)n");
	printf("  15 points        30 points          50 points      75 points          100 pointsn");
	printf("n");
	for(rnd=1;rnd<=30;rnd++){
		printMap();
		//随机生成敌人
	    RandomNumber();
	    printf("Fire to area:n");
	    scanf("%d",&re);
	    enemy_hp=20;
	    //判断是否击杀敌人
	    if(re==location){
	    	for(int i=1;i<=4;i++){
	    		enemy_hp-=5;
	    		printf("n");
	    		printf("HP of enemy: %d n",enemy_hp);
	    		printf("HP of tower: %d n",hp);
	    		Sleep(1000);
			}
	    	if(enemy_hp==0){
	    		printf("n");
	    		printf("You destroyed the %d  wave of enemies!n",rnd);
	    		point+=5;
	            printf("point: %d n",point);
	            printf("n");
			}
	        Sleep(3000);
	    }
	    else{
		    printf("This wave of enemies has never been hit. Come on next time!n");
		    hp-=5;
		    printf("HP of tower: %d n",hp);
		    printf("point: %d n",point);
		    printf("n");
			Sleep(3000);
		}
		//判断是否死亡
		isDead();
	}
	return 0;
}
//版权声明:本代码由沾花把玖独立编写,未经允许,请勿抄袭!(感谢SuperAlex4等人对沾花把玖的帮助)

本文内容为小编自己汇总,内容可能会有错误或疏漏,感谢大家的提议!

记得点赞和关注哦~

转载请注明:文章转载自 www.051e.com
本文地址:http://www.051e.com/it/1033919.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 ©2023-2025 051e.com

ICP备案号:京ICP备12030808号