所以我有 3 個老板,每個老板都有圖片,但我不知道如何讓烏龜隨機選擇要使用的圖片。我應該制作另一個串列來存盤影像,然后讓它隨機挑選一只烏龜嗎?我應該在烏龜隱藏的時候立即改變它還是應該在boss戰之前讓它改變?
import turtle as trtl
import random as rd
#these are all the images
fight1_image = "pixel.gif"
bossfight_cow = "boss_cow.gif"
boss_shape_1 = "1.gif"
boss_shape_2 = "acended.gif"
cow_gif = "cow.gif"
cow_helper1 = "cat_helper.gif"
#the 3 variables are the bosses i want to randomize all 3 with the #images below as variables
boss_list = []
heretic_swordsmen = trtl.Turtle()
priest = trtl.Turtle()
impaler = trtl.Turtle()
boss_list = [heretic_swordsmen,priest,impaler]
def bossfight1():
play.hideturtle()
#original cords are (0,-200)
heretic_swordsmen.penup()
heretic_swordsmen.goto(0,100)
heretic_swordsmen.showturtle()
#bosscow is just the main character ignore it
bosscow.penup()
bosscow.goto(0,-100)
bosscow.showturtle()
uj5u.com熱心網友回復:
首先在您的代碼頂部添加:
trtl.register_shape("pixel.gif")
trtl.register_shape("boss_cow.gif")
trtl.register_shape("1.gif")
確保對您要使用的每個影像都執行此操作,否則您無法使用影像。那么你可以很容易地說:
myboss = rd.choice(boss_list)
這給了你老板形象。那么你可以想為你的老板養一只烏龜
boss_object = trtl.Turtle()
然后您可以將其形狀設定為您的影像:
boss_object.shape(myboss)
你完成了!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/454975.html
