zoukankan      html  css  js  c++  java
  • Mini-project # 3

    = =上周的作业,一直忘记更新啦

    这周是做一个定时器游戏。。然而因为永远不能停在正确的位置导致测试好麻烦 - -

    有一个问题是:

      好像不能每次发生改变的时候再用改变字符串的形式使输出改变,而只能在参数里调转成字符串的函数才能在正常的时间点显示T T 

      原因不知。。

    http://www.codeskulptor.org/#user40_Dfn3DhnkwjfR7Mb.py

    import simplegui
    # define global variables
    time = 0
    isrunning = False
    succ = 0
    tot = 0
    
    
    # define helper function format that converts time
    # in tenths of seconds into formatted string A:BC.D
    def format(t):
        D = t % 10;
        t /= 10;
        A = t / 60;
        B = t % 60
        C = B % 10;
        B /= 10
        return str(A)+":"+str(B)+str(C)+"."+str(D)
        
    # define event handlers for buttons; "Start", "Stop", "Reset"
    def start_game():
        global time, isrunning
        isrunning = True
        timer.start()
        
    def stop_game():
        global tot, isrunning, succ
        timer.stop()
        if isrunning == True:
            tot += 1
            if time % 10 == 0 :
                succ += 1
        isrunning = False
        
    def Clear():
        global time, succ, tot
        time = 0
        succ = 0
        tot = 0
        isrunning = False
        timer.stop()
        
    # define event handler for timer with 0.1 sec interval
    def tick():
        global time
        time += 1
    # define draw handler
    def draw(canvas):
        canvas.draw_text(format(time), [200,215],32,"White")
        canvas.draw_text(str(succ)+'/'+str(tot), [340,20], 28, "Blue")
        
    # create frame
    f = simplegui.create_frame("Timer Game", 400, 400)
    timer = simplegui.create_timer(100, tick)
    start = f.add_button("Start", start_game)
    stop = f.add_button("Stop", stop_game)
    reset = f.add_button("Reset", Clear)
    
    # register event handlers
    f.set_draw_handler(draw)
    
    # start frame
    f.start()
    
    # Please remember to review the grading rubric
    View Code
  • 相关阅读:
    ButterKnife不同版本配置
    【转载】RecyclerView源码解析
    【转载】RecyclerView使用全解析
    RecyclerView 和 ListView 使用对比分析
    apk瘦身
    【转载】图片压缩最优方案
    file.listFiles()按文件大小、名称、日期排序方法
    git命令
    Android中由Handler和内部类引起的内存泄漏
    查看Android手机数据库
  • 原文地址:https://www.cnblogs.com/bbbbbq/p/4733407.html
Copyright © 2011-2022 走看看