猫史档案馆


python 贪吃【龟】代码呈现

用户:泠尘晓泠尘晓查看:0 回复:1 评论:0 创建时间:2021-06-05T23:09:46


 

import os
import turtle
import random
import time
board = turtle.Pen()
board.pencolor("red")
game = turtle.Screen()
game.title('贪吃龟·by hermit_')
game.setup(2000,2000,0,0)
game.bgcolor('black')

tck = turtle.Turtle()
tck.shape('turtle')
tck.color('red')
tck.speed(1)
tck.penup()
tck.shapesize(1.5)

leaf = turtle.Turtle()
leaf_shape = ((0,0),(10,0),(10,10),(0,10),(0,0))
game.addshape('leaf',leaf_shape)
print(game.getshapes())
leaf.shape('leaf')
leaf.color('yellow')
leaf.speed(0)
leaf.penup()

def new_leaf():
    leaf.hideturtle()
    leaf.setx(random.randint(-180,180))
    leaf.sety(random.randint(-180,180))
    leaf.showturtle()

def out_window():
    (x,y) = tck.pos()
    outside = x < -750 or x > 750 or y < -450 or y > 450
    return outside

def game_over():
    tck.color('gray')
    leaf.color('gray')
    board.pencolor("gray")
    board.clear()
    board.write(f'得分:{score}',align='center',font=fonts)
def you ():
    tck.setheading(0)

def zuo ():
    tck.setheading(180)

def qian ():
    tck.setheading(90)

def hou ():
    tck.setheading(270)

game.onkeypress(you,"d")
game.onkeypress(zuo,"a")
game.onkeypress(qian,"w")
game.onkeypress(hou,"s")
game.listen()

sd = 1
new_leaf()
tck_len = 1
score = 0
board.goto(0,200)
fonts = ('隶书',25,'bold')
board.hideturtle()
board.clear()
board.write(f'得分:{score}',align='center',font=fonts)
while True:
    tck.shapesize(1.5)
    tck.forward(sd)
    if tck.distance(leaf) < 20:
        tck.shapesize(1.5)
        new_leaf()
        score = score+1
        sd = sd + 0.2
        board.clear()
        board.write(f'得分:{score}',align='center',font=fonts)
        tck.shapesize(1,tck_len,1)
    if out_window():
        game_over()
        break

 


回复

上一页1 页 / 共 1下一页
泠尘晓泠尘晓

话说

这玩意好像不能在海龟编辑器上运行

这里备上下载网址

center_image

注:如果有人试下海龟编辑器上可不可以用,跟我说一声

点赞0


评论