第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我的代碼不能在列表之間來回切換?

為什么我的代碼不能在列表之間來回切換?

白板的微信 2022-05-24 10:54:18
我的游戲中有兩個列表,我想在我的方法中切換。我正在開發(fā)一款游戲,在某個時間點,如果一個盒子壞了,屏幕上會打印一種顏色——這些顏色以特定的順序顯示,并在一個列表中。有 3 個級別:A、B 和 C。我進行了此設(shè)置,以便級別切換玩家的健康達到某個點。我希望每次新級別開始時切換列表。因此,如果 A 級從列表 A 開始,我希望 B 級切換到列表 B,而 C 級切換回列表 A。我不知道為什么我的代碼不起作用。我有取決于玩家健康狀況的“if”語句,但沒有發(fā)生切換。在此代碼框被“碎片”打破。BoxA 和 BoxB 是列表。我想會發(fā)生的是,當玩家的生命值低于 20 時,會使用 BoxA。當玩家的生命值高于 20 時,應(yīng)該使用 Box B。當生命值高于 40 時,應(yīng)再次使用 BoxA。    hits = pg.sprite.groupcollide(self.boxs, self.shards, False, True)    hit_count = 0    for hit in hits:        font1 = pg.font.SysFont('comicsans', 100)        if BOXA[hit_count] == GRE:            text = font1.render('green', 1, (GREEN))            #self.effects_sounds['lose_sound'].play()        elif BOXA[hit_count] == BLU:            text = font1.render('blue', 1, (CYAN))        elif BOXB[hit_count] == YEL:            text = font1.render('yellow', 1, (YELLOW))        elif BOXB[hit_count] == RE:            text = font1.render('red', 1, (RED))            #self.effects_sounds['jackpot_sound'].play()        self.screen.blit(text, (250 -(text.get_width()/2),200))        pg.display.update()        i = 0        while i < 100:            pg.time.delay(10)            i += 1            for event in pg.event.get():                if event.type == pg.QUIT:                    i = 301                    pg.quit()        hit.health -= SHARD_DAMAGE        if self.player.health < 20:            self.player.health += 0            hit.health += BOXA.popleft()            hit_count += 1            print('lvl_A')        if self.player.health > 20 and self.player.health < 40:            hit.health += BOXB.popleft()            self.player.health += 0            print('lvl_B')        elif self.player.health > 40:            self.player.health += 0            hit.health += BOXA.popleft()            print('lvl_C')這些列表在我導(dǎo)入到主代碼中的單獨文件中定義。這是一個示例列表:BOXA =  deque([BLU, GRE, BLU, BLU, GRE, GRE, GRE, BLU, GRE, BLU, BLU, BLU])BOXB = deque([YEL, YEL, RE, YEL, RE, RE, RE, YEL])#BLU = 1#GRE = 2#YEL = 7#RE = 4我真的不確定為什么它沒有切換,所以任何見解都將不勝感激!
查看完整描述

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)



查看完整回答
反對 回復(fù) 2022-05-24
  • 1 回答
  • 0 關(guān)注
  • 101 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號