- 整数的数字和
408聊天社
- @ 2026-4-17 17:11:00
6 条评论
-
夏茂勋 LV 5 @ 2026-6-12 18:37:22 -
@ 2026-6-8 17:39:22
Hello
-
@ 2026-6-4 19:25:57.
.
.
.
-
@ 2026-6-4 19:25:16 -
@ 2026-5-31 11:22:14#include <iostream> #include <cstdlib> #include <ctime> #include <conio.h> #include <windows.h> using namespace std; // 清屏函数 void clear() { system("cls"); } // 随机障碍物数量(难度随关卡提升) int getBlockCount(int level) { if (level <= 10) return 2; if (level <= 50) return 3; if (level <= 100) return 5; if (level <= 500) return 8; if (level <= 1000) return 10; if (level <= 1500) return 15; return 20; // 1500~2000关最难 } // 游戏主逻辑 void playLevel(int &level) { int carX = 1, carY = 1; // G 终点 随机位置 int goalX = rand() % 18 + 1; int goalY = rand() % 9 + 1; int blocks = getBlockCount(level); int hp = 3; // 血量:3点 // 生成随机障碍物 bool block[20][10] = {false}; srand(time(0) + level); for (int i = 0; i < blocks; i++) { int x = rand() % 19 + 1; int y = rand() % 9 + 1; if ((x == carX && y == carY) || (x == goalX && y == goalY)) { i--; continue; } block[x][y] = true; } // 游戏循环 while (true) { clear(); cout << "===== 汽车闯关游戏 第 " << level << " / 2000 关 =====" << endl; cout << "方向键=移动 J=跳关 P=暂停 R=重开 血量: " << hp << endl; cout << "开到【G】终点" << endl << endl; // 绘制地图 for (int y = 0; y < 10; y++) { for (int x = 0; x < 20; x++) { if (x == carX && y == carY) { cout << "CAR "; } else if (x == goalX && y == goalY) { cout << "G "; } else if (block[x][y]) { cout << "## "; } else { cout << ".. "; } } cout << endl; } // 到达终点 if (carX == goalX && carY == goalY) { cout << endl << "================================" << endl; cout << " Very Good !!!" << endl; cout << "================================" << endl; Sleep(1500); return; } // 血量为0,重新开始本关 if (hp <= 0) { cout << endl << "===== 血量耗尽,重新开始当前关 =====" << endl; Sleep(1500); playLevel(level); return; } // 按键控制 char ch = _getch(); int nx = carX, ny = carY; // 重新开始当前关卡 R/r if (ch == 'r' || ch == 'R') { playLevel(level); return; } // 暂停 P/p if (ch == 'p' || ch == 'P') { cout << endl << "===== 游戏已暂停,按任意键继续 =====" << endl; return; } // 跳关 J/j if (ch == 'j' || ch == 'J') { cout << endl << "输入跳关关卡 (1-2000): "; cin >> level; if (level < 1) level = 1; if (level > 2000) level = 2000; playLevel(level); return; } // 方向移动 if (ch == 72) ny--; // 上 if (ch == 80) ny++; // 下 if (ch == 75) nx--; // 左 if (ch == 77) nx++; // 右 // 边界 + 障碍物判断(撞墙掉血) bool hit = false; if (nx < 0 || nx >= 20 || ny < 0 || ny >= 10) hit = true; else if (block[nx][ny]) hit = true; if (hit) { hp--; // 撞墙掉1点血 } else { carX = nx; carY = ny; } } } int main() { int level = 1; srand(time(0)); cout << "===== 汽车闯关小游戏 满级版=====" << endl; cout << "===== V9.0.0=====" << endl; cout << "按任意键开始游戏..." << endl; _getch(); // 2000关循环 for (; level <= 2000; level++) { playLevel(level); } cout << endl << " 恭喜你通关全部 2000 关!!!" << endl; return 0; } -
@ 2026-5-22 17:11:07EGH
- 1
信息
- ID
- 1342
- 时间
- ms
- 内存
- MiB
- 难度
- 9
- 标签
- (无)
- 递交数
- 38
- 已通过
- 4
- 上传者