Mini-project # 3-"Stopwatch:the Game"

Source: Internet
Author: User

= = Last week's homework, always forget to update

This week is to do a timer game. But because you can never stop in the right place and cause the test to be troublesome--

There is one problem:

It seems that it is not possible to change the output of a string every time a change occurs, but a function that can only be converted to a string in a parameter can display T T at a normal point in time.

I don't know why.

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

Import simplegui# DefineGlobalVariablestime=0isrunning=FALSESUCC=0tot=0# define helper function format that converts time#inchTenths of seconds into formattedstringA:BC. Ddef format (t): D= t%Ten; T/=Ten; A= t/ -; B= t% -C= B%Ten; B/=Ten    returnSTR (A) +":"+str (B) +str (C) +"."+Str (D) # defineEventHandlers forButtons"Start","Stop","Reset"def start_game ():GlobalTime , isrunning isrunning=True Timer.start () def stop_game ():Globaltot, isrunning, succ timer.stop ()ifIsRunning = =True:tot+=1        ifTime%Ten==0: Succ+=1isrunning=False def Clear ():GlobalTime , succ, tot time=0succ=0tot=0isrunning=False timer.stop () # defineEventHandler forTimer with0.1sec Intervaldef Tick ():Global Time Time+=1# define Draw Handlerdef Draw (canvas): Canvas.draw_text (format time), [ $,215], +," White") Canvas.draw_text (str (SUCC)+'/'+str (TOT), [340, -], -,"Blue") # Create FRAMEF= Simplegui.create_frame ("Timer Game", -, -) Timer= Simplegui.create_timer ( -, tick) start= F.add_button ("Start", Start_game) Stop= F.add_button ("Stop", stop_game) Reset= F.add_button ("Reset", Clear) # RegisterEventHandlersf.set_draw_handler (Draw) # start Framef.start () # Remember to review the grading rubric
View Code

Mini-project # 3-"Stopwatch:the Game"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.