1 回答

TA貢獻1818條經(jīng)驗 獲得超3個贊
我不知道我是否理解你的問題,但我在代碼中看到了一個問題
你應(yīng)該設(shè)置變量
level = "A"
并改變它
if self.player.health < 20:
level = "A"
if self.player.health > 20 and self.player.health < 40:
level = "B"
elif self.player.health > 40:
level = "C"
并在顯示顏色時使用它
if level in ("A", "C"):
if BOXA[hit_count] == GRE:
text = font1.render('green', 1, (GREEN))
elif BOXA[hit_count] == BLU:
text = font1.render('blue', 1, (CYAN))
else:
elif BOXB[hit_count] == YEL:
text = font1.render('yellow', 1, (YELLOW))
elif BOXB[hit_count] == RE:
text = font1.render('red', 1, (RED))
沒有這個,它總是檢查第一個列表BOXA,它總是找到它用來顯示文本的顏色,它從不檢查BOXB
或者你應(yīng)該使用
box = BOXA
并改變它
if self.player.health < 20:
box = BOXA
if self.player.health > 20 and self.player.health < 40:
box = BOXB
elif self.player.health > 40:
box = BOXA
并使用它
if box[hit_count] == GRE:
text = font1.render('green', 1, (GREEN))
elif box[hit_count] == BLU:
text = font1.render('blue', 1, (CYAN))
elif box[hit_count] == YEL:
text = font1.render('yellow', 1, (YELLOW))
elif box[hit_count] == RE:
text = font1.render('red', 1, (RED))
順便說一句:您可以使用顏色創(chuàng)建列表或字典
all_colors = {
GRE: (GREEN, "green")
BLU: (CYAN, "blue")
...
}
并使用此字典而不是選擇顏色if/elif
color, name = all_colors[ box[hit_count] ]
text = font1.render(name, 1, color)
添加回答
舉報