完善配置文件读取

remote
inksoul 2025-10-29 21:25:55 +08:00
parent fbbc6e20af
commit 666cee6c62
5 changed files with 16 additions and 10 deletions

View File

@ -14,7 +14,7 @@ project ("mazzGame")
aux_source_directory(${PROJECT_SOURCE_DIR}/src sourceCodeList)
#
add_executable (mazzGame ${sourceCodeList} "src/Maze.cpp")
add_executable (mazzGame ${sourceCodeList})
if (CMAKE_VERSION VERSION_GREATER 3.12)
set_property(TARGET mazzGame PROPERTY CXX_STANDARD 20)

View File

@ -58,7 +58,7 @@ bool ConfigReader::load(std::string &path)
if (section == "Symbols")
{
if (key == "Wall")
symbols.setWall(value[0]);
m_data.setWall(value[0]);
else if (key == "Empty")
symbols.setEmpty(value[0]);
else if (key == "Player")
@ -73,14 +73,14 @@ bool ConfigReader::load(std::string &path)
else if (section == "Difficulty")
{
if (key == "MonsterAI")
difficulty = std::stoi(value);
m_difficulty = std::stoi(value);
}
else if (section == "Maze")
{
if (key == "Width")
mazeWidth = std::stoi(value);
m_mazeWidth = std::stoi(value);
else if (key == "Height")
mazeHeight = std::stoi(value);
m_mazeHeight = std::stoi(value);
}
}

View File

@ -13,13 +13,11 @@ public:
MazeData getSymbols() const;
void setSymbols(MazeData &value);
private:
std::string trim(const std::string &s);
private:
MazeData symbols; // 存放迷宫符号
int difficulty = 0; // 怪物AI难度
int mazeWidth = 21;
int mazeHeight = 21;
MazeData m_data; // 存放迷宫符号
};

View File

@ -1,5 +1,7 @@
#include "Game.h"
#include <iostream>
Game::Game()
{
}
@ -19,3 +21,8 @@ void Game::initMaze()
void Game::run()
{
}
void Game::printConfig()
{
}

View File

@ -18,6 +18,7 @@ public:
~Game();
void loadConfig(const std::string &filePath, MazeData &data);
void printConfig(MazeData &data);
void initMaze();
void run();
};