私はオリジナルのヘビのようなゲームを作ろうとしていて、「食べ物」をランダムな場所に移動したいのですが、クラスでそれをどうやって使うのかは分かりません。コードには他にもいくつかのエラーがありますが、今プレイヤーと食品に集中したいと思っています。Pythonカメでランダムモジュールを使用するにはどうすればいいですか?
import turtle
import random
"""-------"""
t=turtle.Turtle()
s=turtle.Screen()
cube=turtle.Turtle
"""------------"""
WIDTH, HEIGHT=300, 300
DISTANCE=5
"""--------------"""
s.setup(WIDTH,HEIGHT)
"""------------"""
t.width(1)
s.bgcolor("dark green")
"""-----------------"""
class Border():
def check():
x, y = t.position()
if not -WIDTH/2 < x < WIDTH/2 or not -HEIGHT/2 < y < HEIGHT/2:
t.undo() # undo error
t.speed(0)
t.left(180) # turn around
t.forward(10) # redo movement but in new direction
t.speed(3)
"""-------------"""
randint=random.randint
x=random.randint(cube.xcor, 0)
y=random.randint(0,cube.ycor)
"""---------------"""
class Food():
def block():
cube.color("red")
for i in range(4):
cube.goto(x, -x, y, -y)
cube.begin_fill()
cube.forward(20)
cube.right(90)
cube.end_fill()
"""---------------"""
class Player():
def move_up():
player=False
while player==False:
for i in range(1):
t.forward(DISTANCE)
t.clear()
def move_left():
t.speed(0)
t.left(90)
t.speed(3)
def move_right():
t.speed(0)
t.right(90)
t.speed(3)
"""------------"""
collistion_check=Border()
player1=Player()
s.onkey(Player.move_up,"up")
s.onkey(Player.move_left,"left")
s.onkey(Player.move_right,"right")
s.listen()