问题标题: 模仿超级玛丽的小游戏

0
0
已解决
王梓澳
王梓澳
中级光能
中级光能
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip> 
#include <windows.h>
#include <conio.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)//判断键盘是否按下函数定义 
using namespace std;
struct Game {
	int x,y,lx,ly;
}Player;
int MoveSleep;
int JumpSleep;
int JumpF;
int cnt;
void SetPos(COORD a) {
	HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j) {
	COORD pos={i, j};
	SetPos(pos);
}
void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
bool map[10][100]={
{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,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0},
{0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,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,0,1,1,1,1,1,0,0,0,0,0,1,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},
};
bool mon[10][100]={
{0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,1,1,1,1,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,1,1,1,1,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,0,0,0,0,0,0,0,0,1,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,0,0,0,0,0,0,0,0,0,1,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,0,1,0,0,0,0,1,1,1,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,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,0,0,0,0,0,0,0},
};
bool die[10][100]={
{1,1,1,1,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0},
{1,1,1,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,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,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,1,1,1,1,1,1,1,1},
{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,0,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,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,0,0,0,0,0,0,0,0,0,0,0,0,0},
};
void out(string a) {
	for (int i=0;i<a.size();i++) {
		cout<<a[i];
		Sleep(50);
	}
}
void story() {
	color(7);
	out("剧情篇\n");
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("一天你睡觉时,突然梦见你一人站在一个空无一人的地方...\n");
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("一个声音对你说:你的灵魂已破碎不堪\n你向四周看去,没有任何人\n");
	out("接着你醒来了,你去请求神灵,发现梦里的话是真实的...\n");
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("神灵问:你想要一个完整的灵魂吗?\n你毫不犹豫的回答道:想!\n");
	out("“我已将你的灵魂碎片散落在一个地方,你收集到所有碎片才能获得完整的灵魂,当然,这也会有危险,你愿意吗?”\n“我愿意!”");
	out("突然你被传送到一个二维世界的地图中...\n");
	cout<<"按下Z继续\n";
	while (!KEY_DOWN('Z'));
}
void in_con() {
	system("cls");
	out("游戏目标:控制0收集所有碎片(*),避开危险(X),到达重点(4)\n");
	out("操作须知:a(左)d(右)w(跳跃)(有二段跳,但是由于作者代码存在问题,很难触发)\n");
	cout<<"按下k继续";
	while (!KEY_DOWN('K'));
	system("cls");
	SetPos(0,0);
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"操作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
}
void update() {
	system("cls");
	color(14);cout<<"1.0~1.1 更新游戏界面和地图\n";color(7);
	color(13);cout<<"关于更新:\n1、作者会更新地图关卡\n2、危险方块移动\n3、小怪物\n4、重生\n5、中途退出保存并且下一次打开数据仍然在(需要创建文件夹和相关文件,作者在实验过程中)\n";color(7); 
	cout<<"按下k继续";
	while (!KEY_DOWN('K'));
	system("cls");
	SetPos(0,0);
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"操作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
}
void start() {
	system("cls");
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"操作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
	int i=1;
	while (true) {
		SetPos(2,5);cout<<" ";
		SetPos(2,6);cout<<" ";
		SetPos(2,7);cout<<" ";
		if (i==1) {
			if (KEY_DOWN('Z')) return ;
			SetPos(2,5);color(14);cout<<">";color(7);
		}SetPos(3,5); cout<<"开始游戏";
		if (i==2) {
			if (KEY_DOWN('Z')) in_con();
			SetPos(2,6);color(14);cout<<">";color(7);
			
		}SetPos(3,6); cout<<"查看介绍";
		if (i==3) {
			if (KEY_DOWN('Z')) update();
			SetPos(2,7);color(14);cout<<">";color(7);
		}SetPos(3,7); cout<<"更新内容";
		if (KEY_DOWN('W')&&i-1>=1) i--;
		if (KEY_DOWN('S')&&i+1<=3) i++;
		Sleep(100);
	}
}
void print() {
	SetPos(0,0);
	for (int i=0;i<6;i++) {
		for (int j=0;j<40;j++) {
			color(7);
			if (map[i][j]) cout<<"=";
			else if (mon[i][j]) {
				color(14);
				cout<<"*";
			}
			else if (die[i][j]) {
				color(64);
				cout<<"X";
			}
			else cout<<" ";
		}
		cout<<endl;
	}
}
void control() {//控制函数
	int x=Player.x,y=Player.y;
	if (KEY_DOWN('W')&&x-1>=0&&JumpF<2&&!map[x-1][y]) {
		JumpF++;
		x-=1;
	}
//	if (KEY_DOWN('S')&&x+1<=5&&!map[x+1][y]) x++;
	if (KEY_DOWN('A')&&y-1>=0&&!map[x][y-1]) y--;
	if (KEY_DOWN('D')&&y+1<44&&!map[x][y+1]) y++;
	if (map[x+1][y]||(JumpF==2&&map[x+1][y])) JumpF=0;
//	SetPos(0,0); cout<<JumpF;
	Player.x=x;Player.y=y;
}
void down() {
	if (!map[Player.x+1][Player.y]) Player.x++;
}
bool ifdie() {
	return die[Player.x][Player.y];
}
int main () {
	story();
	start();
	system("cls");
	Player.x=3;Player.y=1;
	Player.lx=3;Player.ly=1;
	print();
	while (true) {
//		SetPos(0,0);
//		cout<<Player.x<<" "<<Player.y;
		SetPos(22,4);color(2);
		cout<<4;
		if (Player.x==4&&Player.y==22) {
			if (cnt==43) {
				color(14);
				system("cls");
				cout<<"You are Win!!!";
				while (true) Sleep(100);
				return 0;
			}
			else {
				print();
				SetPos(0,7);color(14);
				cout<<"你收集的碎片不够";
			}
		}
		MoveSleep++;
		JumpSleep++;
		ifdie();
		if (MoveSleep==8) {
			control();
			MoveSleep=0;
			SetPos(Player.ly,Player.lx);color(7);
			cout<<" ";
			SetPos(Player.y,Player.x);color(30);
			cout<<"0";
			Player.ly=Player.y;Player.lx=Player.x;
		}
		if (mon[Player.x][Player.y]) {
			mon[Player.x][Player.y]=false;
			cnt++;
		}
		if (JumpSleep==15) {
			down();
			JumpSleep=0;
		} 
		if (ifdie()) {
			system("cls");
			color(64);
			cout<<"Game Over!!!\nYou are die!!!";
			while (true) Sleep(100);
			return 0;
		}
		SetPos(0,6);color(14);cout<<"还差"<<43-cnt<<"个碎片需要收集。";
		Sleep(10);
	}
	return 0;
}

