Python程序 Catmouseme
来源:互联网 发布:centos配置内网ip 编辑:程序博客网 时间:2024/06/02 00:28
import turtleimport timeboxsize=200caught=Falsescore=0#functions that are called on keypressesdef up(): mouse.forward(10) checkbound()def left(): mouse.left(45)def right(): mouse.right(45)def down(): mouse.backward(10) checkbound()def quitTurtles(): window.bye()#stop the mouse from leaving windowdef checkbound(): global boxsize if mouse.xcor() > boxsize: mouse.goto(boxsize,mouse.ycor()) if mouse.xcor() < -boxsize: mouse.goto(-boxsize,mouse.ycor()) if mouse.ycor() > boxsize: mouse.goto(mouse.xcor(),boxsize) if mouse.ycor() < -boxsize: mouse.goto(mouse.xcor(),-boxsize)#setup screenwindow = turtle.Screen()mouse = turtle.Turtle()cat= turtle.Turtle()me=turtle.Turtle()mouse.goto(100,100)me.goto(-100,-100)#add key listenerswindow.onkeypress(up,"Up")window.onkeypress(left,"Left")window.onkeypress(right,"Right")window.onkeypress(down,"Down")window.onkeypress(quitTurtles, "Escape")difficulty=window.numinput("Difficulty", "Enter a difficulty from 1 - 5", minval=1, maxval=5)window.listen()#mainloop#note how it changes with difficultywhile not caught: cat.setheading(cat.towards(mouse)) cat.forward(8+difficulty) me.setheading(me.towards(cat)) me.forward(10+difficulty) score = score+1 if cat.distance(mouse)<5: caught=True elif me.distance(cat)<5: caught=True time.sleep(0.2-(0.01*difficulty))window.textinput("GG","Welldone. You scored:" + str(score*difficulty))window.bye()
阅读全文
0 0
- Python程序 Catmouseme
- python程序
- Python - 打包python程序
- Python程序调用另一个Python程序
- Python-2 Python小程序
- 【Python】python调用C程序
- python程序编译
- 第一个Python程序
- 常用Python程序
- Python的爬虫程序
- 第一个Python程序
- 第一个Python程序
- 第一个python 程序
- 第一个Python程序
- Python程序调试(转)
- python程序返回值
- 终止python程序
- 第一个python程序
- (76)蓝图中的转换
- ORA-01704: 文字字符串过长成功解决
- 数据库面试知识
- TweenJS 一个简单但强大的渐变界面
- setjmp.h学习笔记
- Python程序 Catmouseme
- #POJ2823#Sliding Window (单调队列基础)
- JavaScript原型的缺点及改进
- java关键字
- 搭建线程池需要考虑的因素
- 关于synchronized 特别需要强调的一个点!!
- 一共有20级楼梯,每次可以上1级或2级,登上第20级一共有多少种上法
- 基于STM32wifi小车制作(二)-电源设计
- jsp forward指令