操作说明:
这是一款迷宫小游戏。
请选择使用电脑打开。
按“上”、“下”、“左”、“右”键
或者“w”、“s”、“a”、“d”(大小写均可,但是要在英文状态下)
控制“*”在迷宫中移动,走出迷宫即可获得儿童节祝福。
“#”表示墙,空格表示路。
游戏总共三个BGM,分别是1——ninelie。2——Dream。3——光辉岁月。
你可以自己选择BGM。
游戏总共三个难度,分别是简单,普通,困难。
你可以自己选择游戏难度。
简单模式和普通模式都是20*20的地图,起点“*”在左上角。
困难模式是43*43的地图,起点在右上角(大概第九行最右的位置)怕你们看花了找不到起点。
一个模式结束之后,可以等待一两秒,返回到主界面,继续选择新的BGM和新的模式,不会退出。
如果想要退出,可以在选择BGM或者选择模式的时候输入0,即可退出游戏。
更新日志:
此版本为2.0版本。
增加了不止一个BGM,暂时只支持1-3,共三个BGM。
你也可以自己添加喜欢的音乐作为BGM,但是注意只支持wav格式,且命名要命名为1或2或3。
增加了不止一个地图,暂时只有简单、普通、困难三种模式,共三张地图。
增加了一张地图走完,不退出程序的功能。
建议:移动的时候移慢一点,多听点BGM_(:з」∠)_
一点吐槽:每移动一次,屏幕都会闪一下,特别是困难模式,如果引起不适,请选择关闭游戏。
选择BGM功能:
printf("Please choose the BGM, you can choose 1,2,3 or 0--exit:"); //choose BGM
scanf("%d",&bgm);
switch(bgm){
case 1:PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 2:PlaySound("2.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 3:PlaySound("3.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 0:return;break;
default:break;
}
选择游戏难度功能:
printf("Please choose the level of the maze, you can choose 1--easy,2--ordinary,3--hard,0--exit,please input the number:");
scanf("%d",&level);
if(bgm != 0) printf("Please press Enter to enter the maze.\n"); //请按回车键进入游戏界面
getch(); //don't show in the screen,不回显
system("cls"); //清屏
switch(level){
case 1:draw1(maze1);move1(maze1);break;
case 2:draw1(maze2);move1(maze2);break;
case 3:draw3(maze3);move3(maze3);break;
case 0:return;break;
default:break;
}
将游戏主界面写在了menu子函数里,这样就可以实现迷宫走完回到主界面,继续游戏,而不是退出。
//menu
void menu(){
int bgm,level;
system("color 0D"); //color
//system("pause");
//PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
//mciSendString("open D:\\Code\\1.wav",NULL,0,NULL);
printf("\n\t\t\t");
for(int i = 0;i < 20;i ++){
printf("-"); //输出界面上界
}
printf("\n");
printf("The * is the symbol of you.\n"); //*表示你所处的位置
printf("You can press (up,down,left,right) to move the (*).\n"); //你可以按上、下、左右键控制移动
printf("If your keyboard doesn't have these buttons,you can also press (w,s,a,d) to move the (*).\n"); //也可以按w/s/a/d控制移动
printf("Please choose the BGM, you can choose 1,2,3 or 0--exit:"); //choose BGM
scanf("%d",&bgm);
switch(bgm){
case 1:PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 2:PlaySound("2.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 3:PlaySound("3.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 0:return;break;
default:break;
}
printf("Please choose the level of the maze, you can choose 1--easy,2--ordinary,3--hard,0--exit,please input the number:");
scanf("%d",&level);
if(bgm != 0) printf("Please press Enter to enter the maze.\n"); //请按回车键进入游戏界面
getch(); //don't show in the screen,不回显
system("cls"); //清屏
switch(level){
case 1:draw1(maze1);move1(maze1);break;
case 2:draw1(maze2);move1(maze2);break;
case 3:draw3(maze3);move3(maze3);break;
case 0:return;break;
default:break;
}
}
主程序:
#include<stdio.h>
#include<stdlib.h>
#include<conio.h> //get the ASCII of up, down, left and right
#include<windows.h>
#include<mmsystem.h>
#pragma comment(lib,"winmm.lib") //PlaySound()
#include<time.h>
#include<algorithm>
using namespace std;
void draw1(int maze[20][20]);
void draw3(int maze[43][43]);
void menu();
void move1(int maze[20][20]);
void move3(int maze[43][43]);
//easy
int maze1[20][20] = {{1,1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,0,0,1,0,0,0,1,0,0,1},
{1,0,1,1,1,1,1,1,1,0,1,0,1,0,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1},
{1,0,0,0,0,0,0,0,0,0,1,0,1,0,1,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,1},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}};
//画迷宫1
void draw1(int maze[20][20]){
int i,j;
for(i = 0;i < 20;i ++){
printf("\t\t\t"); //display int the center of the screen
for(j = 0;j < 20;j ++){
if(maze[i][j] == 4) printf("*"); //4---you
else if(maze[i][j] == 0) printf(" "); //0---road
else printf("#"); //1---wall
}
printf("\n");
}
}
//画迷宫3
void draw3(int maze[43][43]){
int i,j;
for(i = 0;i < 43;i ++){
printf("\t\t\t"); //display int the center of the screen
for(j = 0;j < 43;j ++){
if(maze[i][j] == 4) printf("*"); //4---you
else if(maze[i][j] == 0) printf(" "); //0---road
else printf("#"); //1---wall
}
printf("\n");
}
}
//menu
void menu(){
int bgm,level;
system("color 0D"); //color
//system("pause");
//PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);
//mciSendString("open D:\\Code\\1.wav",NULL,0,NULL);
printf("\n\t\t\t");
for(int i = 0;i < 20;i ++){
printf("-"); //输出界面上界
}
printf("\n");
printf("The * is the symbol of you.\n"); //*表示你所处的位置
printf("You can press (up,down,left,right) to move the (*).\n"); //你可以按上、下、左右键控制移动
printf("If your keyboard doesn't have these buttons,you can also press (w,s,a,d) to move the (*).\n"); //也可以按w/s/a/d控制移动
printf("Please choose the BGM, you can choose 1,2,3 or 0--exit:"); //choose BGM
scanf("%d",&bgm);
switch(bgm){
case 1:PlaySound("1.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 2:PlaySound("2.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 3:PlaySound("3.wav",NULL,SND_FILENAME|SND_ASYNC|SND_LOOP);break;
case 0:return;break;
default:break;
}
printf("Please choose the level of the maze, you can choose 1--easy,2--ordinary,3--hard,0--exit,please input the number:");
scanf("%d",&level);
if(bgm != 0) printf("Please press Enter to enter the maze.\n"); //请按回车键进入游戏界面
getch(); //don't show in the screen,不回显
system("cls"); //清屏
switch(level){
case 1:draw1(maze1);move1(maze1);break;
case 2:draw1(maze2);move1(maze2);break;
case 3:draw3(maze3);move3(maze3);break;
case 0:return;break;
default:break;
}
}
//移动1
void move1(int maze[20][20]){
int a = 1; //row
int b = 0; //col
char num;
do{
num = getch();
//only change four locations of *
switch(num){
case 72: //↑的ASCII
case 87: //大写W的ASCII
case 119: //小写w的ASCII
if(maze[a-1][b] != 1){ //up
swap(maze[a][b],maze[a-1][b]);
a --;
system("cls"); //clear the screen
draw1(maze);
break;
}
break;
case 80:
case 83:
case 115:
if(maze[a+1][b] != 1){ //down
swap(maze[a+1][b],maze[a][b]);
a ++;
system("cls");
draw1(maze);
break;
}
break;
case 75:
case 65:
case 97:
if(maze[a][b-1] != 1){ //left
swap(maze[a][b-1],maze[a][b]);
b --;
system("cls");
draw1(maze);
break;
}
break;
case 77:
case 68:
case 100:
if(maze[a][b+1] != 1){ //right
swap(maze[a][b+1],maze[a][b]);
b ++;
system("cls");
draw1(maze);
break;
}
break;
default:break;
}
if(maze[18][19] == 4){
printf("\n\t\t Happy Children's Day to you!\n\n\n");
Sleep(2000); //delay
//if(++n != 1) //printf("Please press Enter to return the maze.\n"); //请按回车键返回主界面
//Sleep(2000); //delay
break;
}
}while(1);
system("cls");
menu();
}
//移动3
void move3(int maze[43][43]){
int a = 9; //row
int b = 42; //col
char num;
do{
num = getch();
//only change four locations of *
switch(num){
case 72: //↑的ASCII
case 87: //大写W的ASCII
case 119: //小写w的ASCII
if(maze[a-1][b] != 1){ //up
swap(maze[a][b],maze[a-1][b]);
a --;
system("cls"); //clear the screen
draw3(maze);
break;
}
break;
case 80:
case 83:
case 115:
if(maze[a+1][b] != 1){ //down
swap(maze[a+1][b],maze[a][b]);
a ++;
system("cls");
draw3(maze);
break;
}
break;
case 75:
case 65:
case 97:
if(maze[a][b-1] != 1){ //left
swap(maze[a][b-1],maze[a][b]);
b --;
system("cls");
draw3(maze);
break;
}
break;
case 77:
case 68:
case 100:
if(maze[a][b+1] != 1){ //right
swap(maze[a][b+1],maze[a][b]);
b ++;
system("cls");
draw3(maze);
break;
}
break;
default:break;
}
if(maze[9][0] == 4){
printf("\n\t\t\t\tHappy Children's Day to you!\n\n\n");
Sleep(2000); //delay
//if(++n != 1) //printf("Please press Enter to return the maze.\n"); //请按回车键返回主界面
//Sleep(2000); //delay
break;
}
}while(1);
system("cls");
menu();
}
int main(){
menu();
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。