目前只有一关,而且要一命通关,没有复活机会。介绍很简单,就没有设置中途退出看介绍的代码。

而且跳跃有点鬼畜,请求各位帮忙改一下

不是很难,该数据就好了这个if判断里面的数字,下落速度,数字越大越慢同理哈

具体以后会怎么更新看更新内容里面,写完整了。

希望大家玩的愉快

这次游戏界面不像上次发的打飞机那么闪了

王梓澳在2021-08-01 08:33:18追加了内容

还有剧情作者尽力了,有没有语文好的同学帮忙一下

王梓澳在2021-08-01 09:00:26追加了内容

更新动向有个点忘记说了。。。

懒得改代码接太长了。。。

于是

我直接说

隐藏方块、假方块和陷阱(手动斜眼笑)

类似i wanna系列的坑人游戏(嘿嘿)

王梓澳在2021-08-01 11:14:25追加了内容

想玩坑的还是想玩要操作的,我看看怎么做

坑的有点难度。。。

王梓澳在2021-08-01 11:16:00追加了内容

这个部分是地图

map是砖块地图

mon是碎片地图

die是死亡方块地图

如果感觉地图不好或者想要帮作者的可以改

0代表不存在,1代表存在

王梓澳在2021-08-06 18:11:17追加了内容

做了一个小坑,看看大家喜不喜欢这种风格

