恢复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,35 +809,35 @@ 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:
self.zombie_groups[map_y].add(zombie.NormalZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.NORMAL_ZOMBIE:
elif name == c.CONEHEAD_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.ConeHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.CONEHEAD_ZOMBIE:
elif name == c.BUCKETHEAD_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.BucketHeadZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.BUCKETHEAD_ZOMBIE:
elif name == c.FLAG_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.FlagZombie(c.ZOMBIE_START_X, y, self.head_group)) case c.FLAG_ZOMBIE:
elif name == c.NEWSPAPER_ZOMBIE: self.zombie_groups[map_y].add(zombie.FlagZombie(c.ZOMBIE_START_X, 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)) case c.NEWSPAPER_ZOMBIE:
elif name == c.FOOTBALL_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.FootballZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.FOOTBALL_ZOMBIE:
elif name == c.DUCKY_TUBE_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.DuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.DUCKY_TUBE_ZOMBIE:
elif name == c.CONEHEAD_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.ConeHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.CONEHEAD_DUCKY_TUBE_ZOMBIE:
elif name == c.BUCKETHEAD_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.BucketHeadDuckyTubeZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.BUCKETHEAD_DUCKY_TUBE_ZOMBIE:
elif name == c.SCREEN_DOOR_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.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group)) case c.SCREEN_DOOR_ZOMBIE:
elif name == c.POLE_VAULTING_ZOMBIE: self.zombie_groups[map_y].add(zombie.ScreenDoorZombie(c.ZOMBIE_START_X + random.randint(-20, 20) + hugeWaveMove, y, self.head_group))
# 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可 case c.POLE_VAULTING_ZOMBIE:
self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group)) # 本来撑杆跳生成位置不同对齐左端可认为修正了一部分看作移动了70只需要相对修改即可
elif name == c.ZOMBONI: self.zombie_groups[map_y].add(zombie.PoleVaultingZombie(c.ZOMBIE_START_X + random.randint(0, 10) + hugeWaveMove, y, self.head_group))
# 冰车僵尸生成位置不同 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)) # 冰车僵尸生成位置不同
elif name == c.SNORKELZOMBIE: 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))
# 潜水僵尸生成位置不同 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))
# 能否种植物的判断: # 能否种植物的判断:
# 先判断位置是否合法 isValid(map_x, map_y) # 先判断位置是否合法 isValid(map_x, map_y)
@ -861,69 +861,71 @@ 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:
new_plant = plant.SunFlower(x, y, self.sun_group) case c.SUNFLOWER:
elif self.plant_name == c.PEASHOOTER: new_plant = plant.SunFlower(x, y, self.sun_group)
new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y]) case c.PEASHOOTER:
elif self.plant_name == c.SNOWPEASHOOTER: new_plant = plant.PeaShooter(x, y, self.bullet_groups[map_y])
new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y]) case c.SNOWPEASHOOTER:
elif self.plant_name == c.WALLNUT: new_plant = plant.SnowPeaShooter(x, y, self.bullet_groups[map_y])
new_plant = plant.WallNut(x, y) case c.WALLNUT:
elif self.plant_name == c.CHERRYBOMB: new_plant = plant.WallNut(x, y)
new_plant = plant.CherryBomb(x, y) case c.CHERRYBOMB:
elif self.plant_name == c.THREEPEASHOOTER: new_plant = plant.CherryBomb(x, y)
new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type) case c.THREEPEASHOOTER:
elif self.plant_name == c.REPEATERPEA: new_plant = plant.ThreePeaShooter(x, y, self.bullet_groups, map_y, self.map.background_type)
new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y]) case c.REPEATERPEA:
elif self.plant_name == c.CHOMPER: new_plant = plant.RepeaterPea(x, y, self.bullet_groups[map_y])
new_plant = plant.Chomper(x, y) case c.CHOMPER:
elif self.plant_name == c.PUFFSHROOM: new_plant = plant.Chomper(x, y)
new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y]) case c.PUFFSHROOM:
elif self.plant_name == c.POTATOMINE: new_plant = plant.PuffShroom(x, y, self.bullet_groups[map_y])
new_plant = plant.PotatoMine(x, y) case c.POTATOMINE:
elif self.plant_name == c.SQUASH: new_plant = plant.PotatoMine(x, y)
new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT]) case c.SQUASH:
elif self.plant_name == c.SPIKEWEED: new_plant = plant.Squash(x, y, self.map.map[map_y][map_x][c.MAP_PLANT])
new_plant = plant.Spikeweed(x, y) case c.SPIKEWEED:
elif self.plant_name == c.JALAPENO: new_plant = plant.Spikeweed(x, y)
new_plant = plant.Jalapeno(x, y) case c.JALAPENO:
elif self.plant_name == c.SCAREDYSHROOM: new_plant = plant.Jalapeno(x, y)
new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y]) case c.SCAREDYSHROOM:
elif self.plant_name == c.SUNSHROOM: new_plant = plant.ScaredyShroom(x, y, self.bullet_groups[map_y])
new_plant = plant.SunShroom(x, y, self.sun_group) case c.SUNSHROOM:
elif self.plant_name == c.ICESHROOM: new_plant = plant.SunShroom(x, y, self.sun_group)
new_plant = plant.IceShroom(x, y) case c.ICESHROOM:
elif self.plant_name == c.HYPNOSHROOM: new_plant = plant.IceShroom(x, y)
new_plant = plant.HypnoShroom(x, y) case c.HYPNOSHROOM:
elif self.plant_name == c.WALLNUTBOWLING: new_plant = plant.HypnoShroom(x, y)
new_plant = plant.WallNutBowling(x, y, map_y, self) case c.WALLNUTBOWLING:
elif self.plant_name == c.REDWALLNUTBOWLING: new_plant = plant.WallNutBowling(x, y, map_y, self)
new_plant = plant.RedWallNutBowling(x, y) case c.REDWALLNUTBOWLING:
elif self.plant_name == c.LILYPAD: new_plant = plant.RedWallNutBowling(x, y)
new_plant = plant.LilyPad(x, y) case c.LILYPAD:
elif self.plant_name == c.TORCHWOOD: new_plant = plant.LilyPad(x, y)
new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y]) case c.TORCHWOOD:
elif self.plant_name == c.STARFRUIT: new_plant = plant.TorchWood(x, y, self.bullet_groups[map_y])
new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self) case c.STARFRUIT:
elif self.plant_name == c.COFFEEBEAN: new_plant = plant.StarFruit(x, y, self.bullet_groups[map_y], self)
new_plant = plant.CoffeeBean(x, y, self.plant_groups[map_y], self.map.map[map_y][map_x], self.map, map_x) case c.COFFEEBEAN:
elif self.plant_name == c.SEASHROOM: 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.SeaShroom(x, y, self.bullet_groups[map_y]) case c.SEASHROOM:
elif self.plant_name == c.TALLNUT: new_plant = plant.SeaShroom(x, y, self.bullet_groups[map_y])
new_plant = plant.TallNut(x, y) case c.TALLNUT:
elif self.plant_name == c.TANGLEKLEP: new_plant = plant.TallNut(x, y)
new_plant = plant.TangleKlep(x, y) case c.TANGLEKLEP:
elif self.plant_name == c.DOOMSHROOM: new_plant = plant.TangleKlep(x, y)
if self.map.gridHeightSize == c.GRID_Y_SIZE: case c.DOOMSHROOM:
new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=2) if self.map.gridHeightSize == c.GRID_Y_SIZE:
else: 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=3) else:
elif self.plant_name == c.GRAVEBUSTER: new_plant = plant.DoomShroom(x, y, self.map.map[map_y][map_x][c.MAP_PLANT], explode_y_range=3)
new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x) case c.GRAVEBUSTER:
elif self.plant_name == c.FUMESHROOM: new_plant = plant.GraveBuster(x, y, self.plant_groups[map_y], self.map, map_x)
new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y]) case c.FUMESHROOM:
elif self.plant_name == c.GARLIC: new_plant = plant.FumeShroom(x, y, self.bullet_groups[map_y], self.zombie_groups[map_y])
new_plant = plant.Garlic(x, y) case c.GARLIC:
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: