黑暗森林df5
超级实用版
/********************************************************************************************************************************************************************
*********************************************************************************************************************************************************************
程序名称: 黑暗森林5
修改: eywb
修改日期 版本号 修改人
20170824 Version 1.2.0 eywb
说明:
本产品并非初稿 更新内容:修复bug与增加噩梦模式
——··警告:个 人 所 有 请 勿 盗 程 序··——
【点 击 F11 开 始 游 戏】
*********************************************************************************************************************************************************************
***********************************************************************************************************************************************************************
*/
// ↓ 下 面 是 程 序 【eywb修改】 + 说 明【eywb添加】 + 版 本 信 息 【还是eywb添加】 ↓
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:自己填写
输出参数:自己填写
返回值:s_OK返回成功,否则执行失败
其他说明:无
修改日期 版本号 修改人 修改内容
20170824 Version 1.0.1 eywb 如下
***********************************************************************************************************************************************************************
*/
#include<iostream>
#include<cmath>
#include<cstdio>
#include<windows.h>
#include<string>
#include<cstdlib>
#include<time.h>
#include <conio.h>
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:#define
输出参数:const
返回值:s_OK返回成功,否则执行失败
其他说明:添加头文件
修改日期 版本号 修改人 修改内容
20170824 Version 1.0.2 eywb 修改地图头文件
***********************************************************************************************************************************************************************
*/
#define SetColorWhiteonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE)//输出地图颜色 【红】【绿】【蓝】
#define SetColorRedonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED)//输出地图颜色【单独定义】
#define SetColorGreenonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN)//输出地图颜色【单独定义】
#define SetColorYellowonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_GREEN)//输出地图颜色【单独定义】
#define SetColorBlueonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_BLUE)//输出地图颜色【单独定义】
#define SetColorMagentaonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_RED | FOREGROUND_BLUE)//输出地图颜色【单独定义】
#define SetColorCyanonBlack SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY |FOREGROUND_GREEN | FOREGROUND_BLUE)//输出地图颜色【单独定义】
#define SetColorBlackonGray SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |BACKGROUND_INTENSITY)//输出地图颜色【单独定义】
#define SetColorBlackonRed SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |FOREGROUND_INTENSITY | BACKGROUND_RED)//输出地图颜色【单独定义】
#define SetColorRedonWhite SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY |FOREGROUND_INTENSITY | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |FOREGROUND_RED)//输出地图颜色【单独定义】
#define SetBEGIN SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),FOREGROUND_INTENSITY)//初始化地图坐标
#define SetNULL SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),BACKGROUND_INTENSITY)//初始化二维地图
using namespace std;
const int csm_x=5,csm_y=5;//地图大小和传送门的坐标,
const char csm='@';//传送门入口,开关
bool win=false;
int maxnum=30;
char map[30][30];
bool way[30][30];
short mobs=0,Potation_time;
double MAXP;
bool easterEgg=0;//彩蛋模式是否启用
struct Info{
char looks;//皮肤
int x,y;//坐标
int g;//攻击力
double xl;//血量
bool die;//是否死亡
};
struct N{
char man1;
char other1;
char man2;
char other2;
char man3;
char other3;
char man4;
char other4;
}Skin_bag;
Info man,other1;
void init_skin_bag(void){
Skin_bag.man1=char(1);
Skin_bag.other1=char(2);
Skin_bag.man2=char(15);
Skin_bag.other2=char(267);
Skin_bag.man3='A';
Skin_bag.other3='B';
Skin_bag.man4=char(24);
Skin_bag.other4=char(25);
return;
}
void youwin(void){
cout<<"\\ / /--\\ | | | | | | |\\ |\n";
cout<<" \\ / / \\ | | | | | | | \\ |\n";
cout<<" \\/ | | | | | | | | | \\ |\n";
cout<<" | \\ / \\ / \\ /\\ | | | \\ |\n";
cout<<" | \\--/ \\__/ \\_/ \\_/ | | \\|\n";
return;
}
void youdie(void){
cout<<"\\ / /--\\ | | |---\\ |-| |---| ||\n";
cout<<" \\ / / \\ | | | \\ | | ||\n";
cout<<" \\/ | | | | | | | |---| ||\n";
cout<<" | \\ / \\ / | / | | \n";
cout<<" | \\--/ \\--/ |---/ |_| |---| O\n";
return;
}
void youexit(void){
system("cls");
cout<<"\t ----+----\n";
cout<<"\t --|--\\ \n";
cout<<"\t |\\___| |---\\\n";
cout<<"\t |-------|-----| \n";
cout<<"\t |\n";
cout<<"\t "<<man.looks<<" \n\n\n";
cout<<"\t_____________"<<other1.looks<<"_______________\n";
cout<<"\t YOU EXIT THE GAME!!";
return;
}
void init(void){
system("cls");
cout<<"|----\\ ___ |---\\ | / \n";
cout<<"| \\ / \\ | | | /\n";
cout<<"| | /___\\ |---/ |/\n";
cout<<"| / / \\ | \\ | \\\n";
cout<<"|----/ / \\ | \\ | \\\n\n";
cout<<"\t|---| /--\\ |---\\ |---| /---\\ \\-----\\\n";
cout<<"\t| / \\ | | | | |\n";
cout<<"\t|---| | | |---/ |---| \\---\\ |\n";
cout<<"\t| \\ / | \\ | | |\n";
cout<<"\t| \\--/ | \\ |---| \\---/ |\n";
cout<<"\t 黑暗森林5\n";
cout<<" \t 按1开始游戏 按2结束游戏\n";
cout<<" \t 按3获得帮助 按4挑战彩蛋模式\n" ;
return;
}
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:无
输出参数:自己填写
返回值:main函数返回成功,否则执行失败
其他说明:修改开始页面
修改日期 版本号 修改人 修改内容
20170824 Version 1.0.3 eywb 函数框架修改
***********************************************************************************************************************************************************************
*/
void showdata(void){
for(int i=0;i<maxnum;i++){
for(int j=0;j<maxnum;j++){
if(Potation_time!=0){
SetColorGreenonBlack;
if(map[i][j]=='1'){
SetNULL;
printf(" ");
}
else if(map[i][j]=='2'){
SetNULL;
printf("--");
}
else if(map[i][j]=='3'){
SetNULL;
printf("==");
}
else if(map[i][j]=='4'){
SetNULL;
printf("##");
}
else if(map[i][j]=='5'){
SetNULL;
printf(" .");
}
else if(map[i][j]=='6'){
map[i][j]='.';
printf(" %c",map[i][j]);
}
else if(i==man.x&&j==man.y){
printf("%2c",man.looks);
}
else if(i==other1.x && j==other1.y){
printf("%2c",other1.looks);
}
else{
printf(" %c",map[i][j]);
}
}
else if(way[i][j]==true){
if(i==man.x && j==man.y){
SetColorCyanonBlack;
printf("%2c",man.looks);
}
else if(i==other1.x && j==other1.y){
SetColorCyanonBlack;
printf("%2c",other1.looks);
}
else if(map[i][j]=='1'){
SetColorBlackonRed;
printf(" ");
}
else if(map[i][j]=='2'){
SetColorBlackonRed;
printf("--");
}
else if(map[i][j]=='3'){
SetColorBlackonRed;
printf("==");
}
else if(map[i][j]=='4'){
SetColorBlackonRed;
printf("##");
}
else if(map[i][j]=='5'){
SetColorBlackonRed;
printf(" .");
}
else if(map[i][j]=='6'){
map[i][j]='.';
printf(" %c",map[i][j]);
}
else if(map[i][j]=='&'){
SetColorMagentaonBlack;
printf(" %c",map[i][j]);
}
else if(map[i][j]=='O'){
SetColorYellowonBlack;
printf(" %c",map[i][j]);
}
else if(map[i][j]=='.'){
SetBEGIN;
printf(" %c",map[i][j]);
}
else if(Potation_time!=0){
printf(" %c",map[i][j]);
}
else if(map[i][j]==csm){
SetColorWhiteonBlack;
printf(" %c",map[i][j]);
}
}
else{
SetBEGIN;
cout<<" ";
}
}
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:setBEGIN
输出参数:const
返回值:VOID无返回值
其他说明:添加头文件
修改日期 版本号 修改人 修改内容
20170824 Version 1.0.4 eywb 修改函数名称
***********************************************************************************************************************************************************************
*/
cout<<endl;
}
SetBEGIN;
return;
}
void man_move(char key,int& zf,short& mobs){
if(man.x==csm_x && man.y==csm_y && mobs>=3){
win=true;
return;
}
if(key!='A' && key!='D' && key!='S' && key!='W')return;
else{
map[man.x][man.y]='.';
if(key=='W' && man.x>0){
if(map[man.x-1][man.y]=='1' ||map[man.x-1][man.y]=='2' ||map[man.x-1][man.y]=='3'
||map[man.x-1][man.y]=='4' ||map[man.x-1][man.y]=='5'){
map[man.x-1][man.y]+=1;
return;
}
man.x--;
if(man.x==other1.x && man.y==other1.y){
man.xl-=other1.g;
other1.x=other1.y=0;
other1.die=true;
zf+=50;
if(man.xl<=0)man.die=true;
mobs++;
}
else if(map[man.x][man.y]=='&'){
zf+=10;
man.xl+=rand()%3;
Potation_time+=rand()%5+4;
}
else if(map[man.x][man.y]=='O'){
zf+=5;
}
}
else if(key=='S' && man.x<maxnum-1){
if(map[man.x+1][man.y]=='1' ||map[man.x+1][man.y]=='2'||map[man.x+1][man.y]=='3'
||map[man.x+1][man.y]=='4'||map[man.x+1][man.y]=='5'){
map[man.x+1][man.y]+=1;
return;
}
man.x++;
if(man.x==other1.x && man.y==other1.y){
man.xl-=other1.g;
other1.x=other1.y=0;
zf+=50;
other1.die=true;
if(man.xl<=0)man.die=true;
mobs++;
}
else if(map[man.x][man.y]=='&'){
zf+=10;
man.xl+=rand()%3;
Potation_time+=rand()%5+4;
}
else if(map[man.x][man.y]=='O'){
zf+=5;
}
}
else if(key=='A' && man.y>0){
if(map[man.x][man.y-1]=='1' ||map[man.x][man.y-1]=='2'||map[man.x][man.y-1]=='3'
||map[man.x][man.y-1]=='4'||map[man.x][man.y-1]=='5'){
map[man.x][man.y-1]+=1;
return;
}
man.y--;
if(man.x==other1.x && man.y==other1.y){
man.xl-=other1.g;
other1.x=other1.y=0;
zf+=50;
other1.die=true;
if(man.xl<=0)man.die=true;
mobs++;
}
else if(map[man.x][man.y]=='&'){
zf+=10;
man.xl+=rand()%3;
Potation_time+=rand()%5+4;
}
else if(map[man.x][man.y]=='O'){
zf+=5;
}
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:#define
输出参数:const
返回值:s_OK返回成功,否则执行失败
其他说明:添加头文件
修改日期 版本号 修改人 修改内容
20170824 Version 1.0.5 eywb 修改模式
***********************************************************************************************************************************************************************
*/
}
else if(key=='D' && man.y<maxnum-1){
if(map[man.x][man.y+1]=='1' ||map[man.x][man.y+1]=='2'||map[man.x][man.y+1]=='3'
||map[man.x][man.y+1]=='4'||map[man.x][man.y+1]=='5'){
map[man.x][man.y+1]+=1;
return;
}
man.y++;
if(man.x==other1.x && man.y==other1.y){
man.xl-=other1.g;
zf+=50;
other1.die=true;
if(man.xl<=0)man.die=true;
mobs++;
}
else if(map[man.x][man.y]=='&'){
zf+=10;
man.xl+=rand()%3;
Potation_time+=rand()%5+4;
}
else if(map[man.x][man.y]=='O'){
zf+=5;
}
}
way[man.x][man.y]=true;
if(man.x>0)way[man.x-1][man.y]=true;
if(man.y>0)way[man.x][man.y-1]=true;
if(man.y<maxnum-1)way[man.x][man.y+1]=true;
if(man.x<maxnum-1)way[man.x+1][man.y]=true;
}
return;
}
bool CanMove(int m,int&x,int&y){
if(m==0){
if(x+1<maxnum && map[x+1][y]=='.' && x+1!=man.x){
x++;
return true;
}
return false;
}
else if(m==1){
if(x-1>=0 && map[x-1][y]=='.' && x-1!=man.x){
x--;
return true;
}
return false;
}
else if(m==2){
if(y+1<maxnum && map[x][y+1]=='.' && y+1!=man.y){
y++;
return true;
}
return false;
}
else if(m==3){
if(y-1>=0 && map[x][y-1]=='.' && y-1!=man.y){
y--;
return true;
}
return false;
}
return true;
}
void other1_move(void){
if(other1.die==false){
int x;
x=rand()%4;
for(int i=0;i<20;i++){
x=rand()%4;
if(CanMove(x,other1.x,other1.y)==true)break;
}
}
else if(other1.die==true){
int x=rand()%maxnum;
int y=rand()%maxnum;
while(map[x][y]!='.'){
x=rand()%maxnum;
y=rand()%maxnum;
}
other1.x=x;
other1.y=y;
other1.die=false;
}
return;
}
/********************************************************************************************************************************************************************
程序名称:黑暗森林5
初稿:空间穿越者、commertton
修改:eywb
输入参数:无
输出参数:无
返回值:s_OK返回成功,否则执行失败
其他说明:无
修改日期 版本号 修改人 修改内容
20170824 Version 1.1.0 eywb 添加角色
***********************************************************************************************************************************************************************
*/
void put_coin(int n){
int x,y;
for(int i=0;i<n;i++){
x=rand()%maxnum;
y=rand()%maxnum;
while(map[x][y]!='.'){
x=rand()%maxnum;
y=rand()%maxnum;
}
map[x][y]='O';
}
return;
}
void put_potation(int n){
int x,y;
for(int i=0;i<n;i++){
x=rand()%maxnum;
y=rand()%maxnum;
while(map[x][y]!='.'){
x=rand()%maxnum;
y=rand()%maxnum;
}
map[x][y]='&';
}
return;
}
void put_block(int n){
int x,y;
for(int i=0;i<n;i++){
x=rand()%maxnum;
y=rand()%maxnum;
while(map[x][y]!='.'){
x=rand()%maxnum;
y=rand()%maxnum;
}
map[x][y]='1';
}
return;
}
void start(void){
system("cls");
int zf=0,sj=0;
for(int i=0;i<maxnum;i++){
for(int j=0;j<maxnum;j++){
way[i][j]=false;
map[i][j]='.';
}
}
if(easterEgg==1){
man.x=man.y=9;
way[man.x][man.y]=true;
man.xl=15;man.g=4;
man.die=false;other1.die=false;
other1.xl=4;
other1.g=3;
Potation_time=0;
win=false;
maxnum=15;
int t=rand()%4;
cout<<"彩蛋模式【已修改】:"<<t<<"\n";
getch();
for(int i=0;i<maxnum;i++){
for(int j=0;j<maxnum;j++){
if(t==0){
map[i][j]='5';
}
else if(t==1){
map[i][j]='O';
}
else if(t==2){
map[i][j]='&';
}
else if(t==3){
map[i][j]='.';
}
}
}
map[man.x][man.y]='.';
map[other1.x][other1.y]='.';
}
else{
cout<<"请输入游戏难度:1级,2级,3级(3级可能很卡),4级[eywb添加]←注意,由于过于巨大,请全屏游玩 ,输入0挑战噩梦模式←电脑不好的不要轻易尝试 5级【正在开发中 约1.2.0版本后可使用】:";
char n;
n=getch();
system("cls");
if(n=='1'){
cout<<"简单模式...\n";
maxnum=15;
}
else if(n=='2'){
cout<<"中等模式...\n";
maxnum=25;
}
else if(n=='3'){
cout<<"困难模式...\n";
maxnum=30;
}
else if(n=='4'){
cout<<"级难模式[eywb添加]...\n";
maxnum=50;
}
else if(n=='0'){
cout<<"噩梦模式[eywb添加]...\n";
maxnum=250;
}
else{
cout<<"退出...\n";
return;
}
man.x=man.y=9;
way[man.x][man.y]=true;
man.xl=15;man.g=4;
man.die=false;other1.die=false;
other1.xl=4;
other1.g=3;
Potation_time=0;
win=false;
put_block(maxnum+10);
cout<<"正在生成"<<maxnum+10<<"堵墙...\n";
int Ra1=rand()%6+maxnum-10;
put_potation(Ra1);
cout<<"正在生成"<<Ra1<<"瓶药水...\n";
int Ra2=rand()%6+maxnum-10;
put_coin(Ra2);
cout<<"正在生成"<<Ra2<<"个金币...\n";
Sleep(1000);
system("cls");
}
char key;
mobs=0;
while(1){
showdata();
SetBEGIN;
cout<<"血量:"<<man.xl<<"/15 时间:"<<sj++<<" 得分:"<<zf<<" 药水时间:"<<Potation_time<<" 怪物死亡次数:"<<mobs<<"/3"<<endl;
key=getch();
key=char(toupper(key));
if(key=='E'){
youexit();
getch();
break;
}
man_move(key,zf,mobs);
other1_move();
if(Potation_time>0)--Potation_time;
system("cls");
if(man.die==true){
youdie();
cout<<"血量:"<<man.xl<<" 时间:"<<sj<<" 得分:"<<zf<<endl;
getch();
return;
}
if(mobs>=3){
map[csm_x][csm_y]=csm;
}
if(win==true){
youwin();
break;
}
}
MAXP=max(MAXP,zf*2-sj+man.xl);
cout<<"\n总分:"<<zf<<" 时间:"<<sj<<" 最后评价:"<<zf*2-sj+man.xl;
cout<<"\n最高最后评价:"<<MAXP;
if(zf*2-sj+man.xl>=MAXP && easterEgg==0)cout<<"刷新最大纪录!\n";
else cout<<"\n";
getch();
return;
}
void about(void){
SetColorWhiteonBlack;
cout<<"Dark Forest V4.0:Mobs' killer\n"
<<"Move:\n"
<<"\tW:Go up\n"
<<"\tS:Go down\n"
<<"\tA:Go left\n"
<<"\tD:Go right\n"
<<"\tX:Do nothing\n"
<<"\tE:exit the game\n"
<<"Thing:";
SetColorMagentaonBlack;
cout<<"\t&:Potation\n";
SetColorYellowonBlack;
cout<<"\tO:Coin\n";
SetColorRedonBlack;
cout<<"\t :block\n";
SetColorCyanonBlack;
cout<<"\t"<<man.looks<<":You\n"
<<"\t"<<other1.looks<<":Mobs\n";
SetBEGIN;
getch();
return;
}
void maker(void){
cout<<"Maker\n"
<<"\tTime Traveller(滕思远)(主编)\n"
<<"\tMC command(牟昱东)(后期)\n"
<<"\tTime Traveller(第五版全部代码)\n"
<<" \eyeywb(张恩域)(备注修改)\n";
getch();
return;
}
void SetNewSkin(void){
int temp;
freopen("Skin.txt","w",stdout);
printf("%d %d\n",man.looks,other1.looks);
fclose(stdout);
return;
}
void skin(void){
int n;
printf("Thows a shin:\n");
printf("\t1:%2c%2c(经典)\n",Skin_bag.man1,Skin_bag.other1);
printf("\t2:%2c%2c(蛛蝎)\n",Skin_bag.man2,Skin_bag.other2);
printf("\t3:%2c%2c(字母)\n",Skin_bag.man3,Skin_bag.other3);
printf("\t4:%2c%2c(箭头)\n",Skin_bag.man4,Skin_bag.other4);
n=getch();
while(n>4 && n<=0){
n=getch();
}
if(n=='1'){
man.looks=Skin_bag.man1;
other1.looks=Skin_bag.other1;
}
if(n=='2'){
man.looks=Skin_bag.man2;
other1.looks=Skin_bag.other2;
}
if(n=='3'){
man.looks=Skin_bag.man3;
other1.looks=Skin_bag.other3;
}
if(n=='4'){
man.looks=Skin_bag.man4;
other1.looks=Skin_bag.other4;
}
cout<<"Now you SKin:"<<man.looks<<" Mobs' Skin:"<<other1.looks<<endl;
getch();
return;
}
void help(void){
while(1){
char n;
system("cls");
cout<<"1:关于...[已修改]\n"
<<"2:作者...[已修改]\n"
<<"3:皮肤包[已修改]\n"
<<"4:查看源代码(可能很卡)[已修改]\n"
<<"5:清除最高纪录[已修改]\n"
<<"6:退出[已修改]\n";
n=getch();
while(n>4 && n<=0){
n=getch();
}
if(n=='1'){
system("cls");
about();
}
else if(n=='2'){
system("cls");
maker();
}
else if(n=='3'){
system("cls");
skin();
}
else if(n=='4'){
system("cls");
cout<<"Are you sure? 1:Yes 0:No\n";
if(getch()=='1'){
system("call DarFor.txt");
}
}
else if(n=='5'){
system("cls");
MAXP=0;
cout<<"OKAY,Press any key to contiune.\n";
getch();
}
else break;
}
return;
}
void getskin(void){
int a,b;
freopen("Skin.txt","r",stdin);
cin>>a>>b;
fclose(stdin);
man.looks=a;
other1.looks=b;
return;
}
void getMAXP(void){
freopen("coin.txt","r",stdin);
cin>>MAXP;
fclose(stdin);
return;
}
void SetMAXP(void){
freopen("coin.txt","w",stdout);
cout<<MAXP<<endl;
fclose(stdout);
return;
}
int main(){
SetBEGIN;
getskin();
getMAXP();
srand((unsigned)time(NULL));
init_skin_bag();
char n;
while(1){
init();
n=getch();
if(n=='1') start();
else if(n=='3') help();
else if(n=='4') {
easterEgg=1;
start();
easterEgg=0;
}
else if(n=='2')break;
}
SetNewSkin();
SetMAXP();
return 0;
}