不知道什么图片
2025-08-10 16:24:27
发布于:浙江
#include <bits/stdc++.h>
#include <conio.h>
using namespace std;
void memu();
struct Pickaxe {
int a[5] = {20, 30, 50};
int hardness, grade;
Pickaxe (int grade = 0) {
this -> grade = grade;
}
};
struct Player {
vector <Pickaxe> pickaxe;
int mines[5] = {0, 0, 0};
int money = 0;
int power = 114514;
};
Player player;
struct Mine {
int n;
char mine[50][50];
bool isShow[50][50];
string information;
struct Pos {
int x, y;
Pos (int x = 1, int y = 1) {
this -> x = x;
this -> y = y;
}
};
Pos playerPos;
Mine (int n = 4, Pos pos = {1, 1}) {
this -> n = n;
playerPos = pos;
information = "";
srand(time(0));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
mine[i][j] = rand() % 2 ? ' ' : '*';
isShow[i][j] = 0;
}
}
mine[rand() % (n - 1) + 2][rand() % (n - 1) + 2] = 'O';
isShow[playerPos.x][playerPos.y] = 1;
}
void pr() {
system("cls");
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == playerPos.x && j == playerPos.y) {
printf("@");
} else if (isShow[i][j]) {
printf("%c", mine[i][j]);
} else {
printf("#");
}
printf(" ");
}
printf("\n");
}
printf("%s\n", information.c_str());
printf("体力:%d", player.power);
}
void dig(int x, int y) {
if (!isShow[x][y] && player.power) {
if (mine[x][y] == '*') {
int r = rand() % 100 + 1;
if (1 <= r && r <= 75) {
r = 0;
} else if (76 <= r && r <= 95) {
r = 1;
} else {
r = 2;
}
player.mines[r]++;
string s[5] = {"铁", "金", "钻石"};
information = "你挖到了" + s[r] + "矿";
} else if (mine[x][y] == 'O') {
information = "你挖到了通往下一层的洞口";
} else {
information = "你什么都没挖到";
}
isShow[x][y] = 1;
player.power--;
} else {
information = "";
}
}
int playerMove(char key) {
int d[4][2] = {-1, 0, 1, 0, 0, -1, 0, 1};
int f = -1;
switch (key) {
case 'w':
f = 0;
break;
case 's':
f = 1;
break;
case 'a':
f = 2;
break;
case 'd':
f = 3;
break;
case ' ':
f = -2;
break;
}
if (f == -2 && mine[playerPos.x][playerPos.y] == 'O') {
return 1;
} else {
if (f != -1) {
int x = playerPos.x + d[f][0], y = playerPos.y + d[f][1];
if (1 <= x && x <= n && 1 <= y && y <= n) {
if (isShow[x][y]) {
playerPos.x = x, playerPos.y = y;
information = "";
} else if (player.power) {
playerPos.x = x, playerPos.y = y;
dig(x, y);
}
}
}
}
return 0;
}
// void ask() {
// isShow[a][b] = 1;
// pr();
// string s[5] = {"铁", "金", "钻石"};
// int v[5] = {10, 30, 100};
// if (mine[a][b] == '@') {
// int r = rand() % 10;
// if (0 <= r && r <= 6) {
// r = 0;
// } else if (7 <= r && r <= 9) {
// r = 1;
// } else {
// r = 2;
// }
// player.mines[r]++;
// cout << "你挖到了" << s[r] << "矿" << endl;
// cout << "镐子耐久-1" << endl;
// } else {
// cout << "你什么都没挖到" << endl;
// cout << "镐子耐久-1" << endl;
// }
// }
};
struct Mines {
string name;
vector <Mine> mine;
Mines (string name = "矿洞") {
this -> name = name;
}
};
vector <Mines> saves;
void toMine(int choose) {
int floor = 0;
Mine mine = saves[choose].mine[floor];
mine.pr();
while (true) {
if (_kbhit()) {
char key = _getch();
if (key == 27) {
break;
}
int isDownward = mine.playerMove(key);
if (isDownward) {
floor++;
saves[choose].mine.push_back(Mine(4, {mine.playerPos.x, mine.playerPos.y}));
mine = saves[choose].mine[floor];
}
mine.pr();
}
}
}
void chooseMine() {
int choose = 0;
while (true) {
system("cls");
for (int i = 0; i < saves.size(); i++) {
if (i == choose) {
printf("[");
} else {
printf(" ");
}
printf("%d.%s", i + 1, saves[i].name.c_str());
if (i == choose) {
printf("]");
}
printf("\n");
}
char key = _getch();
if (key == 'w' && choose > 0) {
choose--;
}
if (key == 's' && choose < saves.size() - 1) {
choose++;
}
if (key == ' ') {
break;
}
}
toMine(choose);
memu();
}
void bag() {
system("cls");
int choose = 0;
printf("你拥有\n\n");
printf("铁矿*%d 金矿*%d 钻石*%d\n\n", player.mines[0], player.mines[1], player.mines[2]);
printf("你现在的体力:%d", player.power);
_getch();
memu();
}
void buy() {
//
}
void sell() {
cout << "你要出售什么" << endl;
cout << "1." << endl;
cout << "2." << endl;
cout << "3." << endl;
}
void toMarket() {
printf("1.购买");
printf("2.出售");
char key;
while (true) {
key = _getch();
if ('1' <= key && key <= '2') {
break;
}
}
switch (key) {
case '1':
buy();
break;
case '2':
sell();
break;
}
}
void init() {
Mines mines;
mines.mine.push_back(Mine());
saves.push_back(mines);
}
void memu() {
system("cls");
printf("1.下矿\n");
printf("2.背包\n");
printf("3.市场\n");
char key;
while (true) {
key = _getch();
if ('1' <= key && key <= '3') {
break;
}
}
switch (key) {
case '1':
chooseMine();
break;
case '2':
bag();
break;
case '3':
toMarket();
break;
}
}
int main() {
init();
memu();
return 0;
}
这里空空如也
有帮助,赞一个