Compare commits

..

3 Commits

Author SHA1 Message Date
silksnow136 d5531cb2fc hard q31: define MapGrid for map 2026-10-07 00:55:23 +08:00
silksnow136 a9d62a1ff5 docs: update project and q30 READMEs 2026-10-07 00:17:30 +08:00
silksnow136 266d23e620 hard q30: add solution png and correct code 2026-10-07 00:02:53 +08:00
5 changed files with 68 additions and 3 deletions
+3
View File
@@ -0,0 +1,3 @@
# 26国庆招新综合考核试题实践题部分
## 代码思路目录
- [q30 README](q30/README.md)
+4
View File
@@ -0,0 +1,4 @@
### 困难部分第 30 题
此题考查继承与多态,我只需要按题目去定义即可。为了方便在列表中创建实例,加了`__init__`方法。Python 定义抽象类需要来自模块 abc 的装饰器 @abstractmethod,能够让 Pylance 不发出协变不兼容警告,此处为了简便没有使用
[回到主项目 README](../README.md)
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+11 -3
View File
@@ -3,12 +3,20 @@ class Shape:
return 0
class Circle(Shape):
def __init__(self, r):
self.r = r
def area(self):
return 3.14 * r * r
return 3.14 * self.r * self.r
class Square(Shape):
def __init__(self, side):
self.side = side
def area(self):
return side * side
return self.side * self.side
if __name__ == '__main__':
shapes = [Circle(3), Square(5)]
for s in shapes:
print(s.area())
+50
View File
@@ -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;
};