恢复match-case实现

This commit is contained in:
星外之神 2022-07-20 22:27:56 +08:00
parent 9fa2521396
commit f5b19894e6
2 changed files with 96 additions and 94 deletions

View File

@ -21,7 +21,7 @@
## 环境要求 ## 环境要求
* `Python` >= 3.7,最好使用最新版 * `Python` >= 3.10,最好使用最新版
* `Python-Pygame` >= 1.9,最好使用最新版 * `Python-Pygame` >= 1.9,最好使用最新版
## 开始游戏 ## 开始游戏
@ -79,7 +79,7 @@ python main.py
### 使用Nuitka进行构建 ### 使用Nuitka进行构建
编译依赖: 编译依赖:
- `Python` >= 3.7,最好使用最新版 - `Python` >= 3.10,最好使用最新版
- `Python-Pygame` >= 1.9,最好使用最新版 - `Python-Pygame` >= 1.9,最好使用最新版
- `Nuitka` - `Nuitka`
- `MinGW-w64`或其他C编译器 - `MinGW-w64`或其他C编译器

View File

@ -809,34 +809,34 @@ class Level(tool.State):
x, y = self.map.getMapGridPos(0, map_y) x, y = self.map.getMapGridPos(0, map_y)
# 新增的僵尸也需要在这里声明 # 新增的僵尸也需要在这里声明
if name == c.NORMAL_ZOMBIE: match name:
case c.NORMAL_ZOMBIE:
self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.CONEHEAD_ZOMBIE: case c.CONEHEAD_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ConeHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ConeHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.BUCKETHEAD_ZOMBIE: case c.BUCKETHEAD_ZOMBIE:
self.zombie_groups[map_y].add(zombie.BucketHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.BucketHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.FLAG_ZOMBIE: case c.FLAG_ZOMBIE:
self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, y, self.head_group)) self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, y, self.head_group))
elif name == c.NEWSPAPER_ZOMBIE: case c.NEWSPAPER_ZOMBIE:
self.zombie_groups[map_y].add(zombie.NewspaperZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.NewspaperZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.FOOTBALL_ZOMBIE: case c.FOOTBALL_ZOMBIE:
self.zombie_groups[map_y].add(zombie.FootballZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.FootballZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.DUCKY_TUBE_ZOMBIE: case c.DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.DuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.DuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.CONEHEAD_DUCKY_TUBE_ZOMBIE: case c.CONEHEAD_DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ConeHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ConeHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE: case c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE:
self.zombie_groups[map_y].add(zombie.BucketHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.BucketHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.SCREEN_DOOR_ZOMBIE: case c.SCREEN_DOOR_ZOMBIE:
self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
elif name == c.POLE_VAULTING_ZOMBIE: case c.POLE_VAULTING_ZOMBIE:
# 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可 # 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可
self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group))
elif name == c.ZOMBONI: case c.ZOMBONI:
# 冰车僵尸生成位置不同 # 冰车僵尸生成位置不同
self.zombie_groups[map_y].add(zombie.Zomboni(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.plant_groups[map_y], self.map, plant.IceFrozenPlot)) self.zombie_groups[map_y].add(zombie.Zomboni(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.plant_groups[map_y], self.map, plant.IceFrozenPlot))
elif name == c.SNORKELZOMBIE: case c.SNORKELZOMBIE:
# 潜水僵尸生成位置不同
self.zombie_groups[map_y].add(zombie.SnorkelZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group)) self.zombie_groups[map_y].add(zombie.SnorkelZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group))
# 能否种植物的判断: # 能否种植物的判断:
@ -861,71 +861,73 @@ class Level(tool.State):
map_x, map_y = self.map.getMapIndex(x, y) map_x, map_y = self.map.getMapIndex(x, y)
# 新植物也需要在这里声明 # 新植物也需要在这里声明
if self.plant_name == c.SUNFLOWER: match self.plant_name:
case c.SUNFLOWER:
new_plant = plant.SunFlower(x, y, self.sun_group) new_plant = plant.SunFlower(x, y, self.sun_group)
elif self.plant_name == c.PEASHOOTER: case c.PEASHOOTER:
new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y]) new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.SNOWPEASHOOTER: case c.SNOWPEASHOOTER:
new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y]) new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.WALLNUT: case c.WALLNUT:
new_plant = plant.WallNut(x, y) new_plant = plant.WallNut(x, y)
elif self.plant_name == c.CHERRYBOMB: case c.CHERRYBOMB:
new_plant = plant.CherryBomb(x, y) new_plant = plant.CherryBomb(x, y)
elif self.plant_name == c.THREEPEASHOOTER: case c.THREEPEASHOOTER:
new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type) new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type)
elif self.plant_name == c.REPEATERPEA: case c.REPEATERPEA:
new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y]) new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.CHOMPER: case c.CHOMPER:
new_plant = plant.Chomper(x, y) new_plant = plant.Chomper(x, y)
elif self.plant_name == c.PUFFSHROOM: case c.PUFFSHROOM:
new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.POTATOMINE: case c.POTATOMINE:
new_plant = plant.PotatoMine(x, y) new_plant = plant.PotatoMine(x, y)
elif self.plant_name == c.SQUASH: case c.SQUASH:
new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT]) new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT])
elif self.plant_name == c.SPIKEWEED: case c.SPIKEWEED:
new_plant = plant.Spikeweed(x, y) new_plant = plant.Spikeweed(x, y)
elif self.plant_name == c.JALAPENO: case c.JALAPENO:
new_plant = plant.Jalapeno(x, y) new_plant = plant.Jalapeno(x, y)
elif self.plant_name == c.SCAREDYSHROOM: case c.SCAREDYSHROOM:
new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.SUNSHROOM: case c.SUNSHROOM:
new_plant = plant.SunShroom(x, y, self.sun_group) new_plant = plant.SunShroom(x, y, self.sun_group)
elif self.plant_name == c.ICESHROOM: case c.ICESHROOM:
new_plant = plant.IceShroom(x, y) new_plant = plant.IceShroom(x, y)
elif self.plant_name == c.HYPNOSHROOM: case c.HYPNOSHROOM:
new_plant = plant.HypnoShroom(x, y) new_plant = plant.HypnoShroom(x, y)
elif self.plant_name == c.WALLNUTBOWLING: case c.WALLNUTBOWLING:
new_plant = plant.WallNutBowling(x, y, map_y, self) new_plant = plant.WallNutBowling(x, y, map_y, self)
elif self.plant_name == c.REDWALLNUTBOWLING: case c.REDWALLNUTBOWLING:
new_plant = plant.RedWallNutBowling(x, y) new_plant = plant.RedWallNutBowling(x, y)
elif self.plant_name == c.LILYPAD: case c.LILYPAD:
new_plant = plant.LilyPad(x, y) new_plant = plant.LilyPad(x, y)
elif self.plant_name == c.TORCHWOOD: case c.TORCHWOOD:
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y]) new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.STARFRUIT: case c.STARFRUIT:
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self) new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self)
elif self.plant_name == c.COFFEEBEAN: case c.COFFEEBEAN:
new_plant = plant.CoffeeBean(x, y, self.plant_groups[map_y], self.map.map[map_y][map_x], self.map, map_x) new_plant = plant.CoffeeBean(x, y, self.plant_groups[map_y], self.map.map[map_y][map_x], self.map, map_x)
elif self.plant_name == c.SEASHROOM: case c.SEASHROOM:
new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y]) new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y])
elif self.plant_name == c.TALLNUT: case c.TALLNUT:
new_plant = plant.TallNut(x, y) new_plant = plant.TallNut(x, y)
elif self.plant_name == c.TANGLEKLEP: case c.TANGLEKLEP:
new_plant = plant.TangleKlep(x, y) new_plant = plant.TangleKlep(x, y)
elif self.plant_name == c.DOOMSHROOM: case c.DOOMSHROOM:
if self.map.gridHeightSize == c.GRID_Y_SIZE: if self.map.gridHeightSize == c.GRID_Y_SIZE:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2) new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2)
else: else:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3) new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3)
elif self.plant_name == c.GRAVEBUSTER: case c.GRAVEBUSTER:
new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x) new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x)
elif self.plant_name == c.FUMESHROOM: case c.FUMESHROOM:
new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y]) new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y])
elif self.plant_name == c.GARLIC: case c.GARLIC:
new_plant = plant.Garlic(x, y) new_plant = plant.Garlic(x, y)
if new_plant.can_sleep and self.background_type in c.DAYTIME_BACKGROUNDS: if new_plant.can_sleep and self.background_type in c.DAYTIME_BACKGROUNDS:
new_plant.setSleep() new_plant.setSleep()
mushroomSleep = True mushroomSleep = True