增加传送带关卡卡片生成权重机制

This commit is contained in:
wszqkzqk 2022-07-23 09:38:59 +08:00
parent f5b19894e6
commit 29c8824d1f
6 changed files with 43 additions and 41 deletions

View File

@ -6,7 +6,7 @@
"included_zombies":["Zombie", "ConeheadZombie", "BucketheadZombie", "NewspaperZombie", "PoleVaultingZombie"],
"num_flags":4,
"inevitable_zombie_list":{"20":["BucketheadZombie"]},
"card_pool":[ "WallNutBowling",
"RedWallNutBowling"
]
"card_pool":{ "WallNutBowling":300,
"RedWallNutBowling":100
}
}

View File

@ -6,12 +6,12 @@
"num_flags":3,
"included_zombies":["Zombie", "ConeheadZombie", "BucketheadZombie", "PoleVaultingZombie"],
"inevitable_zombie_list":{"20":["BucketheadZombie"]},
"card_pool":[ "Peashooter",
"SnowPea",
"WallNut",
"CherryBomb",
"RepeaterPea",
"Chomper",
"PotatoMine"
]
"card_pool":{ "Peashooter":200,
"SnowPea":200,
"WallNut":100,
"CherryBomb":100,
"RepeaterPea":200,
"Chomper":100,
"PotatoMine":100
}
}

View File

@ -8,12 +8,12 @@
"BucketheadZombie", "NewspaperZombie",
"FootballZombie", "ScreenDoorZombie"],
"inevitable_zombie_list":{"30":["FootballZombie"]},
"card_pool":[ "PuffShroom",
"ScaredyShroom",
"IceShroom",
"HypnoShroom",
"DoomShroom",
"GraveBuster",
"FumeShroom"
]
"card_pool":{ "PuffShroom":200,
"ScaredyShroom":100,
"IceShroom":100,
"HypnoShroom":100,
"DoomShroom":100,
"GraveBuster":100,
"FumeShroom":200
}
}

View File

@ -8,13 +8,13 @@
"BucketheadZombie", "SnorkelZombie",
"Zomboni"],
"inevitable_zombie_list":{"30":["BucketheadZombie"]},
"card_pool":[ "Lilypad", "Lilypad",
"TorchWood",
"TallNut",
"TangleKlep",
"Spikeweed",
"Squash",
"Jalapeno",
"Threepeater", "Threepeater", "Threepeater", "Threepeater", "Threepeater"
]
"card_pool":{ "Lilypad":200,
"TorchWood":100,
"TallNut":100,
"TangleKlep":100,
"Spikeweed":100,
"Squash":100,
"Jalapeno":100,
"Threepeater":400
}
}

View File

@ -1,5 +1,6 @@
import os
import random
from select import select
import pygame as pg
from .. import tool
from .. import constants as c
@ -23,12 +24,9 @@ def getSunValueImage(sun_value):
return image
def getCardPool(data):
card_pool = []
for card in data:
for i,name in enumerate(c.PLANT_CARD_INFO):
if name[c.PLANT_NAME_INDEX] == card:
card_pool.append(i)
break
card_pool = {}
for cardName in data:
card_pool[c.PLANT_CARD_INFO[c.PLANT_CARD_INDEX[cardName]]] = data[cardName]
return card_pool
class Card():
@ -40,7 +38,7 @@ class Card():
self.index = index
self.sun_cost = c.PLANT_CARD_INFO[index][c.SUN_INDEX]
self.frozen_time = c.PLANT_CARD_INFO[index][c.FROZEN_INDEX]
self.frozen_time = c.PLANT_CARD_INFO[index][c.FROZEN_TIME_INDEX]
self.frozen_timer = -self.frozen_time
self.refresh_timer = 0
self.select = True
@ -382,6 +380,8 @@ class MoveBar():
self.card_start_x = self.rect.x + 8
self.card_end_x = self.rect.right - 5
self.card_pool = card_pool
self.card_pool_name = tuple(self.card_pool.keys())
self.card_pool_weight = tuple(self.card_pool.values())
self.card_list = []
self.create_timer = -c.MOVEBAR_CARD_FRESH_TIME
@ -397,11 +397,8 @@ class MoveBar():
return False
x = self.card_end_x
y = 6
index = random.randint(0, len(self.card_pool) - 1)
card_index = self.card_pool[index]
card_name = c.PLANT_CARD_INFO[card_index][c.CARD_INDEX] + '_move'
plant_name = c.PLANT_CARD_INFO[card_index][c.PLANT_NAME_INDEX]
self.card_list.append(MoveCard(x, y, card_name, plant_name))
selected_card = random.choices(self.card_pool_name, self.card_pool_weight)[0]
self.card_list.append(MoveCard(x, y, selected_card[c.CARD_INDEX] + "_move", selected_card[c.PLANT_NAME_INDEX]))
return True
def update(self, current_time):

View File

@ -198,7 +198,7 @@ BAR_CARD_X_INTERNAL = 51
PLANT_NAME_INDEX = 0
CARD_INDEX = 1
SUN_INDEX = 2
FROZEN_INDEX = 3
FROZEN_TIME_INDEX = 3
# 传送带模式中的刷新间隔和移动速率
MOVEBAR_CARD_FRESH_TIME = 6000
@ -503,6 +503,11 @@ PLANT_CARD_INFO = (# 元组 (植物名称, 卡片名称, 阳光, 冷却时间)
0),
)
# 卡片中的植物名称与索引序号的对应关系,指定名称以得到索引值
PLANT_CARD_INDEX={}
for i, item in enumerate(PLANT_CARD_INFO):
PLANT_CARD_INDEX[item[PLANT_NAME_INDEX]] = i
# 指定了哪些卡可选(排除坚果保龄球特殊植物)
CARDS_TO_CHOOSE = range(len(PLANT_CARD_INFO) - 2)