跳到正文

休闲·娱乐

c++跑酷小游戏

WuMin4约 60 分钟
原文
文章信息与版本

文章信息

发布
2023年1月16日
收录
2025年12月12日
更新
2026年11月18日
篇幅
约 60 分钟
获赞
1

版本

  1. v1当前

史 山 警 告\color{red}{\bold{史 \ 山 \ 警 \ 告}}

C++
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
#include<cwchar>
using namespace std;
struct teleportEvent{
	int ID,pos1[2],pos2[2];
};
const int mapCnt=15,blockCnt=12;
int nPlayerPos[2]={1,11},bPlayerPos[2]={1,11},nowMap=0,playerSpawnPoint[2]={1,11},startPlayTime,playerDeathCnt,playerColor=15,playerTextSize=32,keys[6]={1,2,3,2,1,2};
double playerYv=0,playerJumpH=3;
bool playerWin=0,playerMoveDir=0,playerPressR=0,colorMode=0;
int bestTime[mapCnt];
char blocks[blockCnt]={' ','=','-','#','@','P','S','G','>','<','X','%'};
string mapsName[mapCnt]={"缓存地图(勿进)","简单的跳平台","简单的跳个刺","蹦床乐园","顶级折磨"
	,"密室逃生","ZY","传送带跑酷","微操小考验","额我也不知道这关叫什么"
	,"冰雪世界","折磨你祖宗十八代","信仰之跃","炒鸡EX","传送之美"};
