Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/levelfour.py
blob: 4e1e4e8390bd327ad2abe7f62ee8ae1e5f31e2a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
import random, os.path
import util

import pygame
import pygame.font
from pygame.locals import *
import time
import math

#to do: possibly change to 5 minute intervals for ease of reading
#       put am/pm on the watches themselves
    
def run():
    #Must initialize pygame before doing anything else
    pygame.init()
    random.seed()
    
    display_flags = DOUBLEBUF
    
    #XO laptop is 1200x900 resolution
    width, height = 1200, 900

    if pygame.display.mode_ok((width, height), display_flags ):
        screen = pygame.display.set_mode((width, height), display_flags)
		  
    clock = pygame.time.Clock() 
    run = 1
    pygame.display.set_caption('OLPC Math Game')



    background = util.load_image('watch_drop_bg.bmp')
    
    watch1 = util.load_image('watch_broken2.bmp')
    colorkey = watch1.get_at((0, 0))
    watch1.set_colorkey(colorkey)
    
    watch2 = util.load_image('watch3.bmp')
    colorkey = watch2.get_at((0, 0))
    watch2.set_colorkey(colorkey)
    
    bg_draw = 1
    state = (4,1)
    screen.blit(background,(0,0))
    intro_string = "We are finally out of the cellar, but now Count Mathenstein is nowhere in sight! But look, he dropped his watch...and it broke when it fell, so it still is showing the time it was when he was here! How long has it been since the Count was last here?"
    util.ok_box(intro_string,(300,300),600,70,screen)
    current_hours = int(time.strftime("%H"))
    current_minutes = int(time.strftime("%M"))
    random_hours = random.randint(0,current_hours)
    if random_hours == current_hours and current_minutes > 20:
        random_minutes = random.randint(10,current_minutes)
    else:
        random_minutes = random.randint(0,60)
    if current_hours % 12 == current_hours and current_hours != 12:
        am_pm_current = "AM"
    else:
        am_pm_current = "PM"
        
    if random_hours % 12 == random_hours and random_hours != 12:
        am_pm_broken = "AM"
    else:
        am_pm_broken = "PM"

    watch3_mid =  (333,441)
    broken_watch =  (880,510)
    line_length_1 = 100
    cur_hours = current_hours
    current_hours = current_hours % 12
    if current_hours == 0:
        current_hours = 12
    elapsed_time = (cur_hours - random_hours)*60+current_minutes-random_minutes
    print "answer in case its hard to tell for debugging:"
    print " current time: "
    print current_hours
    print current_minutes
    print am_pm_current
    print "random time"
    print random_hours
    print random_minutes
    print am_pm_broken
    print "elapsed: "
    print elapsed_time

    while run:
        events = pygame.event.get()
        for event in events: 
            #User decides to exit program
            if event.type == QUIT:              
                run = 0 #stop running
                pygame.quit()


        if bg_draw  == 1:
            bg_draw = 0
            screen.blit(background,(0,0))
            screen.blit(watch1,(630,100))
            screen.blit(watch2, (100,100))
            font = pygame.font.Font(None, 24)

            pygame.draw.line(screen, (0,0,0),watch3_mid,( watch3_mid[0]+50*math.cos(math.radians(90-30*current_hours)), watch3_mid[1]-50*math.sin(math.radians(90-30*current_hours))) ,8)
            pygame.draw.line(screen, (0,0,0),watch3_mid, (watch3_mid[0]+100*math.cos(math.radians(90-6*current_minutes)), watch3_mid[1]-100*math.sin(math.radians(90-6*current_minutes))), 2) 
            
            pygame.draw.line(screen, (0,0,0),broken_watch, (broken_watch[0]+50*math.cos(math.radians(90-30*random_hours)),broken_watch[1]-50*math.sin(math.radians(90-30*random_hours)) ) ,8)
            pygame.draw.line(screen, (0,0,0),broken_watch, (broken_watch[0]+100*math.cos(math.radians(90-6*random_minutes)), broken_watch[1]-100*math.sin(math.radians(90-6*random_minutes))), 2)
            
            text_rect = pygame.Rect((400,800),(30,30))
            text_box = util.render_textrect(am_pm_current,font,text_rect,(255,255,255),0,0)
            screen.blit(text_box,text_rect.topleft)

            text_rect = pygame.Rect((900,800),(30,30))
            text_box = util.render_textrect(am_pm_broken,font,text_rect,(255,255,255),0,0)
            screen.blit(text_box,text_rect.topleft)

            elapsed_guess = util.ask(screen,"How long has it been since his watch broke? (HH:MM)", 450,800,400)
            print "hmm"
            hours_guess = int(elapsed_guess[0:elapsed_guess.find(':')])
            minutes_guess = int(elapsed_guess[elapsed_guess.find(':')+1:len(elapsed_guess)])
            guess = hours_guess*60+minutes_guess
            print "guess"
            print guess
        
            if int(guess) == elapsed_time or elapsed_guess == "quit":
                print "win"
                util.ok_box("Good job, now we know how long it has been since he was here!",(500,300),200,50,screen)
                run = 0
            else:
                bg_draw = 1
            


        pygame.display.flip()
        
        clock.tick(40) #limits to 40 FPS
	
    
def main():
    print "Running Tower"
    run()
    
#runs main if called via other naming convention
if __name__ == '__main__': main()