C++#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <map>
#include <algorithm>
#include <iomanip>
using namespace std;
// 第一世代151只宝可梦中英文对照
map<int, string> pokemonNames = {
{1, "妙蛙种子"}, {2, "妙蛙草"}, {3, "妙蛙花"},
{4, "小火龙"}, {5, "火恐龙"}, {6, "喷火龙"},
{7, "杰尼龟"}, {8, "卡咪龟"}, {9, "水箭龟"},
{10, "绿毛虫"}, {11, "铁甲蛹"}, {12, "巴大蝶"},
{13, "独角虫"}, {14, "铁壳蛹"}, {15, "大针蜂"},
{16, "波波"}, {17, "比比鸟"}, {18, "大比鸟"},
{19, "小拉达"}, {20, "拉达"},
{21, "烈雀"}, {22, "大嘴雀"},
{23, "阿柏蛇"}, {24, "阿柏怪"},
{25, "皮卡丘"}, {26, "雷丘"},
{27, "穿山鼠"}, {28, "穿山王"},
{29, "尼多兰"}, {30, "尼多娜"}, {31, "尼多后"},
{32, "尼多朗"}, {33, "尼多力诺"}, {34, "尼多王"},
{35, "皮皮"}, {36, "皮可西"},
{37, "六尾"}, {38, "九尾"},
{39, "胖丁"}, {40, "胖可丁"},
{41, "超音蝠"}, {42, "大嘴蝠"},
{43, "走路草"}, {44, "臭臭花"}, {45, "霸王花"},
{46, "派拉斯"}, {47, "派拉斯特"},
{48, "毛球"}, {49, "摩鲁蛾"},
{50, "地鼠"}, {51, "三地鼠"},
{52, "喵喵"}, {53, "猫老大"},
{54, "可达鸭"}, {55, "哥达鸭"},
{56, "猴怪"}, {57, "火暴猴"},
{58, "卡蒂狗"}, {59, "风速狗"},
{60, "蚊香蝌蚪"}, {61, "蚊香君"}, {62, "蚊香泳士"},
{63, "凯西"}, {64, "勇基拉"}, {65, "胡地"},
{66, "腕力"}, {67, "豪力"}, {68, "怪力"},
{69, "喇叭芽"}, {70, "口呆花"}, {71, "大食花"},
{72, "玛瑙水母"}, {73, "毒刺水母"},
{74, "小拳石"}, {75, "隆隆石"}, {76, "隆隆岩"},
{77, "小火马"}, {78, "烈焰马"},
{79, "呆呆兽"}, {80, "呆壳兽"},
{81, "小磁怪"}, {82, "三合一磁怪"},
{83, "大葱鸭"},
{84, "嘟嘟"}, {85, "嘟嘟利"},
{86, "小海狮"}, {87, "白海狮"},
{88, "臭泥"}, {89, "臭臭泥"},
{90, "大舌贝"}, {91, "刺甲贝"},
{92, "鬼斯"}, {93, "鬼斯通"}, {94, "耿鬼"},
{95, "大岩蛇"},
{96, "催眠貘"}, {97, "引梦貘人"},
{98, "大钳蟹"}, {99, "巨钳蟹"},
{100, "霹雳电球"}, {101, "顽皮雷弹"},
{102, "蛋蛋"}, {103, "椰蛋树"},
{104, "卡拉卡拉"}, {105, "嘎啦嘎啦"},
{106, "飞腿郎"},
{107, "快拳郎"},
{108, "大舌头"},
{109, "瓦斯弹"}, {110, "双弹瓦斯"},
{111, "独角犀牛"}, {112, "钻角犀兽"},
{113, "吉利蛋"},
{114, "蔓藤怪"},
{115, "袋兽"},
{116, "墨海马"}, {117, "海刺龙"},
{118, "角金鱼"}, {119, "金鱼王"},
{120, "海星星"}, {121, "宝石海星"},
{122, "魔墙人偶"},
{123, "飞天螳螂"},
{124, "迷唇姐"},
{125, "电击兽"},
{126, "鸭嘴火兽"},
{127, "凯罗斯"},
{128, "肯泰罗"},
{129, "鲤鱼王"}, {130, "暴鲤龙"},
{131, "拉普拉斯"},
{132, "百变怪"},
{133, "伊布"}, {134, "水伊布"}, {135, "雷伊布"}, {136, "火伊布"},
{137, "多边兽"},
{138, "菊石兽"}, {139, "多刺菊石兽"},
{140, "化石盔"}, {141, "镰刀盔"},
{142, "化石翼龙"},
{143, "卡比兽"},
{144, "急冻鸟"},
{145, "闪电鸟"},
{146, "火焰鸟"},
{147, "迷你龙"}, {148, "哈克龙"}, {149, "快龙"},
{150, "超梦"},
{151, "梦幻"}
};
// 宝可梦类
class Pokemon {
public:
int id; // 宝可梦编号 (1-151)
string name;
int level;
int hp;
int maxHp;
int attack;
bool isPlayer;
bool isCompanion;
int x, y; // 位置
int type; // 0:普通, 1:火, 2:水, 3:草, 4:电, 5:冰, 6:格斗, 7:毒, 8:地面, 9:飞行, 10:超能力, 11:虫, 12:岩石, 13:幽灵, 14:龙, 15:钢
Pokemon(int pid, int lvl, int posX, int posY, bool player = false, bool companion = false)
: id(pid), level(lvl), x(posX), y(posY), isPlayer(player), isCompanion(companion) {
name = pokemonNames[pid];
// 根据ID设置基本属性
maxHp = 30 + (pid % 20) * 5;
attack = 5 + (pid % 10) * 2;
// 传说宝可梦增强
if (pid >= 144 && pid <= 151) {
maxHp *= 2;
attack *= 2;
}
// 玩家宝可梦增强
if (player) {
maxHp *= 1.5;
attack *= 1.5;
}
// 应用等级加成
maxHp *= (1 + level / 10.0);
attack *= (1 + level / 10.0);
hp = maxHp;
// 设置宝可梦类型
setType(pid);
}
// 设置宝可梦类型
void setType(int pid) {
if (pid >= 1 && pid <= 3) type = 3; // 草
else if (pid >= 4 && pid <= 6) type = 1; // 火
else if (pid >= 7 && pid <= 9) type = 2; // 水
else if (pid == 25 || pid == 26 || pid == 100 || pid == 101 || pid == 125) type = 4; // 电
else if (pid == 37 || pid == 38 || pid == 58 || pid == 59 || pid == 77 || pid == 78 || pid == 126) type = 1; // 火
else if (pid == 60 || pid == 61 || pid == 62 || pid == 72 || pid == 73 || pid == 86 || pid == 87 || pid == 90 || pid == 91 || pid == 116 || pid == 117 || pid == 118 || pid == 119 || pid == 120 || pid == 121 || pid == 131 || pid == 134) type = 2; // 水
else if (pid == 43 || pid == 44 || pid == 45 || pid == 46 || pid == 47 || pid == 69 || pid == 70 || pid == 71 || pid == 102 || pid == 103 || pid == 114) type = 3; // 草
else if (pid == 144) type = 5; // 冰
else if (pid == 145) type = 4; // 电
else if (pid == 146) type = 1; // 火
else if (pid >= 56 && pid <= 57 || pid == 106 || pid == 107) type = 6; // 格斗
else if (pid >= 23 && pid <= 24 || pid == 29 || pid == 30 || pid == 31 || pid == 32 || pid == 33 || pid == 34 || pid == 41 || pid == 42 || pid == 72 || pid == 73 || pid == 88 || pid == 89 || pid == 109 || pid == 110) type = 7; // 毒
else if (pid == 27 || pid == 28 || pid == 50 || pid == 51 || pid == 74 || pid == 75 || pid == 76 || pid == 95 || pid == 104 || pid == 105 || pid == 111 || pid == 112) type = 8; // 地面
else if (pid >= 16 && pid <= 18 || pid == 21 || pid == 22 || pid == 41 || pid == 42 || pid == 83 || pid == 84 || pid == 85 || pid == 123 || pid == 142) type = 9; // 飞行
else if (pid == 63 || pid == 64 || pid == 65 || pid == 79 || pid == 80 || pid == 96 || pid == 97 || pid == 102 || pid == 103 || pid == 122 || pid == 124 || pid == 150 || pid == 151) type = 10; // 超能力
else if (pid == 10 || pid == 11 || pid == 12 || pid == 13 || pid == 14 || pid == 15 || pid == 46 || pid == 47 || pid == 48 || pid == 49 || pid == 123 || pid == 127) type = 11; // 虫
else if (pid == 74 || pid == 75 || pid == 76 || pid == 95 || pid == 138 || pid == 139 || pid == 140 || pid == 141) type = 12; // 岩石
else if (pid >= 92 && pid <= 94) type = 13; // 幽灵
else if (pid >= 147 && pid <= 149) type = 14; // 龙
else if (pid == 81 || pid == 82) type = 15; // 钢
else type = 0; // 普通
}
// 显示宝可梦信息
void displayInfo() const {
string typeNames[16] = {"普通", "火", "水", "草", "电", "冰", "格斗", "毒", "地面", "飞行",
"超能力", "虫", "岩石", "幽灵", "龙", "钢"};
cout << name << " Lv" << level << " (" << typeNames[type] << ")";
cout << " HP: " << hp << "/" << maxHp;
}
};
// 游戏类
class PokemonGame {
private:
const int WIDTH = 40;
const int HEIGHT = 20;
vector<vector<char>> map;
Pokemon player;
vector<Pokemon> companions;
vector<Pokemon> enemies;
int score;
int gameLevel;
int experience;
int nextLevelExp;
int maxCompanions;
public:
PokemonGame() : player(133, 5, WIDTH/2, HEIGHT/2, true), score(0), gameLevel(1), experience(0), nextLevelExp(100), maxCompanions(3) {
// 初始化地图
map = vector<vector<char>>(HEIGHT, vector<char>(WIDTH, '.'));
// 创建初始敌人
spawnEnemies(10);
}
// 生成敌人
void spawnEnemies(int count) {
for (int i = 0; i < count; i++) {
int x, y;
do {
x = rand() % WIDTH;
y = rand() % HEIGHT;
} while (map[y][x] != '.' ||
(x == player.x && y == player.y));
// 随机选择宝可梦ID (1-151),但排除伊布(133)
int enemyId;
do {
enemyId = rand() % 151 + 1;
} while (enemyId == 133);
enemies.push_back(Pokemon(enemyId, gameLevel, x, y));
map[y][x] = 'E';
}
}
// 显示游戏地图
void displayMap() {
system("cls");
cout << "=== 宝可梦割草游戏 ===" << endl;
cout << "分数: " << score << " | 等级: " << gameLevel << " | 经验: " << experience << "/" << nextLevelExp;
cout << " | 同伴数: " << companions.size() << "/" << maxCompanions << endl;
cout << "控制: W(上) A(左) S(下) D(右) 空格(攻击) Q(退出)" << endl << endl;
// 绘制地图
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
if (player.x == x && player.y == y) {
cout << 'P'; // 玩家
} else {
bool drawn = false;
// 绘制同伴
for (const auto& comp : companions) {
if (comp.x == x && comp.y == y) {
cout << 'C';
drawn = true;
break;
}
}
// 绘制敌人
if (!drawn) {
for (const auto& enemy : enemies) {
if (enemy.x == x && enemy.y == y) {
cout << 'E';
drawn = true;
break;
}
}
}
if (!drawn) {
cout << map[y][x];
}
}
cout << ' ';
}
cout << endl;
}
cout << endl;
// 显示玩家信息
cout << "主角: ";
player.displayInfo();
cout << endl;
// 显示同伴信息
if (!companions.empty()) {
cout << "同伴: ";
for (size_t i = 0; i < min(static_cast<size_t>(3), companions.size()); i++) {
companions[i].displayInfo();
cout << " | ";
}
if (companions.size() > 3) cout << "..." << companions.size() - 3 << " more";
cout << endl;
}
// 显示附近敌人信息
cout << "附近敌人: ";
int displayed = 0;
for (const auto& enemy : enemies) {
int dx = abs(player.x - enemy.x);
int dy = abs(player.y - enemy.y);
if (dx <= 5 && dy <= 5) {
enemy.displayInfo();
cout << " | ";
if (++displayed >= 3) break;
}
}
if (displayed == 0) cout << "无";
cout << endl;
}
// 移动玩家
void movePlayer(int dx, int dy) {
int newX = player.x + dx;
int newY = player.y + dy;
if (newX >= 0 && newX < WIDTH && newY >= 0 && newY < HEIGHT) {
player.x = newX;
player.y = newY;
}
}
// 玩家攻击
void playerAttack() {
bool attacked = false;
// 检查周围敌人
for (auto& enemy : enemies) {
int dx = abs(player.x - enemy.x);
int dy = abs(player.y - enemy.y);
if (dx <= 2 && dy <= 2) {
// 计算伤害,考虑属性相克
int damage = player.attack;
// 属性相克系统
if ((player.type == 1 && enemy.type == 3) || // 火克草
(player.type == 1 && enemy.type == 11) || // 火克虫
(player.type == 1 && enemy.type == 15) || // 火克钢
(player.type == 2 && enemy.type == 1) || // 水克火
(player.type == 2 && enemy.type == 8) || // 水克地面
(player.type == 2 && enemy.type == 12) || // 水克岩石
(player.type == 3 && enemy.type == 2) || // 草克水
(player.type == 3 && enemy.type == 8) || // 草克地面
(player.type == 3 && enemy.type == 12) || // 草克岩石
(player.type == 4 && enemy.type == 2) || // 电克水
(player.type == 4 && enemy.type == 9) || // 电克飞行
(player.type == 6 && enemy.type == 0) || // 格斗克普通
(player.type == 6 && enemy.type == 12) || // 格斗克岩石
(player.type == 6 && enemy.type == 15)) // 格斗克钢
{
damage *= 1.5;
}
enemy.hp -= damage;
attacked = true;
cout << player.name << " 攻击了 " << enemy.name << "! ";
cout << "造成了 " << damage << " 点伤害!" << endl;
// 如果敌人被击败
if (enemy.hp <= 0) {
int expGained = 10 * enemy.level;
score += expGained;
experience += expGained;
cout << "击败了 " << enemy.name << "! 获得 " << expGained << " 经验值!" << endl;
// 20%几率获得同伴
if (companions.size() < maxCompanions && rand() % 100 < 20) {
companions.push_back(Pokemon(enemy.id, enemy.level, enemy.x, enemy.y, false, true));
cout << "获得了同伴: " << companions.back().name << "!" << endl;
}
}
}
}
// 移除被击败的敌人
auto it = enemies.begin();
while (it != enemies.end()) {
if (it->hp <= 0) {
map[it->y][it->x] = '.';
it = enemies.erase(it);
} else {
++it;
}
}
if (!attacked) {
cout << "没有可以攻击的敌人!" << endl;
}
Sleep(500);
}
// 同伴自动攻击
void companionsAttack() {
for (auto& comp : companions) {
for (auto& enemy : enemies) {
int dx = abs(comp.x - enemy.x);
int dy = abs(comp.y - enemy.y);
if (dx <= 2 && dy <= 2) {
int damage = comp.attack;
enemy.hp -= damage;
cout << comp.name << " 攻击了 " << enemy.name << "! ";
cout << "造成了 " << damage << " 点伤害!" << endl;
if (enemy.hp <= 0) {
int expGained = 5 * enemy.level;
score += expGained;
experience += expGained;
cout << "击败了 " << enemy.name << "! 获得 " << expGained << " 经验值!" << endl;
}
}
}
}
// 移除被击败的敌人
auto it = enemies.begin();
while (it != enemies.end()) {
if (it->hp <= 0) {
map[it->y][it->x] = '.';
it = enemies.erase(it);
} else {
++it;
}
}
}
// 敌人移动
void moveEnemies() {
for (auto& enemy : enemies) {
// 简单AI:随机移动或向玩家移动
int moveType = rand() % 3;
int dx = 0, dy = 0;
if (moveType == 0) { // 随机移动
dx = (rand() % 3) - 1; // -1, 0, 1
dy = (rand() % 3) - 1;
} else { // 向玩家移动
if (enemy.x < player.x) dx = 1;
else if (enemy.x > player.x) dx = -1;
if (enemy.y < player.y) dy = 1;
else if (enemy.y > player.y) dy = -1;
}
int newX = enemy.x + dx;
int newY = enemy.y + dy;
if (newX >= 0 && newX < WIDTH && newY >= 0 && newY < HEIGHT) {
// 检查是否与同伴或其他敌人位置冲突
bool canMove = true;
for (const auto& comp : companions) {
if (comp.x == newX && comp.y == newY) {
canMove = false;
break;
}
}
for (const auto& e : enemies) {
if (&e != &enemy && e.x == newX && e.y == newY) {
canMove = false;
break;
}
}
if (canMove) {
enemy.x = newX;
enemy.y = newY;
}
}
}
}
// 检查升级
void checkLevelUp() {
while (experience >= nextLevelExp) {
experience -= nextLevelExp;
gameLevel++;
nextLevelExp = 100 + gameLevel * 50;
// 玩家升级奖励
player.maxHp *= 1.1;
player.hp = player.maxHp;
player.attack *= 1.1;
player.level++;
// 同伴升级
for (auto& comp : companions) {
comp.maxHp *= 1.05;
comp.hp = comp.maxHp;
comp.attack *= 1.05;
comp.level++;
}
cout << "恭喜升级! 当前等级: " << gameLevel << endl;
Sleep(1000);
// 每5级增加一个同伴位置
if (gameLevel % 5 == 0) {
maxCompanions++;
cout << "同伴上限增加! 现在最多可携带 " << maxCompanions << " 只同伴!" << endl;
Sleep(1000);
}
}
}
// 运行游戏
void run() {
srand(time(0));
// 显示游戏标题
cout << "===============================================" << endl;
cout << " 宝可梦割草游戏 - 第一世代151只宝可梦 " << endl;
cout << "===============================================" << endl;
cout << "控制说明: " << endl;
cout << " W - 上移 A - 左移 S - 下移 D - 右移" << endl;
cout << " 空格 - 攻击 Q - 退出游戏" << endl << endl;
cout << "游戏目标: " << endl;
cout << " 控制伊布击败野生宝可梦,收集同伴宝可梦" << endl;
cout << " 击败敌人获得经验值,提升等级" << endl << endl;
cout << "按任意键开始游戏...";
_getch();
while (true) {
displayMap();
// 生成新敌人
if (enemies.size() < 10 + gameLevel) {
spawnEnemies(rand() % 3 + 1);
}
// 获取输入
if (_kbhit()) {
char input = _getch();
input = tolower(input);
switch(input) {
case 'w': movePlayer(0, -1); break;
case 'a': movePlayer(-1, 0); break;
case 's': movePlayer(0, 1); break;
case 'd': movePlayer(1, 0); break;
case ' ': playerAttack(); break;
case 'q':
cout << "游戏结束! 最终分数: " << score << endl;
return;
}
}
// 同伴攻击
companionsAttack();
// 敌人移动
moveEnemies();
// 敌人攻击玩家
for (auto& enemy : enemies) {
int dx = abs(player.x - enemy.x);
int dy = abs(player.y - enemy.y);
if (dx <= 2 && dy <= 2) {
int damage = enemy.attack;
player.hp -= damage;
cout << enemy.name << " 攻击了 " << player.name << "! ";
cout << "造成了 " << damage << " 点伤害!" << endl;
if (player.hp <= 0) {
cout << "你的伊布被击败了! 游戏结束!" << endl;
cout << "最终分数: " << score << endl;
return;
}
}
}
// 恢复玩家HP
if (player.hp < player.maxHp) {
player.hp += 0.5; // 缓慢恢复
if (player.hp > player.maxHp) player.hp = player.maxHp;
}
// 检查升级
checkLevelUp();
Sleep(200); // 控制游戏速度
}
}
};
int main() {
// 设置控制台支持中文
SetConsoleOutputCP(65001);
SetConsoleCP(65001);
PokemonGame game;
game.run();
return 0;
}