diff --git a/mazzGame/src/Config.cpp b/mazzGame/src/Config.cpp index 50854fb..b935a7a 100644 --- a/mazzGame/src/Config.cpp +++ b/mazzGame/src/Config.cpp @@ -1,7 +1,10 @@ -#include "Config.h" +#include "Config.h" #include -#include #include +#include +#include +#include +#include #include ConfigReader::ConfigReader() @@ -32,7 +35,9 @@ std::string ConfigReader::trim(const std::string &s) bool ConfigReader::load(const std::string &path) { + std::ifstream file(path); + file.imbue(std::locale(std::locale(), new std::codecvt_utf8)); if (!file.is_open()) { std::cerr << "无法打开配置文件: " << path << std::endl; diff --git a/mazzGame/src/Game.cpp b/mazzGame/src/Game.cpp index 062eac7..2bd4cef 100644 --- a/mazzGame/src/Game.cpp +++ b/mazzGame/src/Game.cpp @@ -1,4 +1,4 @@ -#include "Game.h" +#include "Game.h" #include @@ -25,14 +25,17 @@ void Game::run() void Game::printConfig() { auto sym = m_config.getSymbols(); - std::cout << "符号配置:\n"; - std::cout << "墙壁: " << sym.getWall() << "\n"; - std::cout << "空地: " << sym.getEmpty() << "\n"; - std::cout << "玩家: " << sym.getPlayer() << "\n"; - std::cout << "怪物: " << sym.getMonster() << "\n"; - std::cout << "陷阱: " << sym.getTrap() << "\n"; - std::cout << "出口: " << sym.getExit() << "\n"; - std::cout << "\n迷宫大小: " << m_config.getMazeWidth() << "x" << m_config.getMazeHeight() << "\n"; + std::cout << "符号配置:" << std::endl; + std::cout << "墙壁: " << sym.getWall() << std::endl; + std::cout << "空地: " << sym.getEmpty() << std::endl; + std::cout << "玩家: " << sym.getPlayer() << std::endl; + std::cout << "怪物: " << sym.getMonster() << std::endl; + std::cout << "陷阱: " << sym.getTrap() << std::endl; + std::cout << "出口: " << sym.getExit() << std::endl; + + std::cout << std::endl; + std::cout << "迷宫大小: " << m_config.getMazeWidth() << "x" << m_config.getMazeHeight() << std::endl; std::cout << "怪物AI难度: " << m_config.getDifficulty() << std::endl; + } \ No newline at end of file diff --git a/mazzGame/src/config.ini b/mazzGame/src/config.ini index bd5699d..b80feb1 100644 --- a/mazzGame/src/config.ini +++ b/mazzGame/src/config.ini @@ -1,10 +1,10 @@ -[Symbols] +[Symbols] Wall = # Player = @ Monster = M Trap = X Exit = E -Empty = +Empty = . [Difficulty] # 0: 随机移动,1: BFS偏向,2: A*精确追踪 diff --git a/mazzGame/src/main.cpp b/mazzGame/src/main.cpp index e658917..d8887d9 100644 --- a/mazzGame/src/main.cpp +++ b/mazzGame/src/main.cpp @@ -1,17 +1,19 @@ -#include "main.h" +#include "main.h" #include +#include int main() { SetConsoleOutputCP(CP_UTF8); SetConsoleCP(CP_UTF8); - std::cout << "Hello CMake." << std::endl; Game game; - game.loadConfig("F:\\mazzGame\\mazzGame\\src\\config.ini"); + game.loadConfig("config.ini"); + game.printConfig(); game.initMaze(); game.run(); + system("pause"); return 0; }