智取生辰纲游戏
🎮 游戏概述
基于《水浒传》"智取生辰纲"故事情节改编的策略冒险游戏。玩家可以扮演杨志(押运方)或晁盖(智取方),体验护送生辰纲与智取生辰纲的双重视角,体验古代军事谋略与江湖智慧的碰撞。
📁 项目结构
take_birthday_gifts/
├── main.cpp # 游戏主程序
├── game_config.h # 游戏配置文件
├── CMakeLists.txt # 编译配置文件
├── README.md # 项目说明文档
├── include/ # 头文件目录
│ ├── characters.h # 角色定义
│ ├── items.h # 物品系统
│ ├── combat.h # 战斗系统
│ ├── events.h # 事件系统
│ └── ai.h # AI系统
├── src/ # 源文件目录
│ ├── characters.cpp # 角色实现
│ ├── items.cpp # 物品实现
│ ├── combat.cpp # 战斗实现
│ ├── events.cpp # 事件实现
│ ├── ai.cpp # AI实现
│ └── utils.cpp # 工具函数
├── assets/ # 资源文件
│ ├── maps/ # 地图数据
│ ├── dialogues/ # 对话文本
│ └── config/ # 配置文件
└── docs/ # 文档
├── gameplay_guide.md # 游戏指南
└── design_docs/ # 设计文档
🎯 核心游戏机制
1. 双主角系统
– 杨志线:护送生辰纲,识破陷阱,安全送达
– 晁盖线:设计计谋,智取生辰纲,躲避追捕
2. 策略系统
– 时间管理:白天/黑夜系统
– 资源管理:体力、士气、粮食
– 路径选择:大路(安全但慢) vs 小路(危险但快)
3. 对话系统
– 分支对话影响剧情走向
– 性格系统:不同选择影响角色关系
– 说服系统:通过对话改变NPC行为
4. 战斗系统
– 即时战术战斗
– 技能组合系统
– 环境互动:利用地形优势
🎮 核心代码实现
1. 游戏配置文件 (game_config.h)
/**
* 智取生辰纲游戏配置文件
* 定义游戏核心参数和常量
*/
#ifndef GAME_CONFIG_H
#define GAME_CONFIG_H
#include <string>
#include <vector>
#include <unordered_map>
#include <memory>
// 游戏版本
#define GAME_VERSION "1.0.0"
#define GAME_TITLE "智取生辰纲"
// 游戏难度等级
enum class GameDifficulty {
EASY, // 简单
NORMAL, // 普通
HARD, // 困难
LEGENDARY // 传奇
};
// 游戏模式
enum class GameMode {
STORY, // 故事模式
FREE_PLAY, // 自由模式
CHALLENGE, // 挑战模式
MULTIPLAYER // 多人模式
};
// 时间系统
struct GameTime {
int year; // 年份
int month; // 月份
int day; // 日期
int hour; // 小时(0-23)
int minute; // 分钟
GameTime(int y, int m, int d, int h, int min)
: year(y), month(m), day(d), hour(h), minute(min) {}
// 转换为字符串
std::string toString() const {
char buffer[64];
snprintf(buffer, sizeof(buffer),
"%04d年%02d月%02d日 %02d:%02d",
year, month, day, hour, minute);
return std::string(buffer);
}
// 判断是否是白天
bool isDaytime() const {
return hour >= 6 && hour < 18;
}
// 判断是否是黑夜
bool isNight() const {
return !isDaytime();
}
// 时间流逝
void advanceMinutes(int minutes) {
minute += minutes;
hour += minute / 60;
minute %= 60;
hour %= 24;
// 简化处理,不处理日期变更
}
};
// 天气系统
enum class Weather {
SUNNY, // 晴天
CLOUDY, // 多云
RAINY, // 雨天
STORMY, // 暴雨
FOGGY, // 雾天
WINDY // 大风
};
// 地理位置
struct Location {
std::string name; // 地点名称
std::string description; // 地点描述
double latitude; // 纬度
double longitude; // 经度
int altitude; // 海拔
Weather weather; // 当前天气
int dangerLevel; // 危险等级(1-10)
// 周边地点
std::vector<std::string> connectedLocations;
Location(const std::string& n, const std::string& desc,
double lat, double lon, int alt, Weather w, int danger)
: name(n), description(desc), latitude(lat), longitude(lon),
altitude(alt), weather(w), dangerLevel(danger) {}
// 获取地点类型
std::string getType() const {
if (name.find("岗") != std::string::npos) return "mountain_pass";
if (name.find("林") != std::string::npos) return "forest";
if (name.find("店") != std::string::npos) return "inn";
if (name.find("铺") != std::string::npos) return "shop";
if (name.find("庄") != std::string::npos) return "village";
return "unknown";
}
};
// 游戏配置主类
class GameConfig {
private:
static GameConfig* instance;
GameConfig(); // 私有构造函数
// 配置数据
std::unordered_map<std::string, Location> locations;
std::unordered_map<Weather, std::string> weatherDescriptions;
public:
// 单例模式
static GameConfig* getInstance() {
if (instance == nullptr) {
instance = new GameConfig();
}
return instance;
}
// 禁止拷贝
GameConfig(const GameConfig&) = delete;
GameConfig& operator=(const GameConfig&) = delete;
// 初始化游戏配置
void initialize();
// 获取地点信息
Location* getLocation(const std::string& name) {
auto it = locations.find(name);
return (it != locations.end()) ? &it->second : nullptr;
}
// 获取所有地点
const std::unordered_map<std::string, Location>& getAllLocations() const {
return locations;
}
// 获取天气描述
std::string getWeatherDescription(Weather weather) const {
auto it = weatherDescriptions.find(weather);
return (it != weatherDescriptions.end()) ? it->second : "未知天气";
}
// 游戏参数
struct {
// 时间参数
int dayDurationMinutes = 1440; // 一天时长(分钟)
int hourDurationMinutes = 60; // 一小时时长
// 体力系统
int maxStamina = 100; // 最大体力
int staminaRecoveryRate = 5; // 体力恢复率/小时
int walkingStaminaCost = 1; // 行走体力消耗/分钟
int runningStaminaCost = 3; // 跑步体力消耗/分钟
int fightingStaminaCost = 10; // 战斗体力消耗/次
// 士气系统
int maxMorale = 100; // 最大士气
int moraleDecayRate = 1; // 士气衰减率/小时
int winBattleMoraleBonus = 20; // 战斗胜利士气加成
int loseBattleMoralePenalty = 30; // 战斗失败士气惩罚
// 资源系统
int maxFood = 1000; // 最大粮食
int foodConsumptionRate = 10; // 粮食消耗率/人/天
int maxWater = 1000; // 最大饮水
int waterConsumptionRate = 5; // 饮水消耗率/人/天
// 战斗系统
int baseHitChance = 70; // 基础命中率
int baseDodgeChance = 20; // 基础闪避率
int criticalHitMultiplier = 2; // 暴击倍数
// AI系统
int aiUpdateInterval = 1; // AI更新间隔(秒)
int npcSpawnRadius = 100; // NPC生成半径
} parameters;
// 根据难度调整参数
void applyDifficulty(GameDifficulty difficulty);
// 保存/加载配置
bool saveConfig(const std::string& filename);
bool loadConfig(const std::string& filename);
~GameConfig();
};
#endif // GAME_CONFIG_H
2. 角色系统 (include/characters.h)
/**
* 角色系统定义
* 定义游戏中所有角色和相关系统
*/
#ifndef CHARACTERS_H
#define CHARACTERS_H
#include <string>
#include <vector>
#include <memory>
#include <functional>
#include "items.h"
// 角色属性
struct CharacterAttributes {
int strength; // 力量
int agility; // 敏捷
int intelligence; // 智力
int endurance; // 耐力
int charisma; // 魅力
int luck; // 运气
CharacterAttributes(int str = 10, int agi = 10, int intl = 10,
int end = 10, int cha = 10, int lck = 10)
: strength(str), agility(agi), intelligence(intl),
endurance(end), charisma(cha), luck(lck) {}
// 总属性点数
int total() const {
return strength + agility + intelligence + endurance + charisma + luck;
}
// 序列化
std::string serialize() const;
// 反序列化
static CharacterAttributes deserialize(const std::string& data);
};
// 角色状态
struct CharacterStatus {
int health; // 生命值
int stamina; // 体力
int morale; // 士气
int hunger; // 饥饿度
int thirst; // 口渴度
int fatigue; // 疲劳度
CharacterStatus(int hp = 100, int sta = 100, int mor = 100,
int hun = 0, int thi = 0, int fat = 0)
: health(hp), stamina(sta), morale(mor),
hunger(hun), thirst(thi), fatigue(fat) {}
// 检查是否存活
bool isAlive() const { return health > 0; }
// 检查是否健康
bool isHealthy() const { return health >= 50 && morale >= 50; }
// 更新状态
void update(int deltaTime);
};
// 技能系统
class Skill {
private:
std::string name;
std::string description;
int level;
int maxLevel;
int experience;
SkillType type;
public:
Skill(const std::string& n, const std::string& desc,
SkillType t, int maxLvl = 10)
: name(n), description(desc), level(1),
maxLevel(maxLvl), experience(0), type(t) {}
// 获取技能名称
std::string getName() const { return name; }
// 获取技能描述
std::string getDescription() const { return description; }
// 获取技能等级
int getLevel() const { return level; }
// 获取技能类型
SkillType getType() const { return type; }
// 增加经验
void addExperience(int exp) {
experience += exp;
// 升级逻辑
int requiredExp = level * 100;
while (experience >= requiredExp && level < maxLevel) {
experience -= requiredExp;
level++;
requiredExp = level * 100;
}
}
// 使用技能
virtual bool use(Character* user, Character* target = nullptr) = 0;
virtual ~Skill() {}
};
// 战斗技能
class CombatSkill : public Skill {
private:
int damage;
int staminaCost;
int cooldown;
int currentCooldown;
public:
CombatSkill(const std::string& n, const std::string& desc,
int dmg, int cost, int cd)
: Skill(n, desc, SkillType::COMBAT),
damage(dmg), staminaCost(cost),
cooldown(cd), currentCooldown(0) {}
bool use(Character* user, Character* target = nullptr) override;
// 更新冷却
void updateCooldown(int deltaTime) {
if (currentCooldown > 0) {
如果你觉得这个游戏好玩,欢迎关注我!
网硕互联帮助中心





评论前必须登录!
注册