地图很简单,如果喜欢作者会继续做坑

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <iomanip> 
#include <windows.h>
#include <conio.h>
#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)//判断键盘是否按下函数定义 
using namespace std;
struct Game {
	int x,y,lx,ly;
}Player;
int MoveSleep;
int JumpSleep;
int JumpF;
int cnt;
void SetPos(COORD a) {
	HANDLE out=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleCursorPosition(out, a);
}
void SetPos(int i, int j) {
	COORD pos={i, j};
	SetPos(pos);
}
void color(int a) {
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),a);
}
bool map[10][100]={
{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,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,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,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,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,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,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,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,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,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,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,1,1,1,1,1,1,1,1,1,1,1},
};
bool die[10][100];
void out(string a) {
	for (int i=0;i<a.size();i++) {
		cout<<a[i];
		Sleep(50);
	}
}
void story() {
	color(7);
	cout<<"剧情篇\n";
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("一天你睡觉时,突然梦见你一人站在一个空无一人的地方...\n");
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("一个声音对你说:你的灵魂已破碎不堪\n你向四周看去,没有任何人\n");
	out("接着你醒来了,你去请求神灵,发现梦里的话是真实的...\n");
	cout<<"按下Z继续\n";
	cout<<"按下Q跳过";
	while (true) {
		if (KEY_DOWN('Z')) break;
		if (KEY_DOWN('Q')) return ;
	}system("cls");
	out("神灵问:你想要一个完整的灵魂吗?\n你毫不犹豫的回答道:想!\n");
	out("“我已将你的灵魂碎片散落在一个地方,你收集到所有碎片才能获得完整的灵魂,当然,这也会有危险,你愿意吗?”\n“我愿意!”");
	out("突然你被传送到一个二维世界的地图中...\n");
	cout<<"按下Z继续\n";
	while (!KEY_DOWN('Z'));
}
void in_con() {
	system("cls");
	out("游戏目标:控制0收集所有碎片(*),避开危险(X),到达重点(4)\n");
	out("**作须知:a(左)d(右)w(跳跃)(有二段跳,但是由于作者代码存在问题,很难触发)\n");
	cout<<"按下k继续";
	while (!KEY_DOWN('K'));
	system("cls");
	SetPos(0,0);
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"**作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
}
void update() {
	system("cls");
	color(14);cout<<"1.0~1.1 更新游戏界面和地图\n";color(7);
	color(13);cout<<"关于更新:\n1、作者会更新地图关卡\n2、危险方块移动\n3、小怪物\n4、**\n5、中途退出保存并且下一次打开数据仍然在(需要创建文件夹和相关文件,作者在实验过程中)\n";color(7); 
	cout<<"按下k继续";
	while (!KEY_DOWN('K'));
	system("cls");
	SetPos(0,0);
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"**作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
}
void start() {
	system("cls");
	cout<<"游戏作者:Jack Sparrow\n";
	cout<<"游戏版本:1.1\n";
	cout<<"如有bug请与作者联系\n";
	cout<<"**作须知:界面选择,w(上)s(下),按下z确定\n";
	color(14);cout<<"==================================================";color(7);
	int i=1;
	while (true) {
		SetPos(2,5);cout<<" ";
		SetPos(2,6);cout<<" ";
		SetPos(2,7);cout<<" ";
		if (i==1) {
			if (KEY_DOWN('Z')) return ;
			SetPos(2,5);color(14);cout<<">";color(7);
		}SetPos(3,5); cout<<"开始游戏";
		if (i==2) {
			if (KEY_DOWN('Z')) in_con();
			SetPos(2,6);color(14);cout<<">";color(7);
		}SetPos(3,6); cout<<"查看介绍";
		if (i==3) {
			if (KEY_DOWN('Z')) update();
			SetPos(2,7);color(14);cout<<">";color(7);
		}SetPos(3,7); cout<<"更新内容";
		if (KEY_DOWN('W')&&i-1>=1) i--;
		if (KEY_DOWN('S')&&i+1<=3) i++;
		Sleep(100);
	}
}
void print() {
	SetPos(0,0);
	for (int i=0;i<6;i++) {
		for (int j=0;j<60;j++) {
			color(7);
			if (map[i][j]) cout<<"=";
			else if (die[i][j]) {
				color(64);
				cout<<"X";
			}
			else cout<<" ";
		}
		cout<<endl;
	}
	SetPos(42,4);color(2);cout<<4;
}
void control() {//控制函数
	int x=Player.x,y=Player.y;
	if (KEY_DOWN('W')&&x-1>=0&&JumpF<2&&!map[x-1][y]) {
		JumpF++;
		x-=1;
	}
//	if (KEY_DOWN('S')&&x+1<=5&&!map[x+1][y]) x++;
	if (KEY_DOWN('A')&&y-1>=0&&!map[x][y-1]) y--;
	if (KEY_DOWN('D')&&y+1<100&&!map[x][y+1]) y++;
	if (map[x+1][y]||(JumpF==2&&map[x+1][y])) JumpF=0;
//	SetPos(0,0); cout<<JumpF;
	Player.x=x;Player.y=y;
}
void down() {
	if (!map[Player.x+1][Player.y]) Player.x++;
}
void k_die() {
	int x=Player.x;
	int y=Player.y;
	if (y==1&&!die[4][2]&&!die[4][3]) {
		die[4][2]=true;
		die[4][3]=true;
		print();
		die[4][3]=false;
	}
} 
int main () {
	story();
	start();
	system("cls");
	Player.x=4;Player.y=0;
	Player.lx=3;Player.ly=1;
	print();
	while (true) {
//		SetPos(0,0);
//		cout<<Player.x<<" "<<Player.y;
//		SetPos(42,4);color(2);
//		cout<<4;
		if (Player.x==4&&Player.y==42) {
			color(14);
			system("cls");
			cout<<"You are Win!!!";
//			while (true) Sleep(100);
			return 0;
		}
//		SetPos(0,0);cout<<die[Player.x][Player.y];
		MoveSleep++;
		JumpSleep++;
		if (MoveSleep==10) {
			control();
			MoveSleep=0;
			SetPos(Player.ly,Player.lx);color(7);
			cout<<" ";
			SetPos(Player.y,Player.x);color(30);
			cout<<"0";
			Player.ly=Player.y;Player.lx=Player.x;
		}
		if (JumpSleep==17) {
			down();
			JumpSleep=0;
		}
		if (die[Player.x][Player.y]) {
			system("cls");
			color(64);
			cout<<"Game Over!!!\nYou are die!!!";
//			while (true) Sleep(100);
			return 0;
		}
		k_die();
		Sleep(10);
	}
	return 0;
}

 

王梓澳在2021-08-06 20:00:16追加了内容

给个答复好不好(作者无语)

做坑人版本的还是正常版本的


1
已采纳
王文博
王文博
缔造者之神
缔造者之神

继续加油!

我通关了!!!!!

0
0
0
0
0
0
0
褚俊皓
褚俊皓
新手天翼
新手天翼

我吃碎片点了一次跳跳了两格高,直接死了

几率还挺高

0
薛乘志
薛乘志
初级启示者
初级启示者

这叫马里奥!!!

mario

我要回答