hard q31: define MapGrid for map
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
#include <string>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
|
||||
enum class TileType{
|
||||
EMPTY,
|
||||
WALL,
|
||||
NOMAL_BEAN,
|
||||
ENERGY_BEAN,
|
||||
PACMAN,
|
||||
GHOST
|
||||
};
|
||||
|
||||
struct Tile{
|
||||
TileType type;
|
||||
std::unordered_map<TileType, std::string> tileTypeToPlaceholder{
|
||||
{TileType::EMPTY, " "},
|
||||
{TileType::WALL, "#"},
|
||||
{TileType::NOMAL_BEAN, "."},
|
||||
{TileType::ENERGY_BEAN, "o"},
|
||||
{TileType::PACMAN, "P"},
|
||||
{TileType::GHOST, "G"}
|
||||
};
|
||||
|
||||
Tile() = default;
|
||||
Tile(TileType t) : type(t) {}
|
||||
};
|
||||
|
||||
class MapGrid{
|
||||
public:
|
||||
MapGrid() = default;
|
||||
|
||||
MapGrid(const std::string& mapFilePath);
|
||||
|
||||
void loadMap(const std::string& mapFilePath);;
|
||||
|
||||
std::unique_ptr<std::pair<int, int>> getSize() const;
|
||||
|
||||
bool isValidPosition(int x, int y) const;
|
||||
|
||||
void setTile(int x, int y, TileType type, const std::string& placeholder);
|
||||
|
||||
void renderMap() const;
|
||||
|
||||
void move(); // 应该是 W A S D 移动
|
||||
private:
|
||||
std::vector<std::vector<Tile>> grid;
|
||||
std::unique_ptr<std::pair<int, int>> size;
|
||||
};
|
||||
Reference in New Issue
Block a user