修复用str作key导致keyerror的问题

This commit is contained in:
星外之神 2022-08-01 22:30:25 +08:00
parent ac3f7f56d7
commit 2862aa28b5
2 changed files with 16 additions and 16 deletions

View File

@ -93,7 +93,7 @@ class Card():
image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height)) image.blit(frozen_image, (0,0), (0, 0, self.rect.w, frozen_height))
image.blit(self.orig_image, (0,frozen_height), image.blit(self.orig_image, (0,frozen_height),
(0, frozen_height, self.rect.w, self.rect.h - frozen_height)) (0, frozen_height, self.rect.w, self.rect.h - frozen_height))
elif self.sun_cost > sun_value: #disable status if self.sun_cost > sun_value: #disable status
image = self.orig_image.copy() image = self.orig_image.copy()
image.set_alpha(192) image.set_alpha(192)
elif self.clicked: elif self.clicked:

View File

@ -102,7 +102,7 @@ class Level(tool.State):
# 可以考虑将波刷新和一波中的僵尸生成分开 # 可以考虑将波刷新和一波中的僵尸生成分开
# useableZombie是指可用的僵尸种类的元组 # useableZombie是指可用的僵尸种类的元组
# inevitableZombie指在本轮必然出现的僵尸输入形式为字典: {波数1:(僵尸1, 僵尸2……), 波数2:(僵尸1, 僵尸2……)……} # inevitableZombie指在本轮必然出现的僵尸输入形式为字典: {波数1:(僵尸1, 僵尸2……), 波数2:(僵尸1, 僵尸2……)……}
def createWaves(self, useableZombies, numFlags, survivalRounds=0, inevitableZombieDict=None): def createWaves(self, useableZombies, numFlags, survivalRounds=0, inevitable_zombie_dict=None):
waves = [] waves = []
@ -130,10 +130,10 @@ class Level(tool.State):
if (self.bar_type != c.CHOOSEBAR_STATIC): if (self.bar_type != c.CHOOSEBAR_STATIC):
volume += 2 volume += 2
if inevitableZombieDict and (wave in inevitableZombieDict): if inevitable_zombie_dict and (wave in inevitable_zombie_dict):
for newZombie in inevitableZombieDict[str(wave)]: for new_zombie in inevitable_zombie_dict[wave]:
zombieList.append(newZombie) zombieList.append(new_zombie)
volume -= c.CREATE_ZOMBIE_DICT[newZombie][0] volume -= c.CREATE_ZOMBIE_DICT[new_zombie][0]
if volume < 0: if volume < 0:
logger.warning(f"{wave}波中手动设置的僵尸级别总数超过上限!") logger.warning(f"{wave}波中手动设置的僵尸级别总数超过上限!")
@ -141,23 +141,23 @@ class Level(tool.State):
minCost = c.CREATE_ZOMBIE_DICT[min(useableZombies, key=lambda x:c.CREATE_ZOMBIE_DICT[x][0])][0] minCost = c.CREATE_ZOMBIE_DICT[min(useableZombies, key=lambda x:c.CREATE_ZOMBIE_DICT[x][0])][0]
while (volume >= minCost) and (len(zombieList) < 50): while (volume >= minCost) and (len(zombieList) < 50):
newZombie = random.choices(useableZombies, weights)[0] new_zombie = random.choices(useableZombies, weights)[0]
# 普通僵尸、路障僵尸、铁桶僵尸有概率生成水中变种 # 普通僵尸、路障僵尸、铁桶僵尸有概率生成水中变种
if self.background_type in c.POOL_EQUIPPED_BACKGROUNDS: if self.background_type in c.POOL_EQUIPPED_BACKGROUNDS:
# 有泳池第一轮的第四波设定上生成水生僵尸 # 有泳池第一轮的第四波设定上生成水生僵尸
if survivalRounds == 0 and wave == 4: if survivalRounds == 0 and wave == 4:
if newZombie in c.CONVERT_ZOMBIE_IN_POOL: if new_zombie in c.CONVERT_ZOMBIE_IN_POOL:
newZombie = c.CONVERT_ZOMBIE_IN_POOL[newZombie] new_zombie = c.CONVERT_ZOMBIE_IN_POOL[new_zombie]
elif survivalRounds > 0 or wave > 4: elif survivalRounds > 0 or wave > 4:
if random.randint(1, 3) == 1: # 1/3概率水上暂时人为设定 if random.randint(1, 3) == 1: # 1/3概率水上暂时人为设定
if newZombie in c.CONVERT_ZOMBIE_IN_POOL: if new_zombie in c.CONVERT_ZOMBIE_IN_POOL:
newZombie = c.CONVERT_ZOMBIE_IN_POOL[newZombie] new_zombie = c.CONVERT_ZOMBIE_IN_POOL[new_zombie]
# 首先几轮不出水生僵尸 # 首先几轮不出水生僵尸
elif newZombie in c.WATER_ZOMBIE: elif new_zombie in c.WATER_ZOMBIE:
continue continue
if c.CREATE_ZOMBIE_DICT[newZombie][0] <= volume: if c.CREATE_ZOMBIE_DICT[new_zombie][0] <= volume:
zombieList.append(newZombie) zombieList.append(new_zombie)
volume -= c.CREATE_ZOMBIE_DICT[newZombie][0] volume -= c.CREATE_ZOMBIE_DICT[new_zombie][0]
waves.append(zombieList) waves.append(zombieList)
# print(wave, zombieList, len(zombieList)) # print(wave, zombieList, len(zombieList))
@ -424,7 +424,7 @@ class Level(tool.State):
self.createWaves( useableZombies=self.map_data[c.INCLUDED_ZOMBIES], self.createWaves( useableZombies=self.map_data[c.INCLUDED_ZOMBIES],
numFlags=self.map_data[c.NUM_FLAGS], numFlags=self.map_data[c.NUM_FLAGS],
survivalRounds=0, survivalRounds=0,
inevitableZombieDict=self.map_data[c.INEVITABLE_ZOMBIE_DICT]) inevitable_zombie_dict=self.map_data[c.INEVITABLE_ZOMBIE_DICT])
else: else:
self.createWaves( useableZombies=self.map_data[c.INCLUDED_ZOMBIES], self.createWaves( useableZombies=self.map_data[c.INCLUDED_ZOMBIES],
numFlags=self.map_data[c.NUM_FLAGS], numFlags=self.map_data[c.NUM_FLAGS],