#include<iostream>
#include<cstdio>
#include<conio.h>
#include<windows.h>
#include<ctime>
#include<cstdlib>
using namespace std;
int main() {
system("title 移动小游戏");
string s = "这是一个迷宫游戏";
for (int i = 0; i < s.size(); i++){
cout << s[i];
Sleep(30);
}
cout << endl;
s = "asdw用于控制";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(50);
}
cout << endl;
s = "r可以破坏方块//但是只有五次机会";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(50);
}
cout << endl;
while (1) {
int jl = 0;
srand(time(NULL));
system("cls");
s = "你准备好了吗//y代表继续,n代退出";
for (int i = 0; i < s.size(); i++) {
cout << s[i];
Sleep(50);
}
cout << endl;
char pd;
cin >> pd;
if (pd == 'n') return 0;
clock_t strat1, end1;
strat1 = clock();
char a[100][100] = { '\0' };
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
if (i == 0 || i == 9) {
a[i][j] = '#';
continue;
}
if (j == 0 || j == 9) {
a[i][j] = '#';
continue;
}
a[i][j] = ' ';
}
}
while (1) {
int mx, my;
mx = rand() % 9;
my = rand() % 9;
//cout << mx << my << endl;
if (mx == 1 && my == 1)
continue;
if (mx == 0 || mx == 9)
continue;
if (my == 0 || my == 9)
continue;
if (my == 8 && mx == 8)
continue;
a[mx][my] = '#';
jl++;
if (jl >= 23)
break;
}
a[1][1] = '*';
cout << "如果觉得无法通关,请按下q" << endl;
cout << "cs:5" << endl;
for (int i = 0; i <= 10; i++)
puts(a[i]);
char ch;
int cs = 5;
int x = 1, y = 1;
char ch1 = 'd';
while (1) {
ch = _getch();
if (ch == 'r') {
if (cs <= 0) continue;
if (ch1 == 'a')
if (y != 1) a[x][y - 1] = ' ';
if (ch1 == 's')
if (x != 6) a[x + 1][y] = ' ';
if (ch1 == 'd')
if (y != 6) a[x][y + 1] = ' ';
if (ch1 == 'w')
if (x != 1) a[x - 1][y] = ' ';
cs--;
}
if (ch == 'a') {
if (a[x][y - 1] != '#') {
a[x][y] = ' ';
y--;
a[x][y] = '*';
}
ch1 = 'a';
}
if (ch == 's') {
if (a[x + 1][y] != '#') {
a[x][y] = ' ';
x++;
a[x][y] = '*';
}
ch1 = 's';
}
if (ch == 'd') {
if (a[x][y + 1] != '#') {
a[x][y] = ' ';
y++;
a[x][y] = '*';
}
ch1 = 'd';
}
if (ch == 'w') {
if (a[x - 1][y] != '#') {
a[x][y] = ' ';
x--;
a[x][y] = '*';
}
ch1 = 'w';
}
if (ch == 'q') return 0;
system("cls");
cout << "如果觉得无法通关,请按下q" << endl;
cout << "cs:" << cs << endl;
for (int i = 0; i <= 10; i++)
puts(a[i]);
if (x == 8 && y == 8) {
system("cls");
cout << "\t\t\t\t\t\t\t";
Sleep(10);
break;
}
}
end1 = clock();
cout << "You Win!!\n\t\t\t\t\t\t\t你用时";
cout << double(end1 - strat1) / 1000 << "秒\n\n\n\n";
Sleep(1000);
}
system("pause");
return 0;
}
c++小游戏,迷宫(随机的地图)
本文含有隐藏内容,请 开通VIP 后查看