作业Week3 "Stopwatch: The Game"
来源:互联网 发布:c语言实现http请求 编辑:程序博客网 时间:2024/05/24 13:28
#!/usr/bin/env python# -*- coding: utf-8 -*-"""__title__ = 'Stopwatch'__author__ = 'Steve'__mtime__ = '2017/9/25'"""# template for "Stopwatch: The Game"import SimpleGUICS2Pygame.simpleguics2pygame as simplegui# define global variablest = 0t_color = "White"times = 0score = 0running = False# define helper function format that converts time# in tenths of seconds into formatted string A:BC.Ddef format(t): D = t % 10 A = t / 600 (B, C) = divmod(t % 600 / 10, 10) return str(A) + ":" + str(B) + str(C) + "." + str(D)# define event handlers for buttons; "Start", "Stop", "Reset"def start(): global t_color, running timer.start() t_color = "White" running = Truedef stop(): global t_color, score, times, running timer.stop() # 补上判断timer是否running阶段 if running == True: times += 1 if t % 10 == 0: t_color = "Gold" # 添加了变色的提示 score += 1 running = Falsedef reset(): global t, t_color, score, times, running t = 0 timer.stop() t_color = "White" times = 0 score = 0 running = False# define event handler for timer with 0.1 sec intervaldef timer_handler(): global t t += 1# define draw handlerdef draw(canvas): global t_color score_message = "Score: " + str(score) + "/" + str(times) canvas.draw_text(format(t), [80, 110], 36, t_color) canvas.draw_text(score_message, [200, 25], 20, "Yellow")# create framef = simplegui.create_frame("Stopwatch", 300, 200)# register event handlersf.add_button("Start", start, 200)f.add_button("Stop", stop, 200)f.add_button("Reset", reset, 200)f.set_draw_handler(draw)timer = simplegui.create_timer(100, timer_handler)# start framef.start()# Please remember to review the grading rubric
阅读全文
0 0
- 作业Week3 "Stopwatch: The Game"
- Mini-project # 3 - "Stopwatch: The Game"
- Week3 作业
- WEEK3作业
- week3作业
- Interactive Python:Mini-project # 3 - "Stopwatch: The Game"
- IIPP迷你项目(三)“Stopwatch: The Game”
- c++ 程序设计 week3 作业
- 【算法设计作业】week3
- 莱斯大学Python课程Mini-project# 3 - "Stopwatch: The Game"
- Beware of the stopwatch
- Logistic Regression WEEK3编程作业
- Stopwatch
- Stopwatch
- Stopwatch
- StopWatch
- Stopwatch
- Stanford 机器学习 Week3 作业 Logistic Regression
- 九度OJ题目1045:百鸡问题
- OD 常用命令
- c语言文件操作函数
- Java 并发工具包 java.util.concurrent 用户指南
- 入门 Webpack,看这篇就够了
- 作业Week3 "Stopwatch: The Game"
- Elasticsearch 架构原理
- Ubuntu命令(不断更新之中)
- C++实现日期类
- scanf、getchar、gets
- Elasticsearch索引原理
- PHP命名规则
- 1Z0-052-001
- Java设计模式——装饰者模式(Decorator Pattern)