string maps[mapCnt][12]={
	{
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",//1
	},
	{
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                  P ",
		"                                               ==== ",
		"                                        <<=>>       ",
		"                                 <<=>>              ",
		"                          >>>>>                     ",
		"                   >>>>>                            ",
		"            >>>>>                                   ",
		"G    >>>>>                                          ",
		"====================================================",//2
	},
	{
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"====================================================",
		"      #     #     #     #     #     =               ",
		"                                    =               ",
		"G  #     #     #     #     #     # P=               ",
		"====================================================",//3
	},
	{
		"                          P                         ",
		"     @                                 @            ",
		"                  @    @             @              ",
		"         @                    @        @            ",
		"               @     @             @    @    @      ",
		"                            @                       ",
		"    @     @            @              @             ",
		"                                 @         @     @  ",
		"                @           @                       ",
		"      @                           @    @      @     ",
		"G                                                 @ ",
		"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",//4
	},
	{
		"                                                    ",
		"                                                    ",
		"                                                    ",
		" =                                                  ",
		" =                                                  ",
		" =                                                  ",
		" ---------------------------------------------------",
		"                                                    ",
		"                                                    ",
		"                                                    ",
		"G                                                P  ",
		"=======@=@==@@==@@==@=@==@@@==@@@==@=@=@@==@==@=====",//5
	},
	{
		"                         ====#==#==#==#==###########",
		"          S              =                          ",
		"===#===##-=  -  =  -  =  =                S         ",
		"          =     =#####=  =--=@==@==@==@==@==   #    ",
		"          =     =======  =      #       #  =      # ",
		"-=@===@==@=     =        =         #       = #      ",
		" #        =     = =====@@=@@#         #    =    #   ",
		"          =     =      ##=================-=    #   ",
		"=======#=-=     =        =                -=  #     ",
		"          =#####=======  =                -=     #  ",
		"G         =#####=ZYNB!=  S  #  #  #  #  # -=#    P  ",
		"=======================@@===========================",//6
	},
	{
		"                #                                   ",
		"               -      #       P                     ",
		"G             -   S # #     ======                  ",
		"-=  ==========    = #       =                       ",
		"-=           #     -     # @                        ",
		"-=      - -=        #     #                         ",
		"-=        #          = #    -                       ",
		"-=       #   #-- @    = -  #                        ",
		"-=   #  #              =   =                        ",
		"-=  -#@#    #          =               #############",
		"-=  -##                =               #有点丑请见谅",
		"==#######====@#########=##@=@#######################",//7
	},
	{
		"                                                    ",
		"                                                    ",
		"G                                                   ",
		"-=>>>>>  <<<<<  >>><<  <<<>>  ===  >>== <<== >< =  =",
		"-=################################################ =",
		"-================================================= =",
		"-=                                           S     =",
		"-=                                          ==     =",
		"-=  #       #    <<<<<<======>      <      ====    =",
		"-= <<<<<<<<<<<<<<             >    <  <<>>>     @@@=",
		"-=P#############################<>#################=",
		"====================================================",//8
	},
	{
		"                                 =                  ",
		"                          ====-  =     ===-         ",
		"                          =      =     =            ",
		"  =  ==  ==  ===   ===    =      =     =            ",
		"  =                       =      =     =            ",
		"  =                       ====         ===          ",
		"P =         ============================           S",
		"============                     ==================-",
		"     #      S         S          S ================-",
		"      #     = = = = === < < < > >=                 -",
		"G  #     ##@= XXXXXXX== XXXXXXXXX= =   =   =   =   -",
		"==================================#==#===#===#===@==",//9
	},
	{
		"                                          S    =    ",
		"                                          ==== =    ",
		"                                  #  #====     =    ",
		"                              #  #====              ",
		"                          #  #====                  ",
		"                      #  #====                      ",
		"                  #  #====            <><           ",
		"              #  #====            <<>>              ",
		"          #  #====       <<>> ><<                   ",
		"      #  #====                                      ",
		"   G  ====             P                            ",
		"======#####################################@########",//10
	},
	{
		" P                                      P           ",
		" -                                                  ",
		"          ----                                      ",
		"    #%%@          #%%@             #%%@             ",
		"                                                    ",
		"                                #%%%%%%%%%@         ",
		" #%%%@    %%%@                                      ",
		"                           %%%@    %%%<             ",
		"                  @%%%                              ",
		"         %%%                                     %%%",
		"G                                                   ",
		"===%%%%%%%%%%%%%%%%%%%%%@@%%%%%%%%%%%%%%%%%%%%%%%===",//11
	},
	{
		"                       =         P    ########     #",
		"############           =#########=-   ########     -",
		"-         #  =%%%      =         #                 -",
		"-         #      %%%># #         #%%%<%<%%%%%%%###= ",
		"-     #   #        #   =          # S  ###    ####  ",
		"-     #   =@%%%%   #   #     %%%% # =  #       ###  ",
		"-=#<<<=   =#####   #   #<-  ### # # #  #       ### -",
		"-=        ###  #   #   #      #     ## #   ##       ",
		"-= %%%%%%%=#   #  <           #      # #--###     S ",
		"-= =#######       #           #      # #  ###    == ",
		"G=         S #   #S           #      #      #      #",
		"==@%%%%%%%%=========%%%#<>#@@%#=%%#@##=%>>%##=%%%%%%",//12
	},
	{
		"                                                    ",
		"                                                    ",
		"                 S                                  ",
		"               =#=                                  ",
		"                                                    ",
		"           =#=                                      ",
		"                        =#=#=                       ",
		"       =#%                                          ",
		"                                  S                 ",
		"   =#%                            =#=#=             ",
		"                                                 P  ",
		"===###@###@###@###@###@###@###@###@###@###@###@#<=>#",//13
	},
	{
		"                                                    ",
		"                                                   P",
		"      =   @     @     @     @     @     @    =   = =",
		"                                                    ",
		"                                                    ",
		" = @  =   @     @     @     @     @     @    @    @ ",
		"                                                    ",
		"                                                    ",
		"      =   @     @     @     @     @     @     = @ = ",
		"                                                    ",
		"                                                    ",
		"====@###############################################",//14
	},
	{
		"==========#                           = |   #       ",
		"          #          ==================-=%% #       ",
		" ======== ###########                 # | # #       ",
		"      |   #         # %%%%%%%%%%%%%%%-# #-# #       ",
		"==========# ======= # |               #@# # ########",
		"########### ####### #==================== #  P#     ",
		"          #     | # ##################### #===#-%%% ",
		"          #=====# # #   #|                #   #-### ",
		"          #     # # #   #%%%%%%%%%%%%%%%%@#   # ### ",
		"          =     | # # = ################### = # ### ",
		"G         |    =#=# | #                  |# | #   | ",
		"=======================%%%%%%%%%%%%%%%%%%%======%%%<",//15
	},
};
vector<teleportEvent> tp[mapCnt];
void initTpEvent(){
	tp[14].push_back({1,{10,10},{44,10}});//x,y
	tp[14].push_back({2,{16,9},{16,6}});
	tp[14].push_back({3,{20,10},{6,3}});
	tp[14].push_back({4,{41,10},{25,7}});
	tp[14].push_back({5,{40,2},{50,10}});
	tp[14].push_back({6,{40,0},{22,4}});
}
void setTextSize(int x,int y){
	CONSOLE_FONT_INFOEX cfi;
	cfi.cbSize=sizeof(cfi);
	cfi.nFont=0;
	cfi.dwFontSize.X=x;
	cfi.dwFontSize.Y=y;
	cfi.FontFamily = FF_DONTCARE;
	cfi.FontWeight = FW_NORMAL;
	SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE),FALSE,&cfi);
}
void closeQuickEditMode(){
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);DWORD mode;
	GetConsoleMode(hStdin,&mode);mode&=~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hStdin,mode);
}
void openQuickEditMode(){
	HANDLE hStdin=GetStdHandle(STD_INPUT_HANDLE);DWORD mode;
	GetConsoleMode(hStdin,&mode);mode|=~ENABLE_QUICK_EDIT_MODE;
	SetConsoleMode(hStdin,mode);
}
void dis_mouse(){
	ShowCursor(false);HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
	CONSOLE_CURSOR_INFO cci;GetConsoleCursorInfo(hOut,&cci);
	cci.bVisible=false;SetConsoleCursorInfo(hOut,&cci);
}
void killCloseButton(){
	DeleteMenu(GetSystemMenu(GetConsoleWindow(),FALSE),SC_CLOSE,MF_DISABLED);
	DrawMenuBar(GetConsoleWindow());
}
bool gks(char s){return GetKeyState(s)<0;}
void ZYMode(){
	HWND hwnd;hwnd=GetConsoleWindow();
	ShowWindow(hwnd,SW_HIDE);
	while(gks('Z'));while(!gks('Z'));
	ShowWindow(hwnd,SW_SHOW);char choose=getch();
}
void color(int a){SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);}
string ys(string st){
	int cnt=1,l=-1;string s;
	for(int i=0;i<st.length();i++){
		if(st[i]==st[i+1]&&i!=st.length()-1) cnt++;
		else if(cnt==1) s+=st[i];
		else{
			s+=st[i];
			s+=to_string(cnt);
			cnt=1;
		}
	}
	for(int i=0;i<s.length();i++) s[i]^=keys[i%6];
	return s;
}
string js(string st){
	for(int i=0;i<st.length();i++) st[i]^=keys[i%6];
	int l=-1;char s[10000];
	for(int i=0;i<st.length();i++){
		if(isdigit(st[i+1])){
			int sum=0;char ss=st[i];
			while(isdigit(st[i+1])) sum=sum*10+(st[i+1]-'0')%10,i++;
			for(int j=1;j<=sum;j++) s[++l]=ss;
		}
		else s[++l]=st[i];
	}
	s[++l]='\0';
	return s;
}
void gt(int y,int x){COORD pos;pos.X=y-1;pos.Y=x-1;SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),pos);}
void outBlock(char block){
	if(!colorMode){
		if(block=='%'){color(9);cout<<'=';}
		else{color(15);cout<<block;}
	}
	else{
		if(block=='='){color(255);cout<<' ';}
		else if(block=='#'){color(71);cout<<' ';}
		else if(block=='@'){color(102);cout<<' ';}
		else if(block=='<'){color(223);cout<<'<';}
		else if(block=='>'){color(223);cout<<'>';}
		else if(block=='-'){color(15);cout<<'-';}
		else if(block=='%'){color(17);cout<<' ';}
		else if(block=='P'){color(46);cout<<'P';}
		else if(block=='S'){color(111);cout<<'S';}
		else{color(15);cout<<block;}
	}color(15);
}
void printPlayer(){
	gt(bPlayerPos[0],bPlayerPos[1]);
	char block=maps[nowMap][bPlayerPos[1]-1][bPlayerPos[0]-1];outBlock(block);
	gt(nPlayerPos[0],nPlayerPos[1]);color(playerColor);cout<<'$';
	color(15);
}
void loadMap(int Map){
	for(int i=0;i<12;i++){
		for(int j=0;j<52;j++){
			char block=maps[Map][i][j];
			if(block=='|'){
				for(int k=0;k<tp[Map].size();k++){
					teleportEvent now=tp[Map][k];
					if((now.pos1[0]==j&&now.pos1[1]==i)||(now.pos2[0]==j&&now.pos2[1]==i)){
						color((now.ID-1)%15+1);
						break;
					}
				}
				cout<<'|';
			}
			else outBlock(block);
		}
		cout<<endl;
	}
}
void GetPos(POINT &pt)
{
	HWND hwnd=GetForegroundWindow();GetCursorPos(&pt);ScreenToClient(hwnd,&pt);
	pt.y=pt.y/playerTextSize;
	pt.x=pt.x*2/playerTextSize;
}
void SAL(bool type){
	if(type==0)//save
	{
		FILE *fp;
		fp=fopen("data.sav","w");
		fprintf(fp,"%d\n",playerColor);
		fprintf(fp,"%d\n",playerTextSize);
		for(int i=0;i<mapCnt;i++){
			fprintf(fp,"%d ",bestTime[i]);
		}
		fprintf(fp,"-1\n");
		fprintf(fp,"%d\n",colorMode);
		cout<<"存档成功!"<<endl;
		system("pause");
		fclose(fp);
	}
	else{
		FILE *fp;
		fp=fopen("data.sav","r");
		if(fp==NULL){
			cout<<"未读取到存档文件"<<endl;
			system("pause");
			return;
		}
		fscanf(fp,"%d",&playerColor);
		fscanf(fp,"%d",&playerTextSize);
		setTextSize(0,playerTextSize);
		for(int x,i=0;i<=100000;i++){
			fscanf(fp,"%d",&x);
			if(x==-1) break;
			if(i<=mapCnt)
				bestTime[i]=x;
		}
		fscanf(fp,"%d",&colorMode);
		fclose(fp);
		cout<<"读档成功!"<<endl;
		system("pause");
	}
}
char getBlock(int x,int y,bool down){
	if(down){
		int i;
		for(i=y;i<53;i++){
			if(maps[nowMap][i][x]!=' '&&maps[nowMap][i][x]!='S'&&maps[nowMap][i][x]!='X'&&maps[nowMap][i][x]!='G'){
				break;
			}
		}
		if(i==53) return ' ';
		else return maps[nowMap][i][x];
	}
	else{
		int i;
		for(i=y;i>=0;i--){
			if(maps[nowMap][i][x]!=' '&&maps[nowMap][i][x]!='S'&&maps[nowMap][i][x]!='X'&&maps[nowMap][i][x]!='G'){
				break;
			}
		}
		if(i==-1) return ' ';
		else return maps[nowMap][i][x];
	}
}
int blockDis(int x,int y,bool down){
	if(down){
		int i;
		for(i=y;i<53;i++){
			if(maps[nowMap][i][x]=='='||maps[nowMap][i][x]=='#'
				||maps[nowMap][i][x]=='-'||maps[nowMap][i][x]=='@'
				||maps[nowMap][i][x]=='P'||maps[nowMap][i][x]=='>'
				||maps[nowMap][i][x]=='<'||maps[nowMap][i][x]=='%'){
				break;
			}
		}
		if(i==53) return -1;
		else return i;
	}
	else{
		int i;
		for(i=y;i>=0;i--){
			if(maps[nowMap][i][x]=='='||maps[nowMap][i][x]=='#'
				||maps[nowMap][i][x]=='@'||maps[nowMap][i][x]=='P'
				||maps[nowMap][i][x]=='>'||maps[nowMap][i][x]=='<'
				||maps[nowMap][i][x]=='%'){
				break;
			}
		}
		if(i==-1) return -1;
		else return i;
	}
}
void playerMove(){
	int x,y;
	bool playerDead=0;
	bPlayerPos[0]=nPlayerPos[0],bPlayerPos[1]=nPlayerPos[1];
	x=nPlayerPos[0]-1,y=nPlayerPos[1]-1;
	if(gks('W')
		&&blockDis(x,y,1)==y+1&&(getBlock(x,y,1)=='='||getBlock(x,y,1)=='-'||getBlock(x,y,1)=='<'||getBlock(x,y,1)=='>')
		&&maps[nowMap][y][x]!='X'&&maps[nowMap][y+1][x]!='%'
		&&playerYv==0){
		playerYv=playerJumpH;
	}
	if(playerYv>0){
		playerYv--;
		bPlayerPos[1]=nPlayerPos[1];
		if(y-playerYv<=blockDis(x,y,0)){
			char block=getBlock(x,y,0);
			if(block=='='||block=='@'||block=='>'||block=='<'||block=='%') nPlayerPos[1]=blockDis(x,y,0)+2,playerYv=0;
			else if(block=='#') playerDead=1;
			else if(block=='P') playerWin=1;
		}
		else nPlayerPos[1]-=playerYv;
	}
	else{
		if(y!=blockDis(x,y,1)||y!=blockDis(x,y,1)+1){
			playerYv--;
			bPlayerPos[1]=nPlayerPos[1];
			if(y-playerYv>=blockDis(x,y,1)){
				char block=getBlock(x,y,1);
				if(block=='='||block=='-'||block=='>'||block=='<'||block=='%') nPlayerPos[1]=blockDis(x,y,1),playerYv=0;
				else if(block=='#') playerDead=1;
				else if(block=='@') nPlayerPos[1]=blockDis(x,y,1),playerYv=4;
				else if(block=='P') playerWin=1;
			}
			else nPlayerPos[1]-=playerYv;
		}
	}
	if(nPlayerPos[1]<=0) nPlayerPos[1]=1;
	if(nPlayerPos[1]>=13) nPlayerPos[1]=12;
	x=nPlayerPos[0]-1,y=nPlayerPos[1]-1;
	bPlayerPos[0]=nPlayerPos[0];
	if((gks('A')||maps[nowMap][y+1][x]=='<'||(playerMoveDir==0&&maps[nowMap][y+1][x]=='%'))
		&&maps[nowMap][y][x-1]!='='&&maps[nowMap][y][x-1]!='<'&&maps[nowMap][y][x-1]!='>'&&maps[nowMap][y][x-1]!='%'
		&&!(playerMoveDir==1&&maps[nowMap][y+1][x]=='%')){
		playerMoveDir=0;
		nPlayerPos[0]-=1;
	}
	if((gks('D')||maps[nowMap][y+1][x]=='>'||(playerMoveDir==1&&maps[nowMap][y+1][x]=='%'))
		&&maps[nowMap][y][x+1]!='='&&maps[nowMap][y][x+1]!='<'&&maps[nowMap][y][x+1]!='>'&&maps[nowMap][y][x+1]!='%'
		&&!(playerMoveDir==0&&maps[nowMap][y+1][x]=='%')){
		playerMoveDir=1;
		nPlayerPos[0]+=1;
	}
	if(nPlayerPos[0]<=0) nPlayerPos[0]=1;
	if(nPlayerPos[0]>=53) nPlayerPos[0]=52;
	x=nPlayerPos[0]-1,y=nPlayerPos[1]-1;
	if(maps[nowMap][y][x]=='#') playerDead=1;
	if(gks('R')){
		if(!playerPressR){
			playerDead=1;
			playerPressR=1;
		}
	}
	else playerPressR=0;
	if(playerDead==1){
		playerDeathCnt++;
		nPlayerPos[0]=playerSpawnPoint[0];
		nPlayerPos[1]=playerSpawnPoint[1];
	}
	if(maps[nowMap][y][x]=='P') playerWin=1;
	if(maps[nowMap][y][x]=='S') playerSpawnPoint[0]=nPlayerPos[0],playerSpawnPoint[1]=nPlayerPos[1];

	if(maps[nowMap][y][x]=='|'){
		for(int i=0;i<tp[nowMap].size();i++){
			teleportEvent now=tp[nowMap][i];
			if(now.pos1[0]==x&&now.pos1[1]==y){
				if(playerMoveDir==1) nPlayerPos[0]=now.pos2[0]+2,nPlayerPos[1]=now.pos2[1]+1;
				else nPlayerPos[0]=now.pos2[0],nPlayerPos[1]=now.pos2[1]+1;

			}
			if(now.pos2[0]==x&&now.pos2[1]==y){
				if(playerMoveDir==1) nPlayerPos[0]=now.pos1[0]+2,nPlayerPos[1]=now.pos1[1]+1;
				else nPlayerPos[0]=now.pos1[0],nPlayerPos[1]=now.pos1[1]+1;
			}
		}
	}
}
void printData(){
	gt(1,13);
	cout<<"                                         ";
	gt(1,13);
	cout<<"当前耗时:"<<(clock()-startPlayTime)/1000<<"  当前死亡次数:"<<playerDeathCnt<<"  按q退出游玩";
}
int startLevel(int lvl){
	system("cls");
	nowMap=lvl;loadMap(lvl);
	playerWin=0,playerDeathCnt=0,playerSpawnPoint[0]=1,playerSpawnPoint[1]=11;
	for(int i=0;i<12;i++)
		for(int j=0;j<52;j++)
			if(maps[nowMap][i][j]=='G') playerSpawnPoint[1]=i+1,playerSpawnPoint[0]=j+1;
	nPlayerPos[0]=playerSpawnPoint[0],nPlayerPos[1]=playerSpawnPoint[1];
	startPlayTime=clock();
	for(;!playerWin;Sleep(80)){
		playerMove();
		printPlayer();
		printData();
		if(gks('Q')) return bestTime[lvl];
		if(gks('Z')) ZYMode();
	}
	return (clock()-startPlayTime)/1000.0;
}
void createLevel(){
	system("cls");
	string createMap[12];
	for(int i=0;i<12;i++) createMap[i]="                                                    ";
	nPlayerPos[0]=1,nPlayerPos[1]=1;
	gt(1,13);cout<<"=/";
	gt(3,13);for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
	cout<<"/ 帮助请按H";char block='=';
	for(;1;Sleep(1)){
		bPlayerPos[0]=nPlayerPos[0],bPlayerPos[1]=nPlayerPos[1];
		POINT pt;GetPos(pt);
		if(pt.x>=0&&pt.y>=0&&pt.x<52&&pt.y<13)
			if(pt.y>11){
			if(pt.x>1&&pt.x<=blockCnt)
				if(gks(1)){
					block=blocks[(int)(pt.x-1)];
					gt(1,13);
					outBlock(block);
				}
			}
		else{
			nPlayerPos[0]=pt.x+1,nPlayerPos[1]=pt.y+1;
			gt(bPlayerPos[0],bPlayerPos[1]);
			outBlock(createMap[bPlayerPos[1]-1][bPlayerPos[0]-1]);
			gt(nPlayerPos[0],nPlayerPos[1]);
			color(240);
			if(gks(1)){
				closeQuickEditMode();
				createMap[nPlayerPos[1]-1][nPlayerPos[0]-1]=block;
			}
			else if(gks(2)){
				openQuickEditMode();
				createMap[nPlayerPos[1]-1][nPlayerPos[0]-1]=' ';
			}
			cout<<createMap[nPlayerPos[1]-1][nPlayerPos[0]-1];
			color(15);
		}
		if(gks('Q')) break;
		if(gks('E')){
			for(int i=0;i<12;i++) maps[0][i]=createMap[i];
			startLevel(0);
			while(gks('Q')) Sleep(50);
			system("cls");
			loadMap(0);
			nPlayerPos[0]=1,nPlayerPos[1]=1;
			gt(1,13);
			cout<<"=/";
			gt(3,13);
			for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
			cout<<"/ 帮助请按H";
		}
		if(gks('H')){
			system("cls");
			cout<<"创作方式:用鼠标在最下面选择方块,用左键放置,右键删除"<<endl;
			cout<<"快捷键:"<<endl;
			cout<<"Q:退出编辑"<<endl;
			cout<<"E:测试关卡"<<endl;
			cout<<"H:打开帮助"<<endl;
			cout<<"S:保存关卡"<<endl;
			cout<<"L:加载关卡"<<endl;
			system("pause");
			system("cls");
			for(int i=0;i<12;i++){
				maps[0][i]=createMap[i];
			}
			loadMap(0);
			nPlayerPos[0]=1,nPlayerPos[1]=1;
			gt(1,13);cout<<"=/";
			gt(3,13);
			for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
			cout<<"/ 帮助请按H";
		}
		if(gks('S')){
			char choose;
			choose=' ';
			while(choose<'0'||choose>'3'){
				system("cls");
				cout<<"请选择保存方式:"<<endl;
				cout<<"1.文件(不方便传输,只能存一个,但很方便导入)"<<endl;
				cout<<"2.地图码(方便传输,可以存很多,但需要粘贴地图码导入)"<<endl;
				cout<<"3:退出"<<endl;
				choose=getch();
			}
			if(choose=='1'){
				FILE *fpp;
				fpp=fopen("createMap","w");
				for(int i=0;i<12;i++){
					for(int j=0;j<52;j++){
						fprintf(fpp,"%d ",(int)(createMap[i][j]));
					}
				}
				fclose(fpp);
				system("cls");
				for(int i=0;i<12;i++){
					maps[0][i]=createMap[i];
				}
				gt(1,1);
				loadMap(0);
				nPlayerPos[0]=1,nPlayerPos[1]=1;
				gt(1,13);cout<<"=/";
				gt(3,13);
				for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
				cout<<"/ 帮助请按H";
				gt(25,13);
				cout<<" 保存成功!";
				Sleep(1000);
				gt(25,13);
				cout<<"          ";
			}
			else if(choose=='2'){
				ofstream code("Mapcode.txt");
				code<<"地图码(请妥善保管地图码,勿漏掉,修改一个字符,否则可能会引发崩溃):"<<endl;
				string all="";
				for(int i=0;i<12;i++){
					all+=createMap[i];
				}
				code<<ys(all);
				code.close();
				system("start Mapcode.txt");
				system("pause");
				system("cls");
				for(int i=0;i<12;i++){
					maps[0][i]=createMap[i];
				}
				gt(1,1);
				loadMap(0);
				nPlayerPos[0]=1,nPlayerPos[1]=1;
				gt(1,13);cout<<"=/";
				gt(3,13);
				for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
				cout<<"/ 帮助请按H";
				gt(25,13);
				cout<<" 保存成功!";
				Sleep(1000);
				gt(25,13);
				cout<<"          ";
			}
			else if(choose=='3'){
				system("cls");
				for(int i=0;i<12;i++){
					maps[0][i]=createMap[i];
				}
				gt(1,1);
				loadMap(0);
				nPlayerPos[0]=1,nPlayerPos[1]=1;
				gt(1,13);cout<<"=/";
				gt(3,13);
				for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
				cout<<"/ 帮助请按H";
			}
		}
		if(gks('L')){
			char choose;
			choose=' ';
			while(choose<'0'||choose>'3'){
				system("cls");
				cout<<"请选择导入方式:"<<endl;
				cout<<"1.文件 2.地图码 3.退出"<<endl;
				choose=getch();
			}
			if(choose=='1'){
				FILE *fpp;
				fpp=fopen("createMap","r");
				if(fpp==NULL){
					gt(26,13);
					cout<<"未读取到文件";
					Sleep(1000);
					gt(26,13);
					cout<<"            ";
				}
				else{
					for(int i=0;i<12;i++){
						for(int j=0;j<52;j++){
							int s;
							fscanf(fpp,"%d ",&s);
							createMap[i][j]=char(s);
						}
					}
					fclose(fpp);
					system("cls");
					for(int i=0;i<12;i++){
						maps[0][i]=createMap[i];
					}
					gt(1,1);
					loadMap(0);
					nPlayerPos[0]=1,nPlayerPos[1]=1;
					gt(1,13);
					cout<<"=/";
					gt(3,13);
					for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
					cout<<"/ 帮助请按H";
					gt(25,13);
					cout<<" 加载成功!";
					Sleep(1000);
					gt(25,13);
					cout<<"          ";
				}
			}
			else if(choose=='2'){
				system("cls");
				cout<<"请输入地图码(用右键粘贴):"<<endl;
				string c;
				getline(cin,c);
				c=js(c);
				if(c.length()!=12*52){
					cout<<"地图码错误,请检查地图码"<<endl;
					system("pause");
				}
				else{
					int l=-1;
					for(int i=0;i<12;i++){
						for(int j=0;j<52;j++){
							createMap[i][j]=c[++l];
						}
					}
				}
				system("cls");
				for(int i=0;i<12;i++){
					maps[0][i]=createMap[i];
				}
				gt(1,1);
				loadMap(0);
				nPlayerPos[0]=1,nPlayerPos[1]=1;
				gt(1,13);
				cout<<"=/";
				gt(3,13);
				for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
				cout<<"/ 帮助请按H";
				gt(25,13);
				cout<<" 加载成功!";
				Sleep(1000);
				gt(25,13);
				cout<<"          ";
			}
			else if(choose=='3'){
				system("cls");
				for(int i=0;i<12;i++){
					maps[0][i]=createMap[i];
				}
				gt(1,1);
				loadMap(0);
				nPlayerPos[0]=1,nPlayerPos[1]=1;
				gt(1,13);
				cout<<"=/";
				gt(3,13);
				for(int i=1;i<blockCnt;i++) outBlock(blocks[i]);
				cout<<"/ 帮助请按H";
			}
		}
	}
	closeQuickEditMode();
	system("cls");
}
void init(){
	setTextSize(0,32);
	closeQuickEditMode();
	dis_mouse();
	initTpEvent();
	system("mode con cols=53 lines=13");
}
void Home(){
	system("cls");
	cout<<
	"                                                    "<<endl<<
	"              非常普通的C++ 跑酷小游戏              "<<endl<<
	"              请使用键盘数字来选择选项              "<<endl<<
	"                      1.游玩                        "<<endl<<
	"                      2.创作                        "<<endl<<
	"                      3.帮助                        "<<endl<<
	"                      4.退出                        "<<endl<<
	"                      5.自定义(摸鱼时一定要用)      "<<endl<<
	"                      6.存读档                      "<<endl<<
	"按Z隐藏程序(请短按,再按一下取消)                    "<<endl<<
	"                                           V1.5     "<<endl<<
	"                                                    "<<endl;
	char choose=getch();
	if(choose=='1'){
		system("cls");
		int page=0;
		while(1){
			system("cls");
			cout<<"请选择游玩关卡:"<<endl;
			for(int i=page*9+1;i<=min(mapCnt,page*9+9);i++){
				cout<<(i-1)%9+1<<":"<<mapsName[i-1];
				if(bestTime[i-1]==0) cout<<" 未游玩";
				else cout<<" 最佳时间:"<<bestTime[i-1]<<'s';
				cout<<endl;
			}
			cout<<"第"<<page+1<<"页,共"<<(mapCnt-1)/9+1<<"页(请按ad切换,q返回)";
			char choose=getch();
			if('1'<=choose&&choose<='9'){
				int lvl=(choose-'0')+9*page-1;
				if(lvl>=mapCnt) continue;
				int lvlTime=startLevel(lvl);
				if(bestTime[lvl]==0) bestTime[lvl]=lvlTime;
				else bestTime[lvl]=min(bestTime[lvl],lvlTime);
				system("cls");
				if(bestTime[lvl]!=0) cout<<"你赢了!耗时"<<lvlTime<<"秒"<<endl;
				system("pause");
				break;
			}
			else if(choose=='q') break;
			else if(choose=='a') page--;
			else if(choose=='d') page++;
			if(page<0) page=(mapCnt-1)/9;
			if(page>(mapCnt-1)/9) page=0;
		}
	}
	else if(choose=='2'){
		system("cls");
		createLevel();
		system("pause");
	}
	else if(choose=='3'){
		system("cls");
		cout<<"啊这这还需要帮助吗"<<endl;
		cout<<"那还是告诉你吧"<<endl;
		cout<<"=  平台,没啥特殊的"<<endl;
		cout<<"#  刺,碰到死,没啥好说的"<<endl;
		cout<<"-  单向板,可以从下面跳上去"<<endl;
		cout<<"@  弹簧,还是没啥讲的"<<endl;
		cout<<"<>  传送带,踩上去会按照固定方向移动"<<endl;
		cout<<"=(蓝色) 冰,踩上去会按照踩上去时的方向移动,且中途不可跳跃、更改方向"<<endl;
		cout<<"P  终点,上去就通关了"<<endl;
		cout<<"S  存档点,可以存档"<<endl;
		cout<<"C  出生点,可以出生"<<endl;
		cout<<"没了..."<<endl;
		system("pause");
	}
	else if(choose=='4') exit(0);
	else if(choose=='5'){
		system("cls");
		cout<<"请选择自定义选项:"<<endl;
		cout<<"1:设置窗口大小"<<endl;
		cout<<"2:设置玩家颜色"<<endl;
		cout<<"3:开关地图真彩模式(测试版)"<<endl;
		char choose=getch();
		if(choose=='1'){
			system("cls");
			int x;
			cout<<"请输入(1-5):";
			cin>>x;
			playerTextSize=pow(2,x);
			setTextSize(0,playerTextSize);
			cout<<"\n设置成功!"<<endl;
			system("pause");
		}
		if(choose=='2'){
			system("cls");
			cout<<"色卡:";
			for(int i=0;i<=15;i++){
				cout<<setw(2)<<i;
			}
			cout<<endl;
			cout<<"     ";
			for(int i=0;i<=15;i++){
				color(i*16+i);
				cout<<"  ";
			}
			cout<<endl;
			color(15);
			int x;
			cout<<"请输入玩家背景色(0-15):";
			cin>>x;
			playerColor=x*16;
			cout<<"\n请输入玩家字符色(0-15):";
			cin>>x;
			playerColor+=x;
			cout<<"\n设置成功!"<<endl;
			system("pause");
		}
		if(choose=='3'){
			system("cls");
			cout<<"请选择:"<<endl;
			cout<<"1.开启 2:关闭"<<endl;
			choose=getch();
			if(choose=='1') colorMode=1;
			else if(choose=='2') colorMode=0;
			else return;
			cout<<"设置成功!"<<endl;
			system("pause");
		}
	}
	else if(choose=='6'){
		system("cls");
		cout<<"请选择模式:"<<endl;
		cout<<"1:存档 2:读档"<<endl;
		char choose=getch();
		if(choose=='1') SAL(0);
		else if(choose=='2') SAL(1);
	}
	else if(choose=='z') ZYMode();
}
int main(){
	init();
	while(1){
		Home();
	}
}
原文
存档评论1 条抓取于