5 Star 8 Fork 6

合肥吃货食光/Python有趣的代码

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Free Games - Simon Says 小游戏.py 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
合肥吃货食光 提交于 2019-07-23 02:01 . Free Games 游戏系列
"""Simon Says
Exercises
1. Speed up tile flash rate.
2. Add more tiles.
"""
from random import choice
from time import sleep
from turtle import *
from freegames import floor, square, vector
pattern = []
guesses = []
tiles = {
vector(0, 0): ('red', 'dark red'),
vector(0, -200): ('blue', 'dark blue'),
vector(-200, 0): ('green', 'dark green'),
vector(-200, -200): ('yellow', 'khaki'),
}
def grid():
"Draw grid of tiles."
square(0, 0, 200, 'dark red')
square(0, -200, 200, 'dark blue')
square(-200, 0, 200, 'dark green')
square(-200, -200, 200, 'khaki')
update()
def flash(tile):
"Flash tile in grid."
glow, dark = tiles[tile]
square(tile.x, tile.y, 200, glow)
update()
sleep(0.5)
square(tile.x, tile.y, 200, dark)
update()
sleep(0.5)
def grow():
"Grow pattern and flash tiles."
tile = choice(list(tiles))
pattern.append(tile)
for tile in pattern:
flash(tile)
print('Pattern length:', len(pattern))
guesses.clear()
def tap(x, y):
"Respond to screen tap."
onscreenclick(None)
x = floor(x, 200)
y = floor(y, 200)
tile = vector(x, y)
index = len(guesses)
if tile != pattern[index]:
exit()
guesses.append(tile)
flash(tile)
if len(guesses) == len(pattern):
grow()
onscreenclick(tap)
def start(x, y):
"Start game."
grow()
onscreenclick(tap)
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
grid()
onscreenclick(start)
done()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/simon4055/fun.git
git@gitee.com:simon4055/fun.git
simon4055
fun
Python有趣的代码
master

搜索帮助