예제 #1
0
 def do_key(self, key):
     if key in g.CROSS and not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             self.help2()
             return
         bu = buttons.check()
         if bu != '':
             self.do_button(bu)
             return
         g.show_help = False
         self.check_nos(1)
         return
     if key in g.CIRCLE:
         self.check_nos(3)
         return
     if key in g.RIGHT:
         self.mouse_right()
         return
     if key in g.LEFT:
         self.mouse_left()
         return
     if key in g.SQUARE:
         if self.sugar and self.cyan_button.get_sensitive():
             self.do_button('cyan')
         if not self.sugar and buttons.active('cyan'):
             self.do_button('cyan')
         return
     if key in g.TICK:
         self.change_level()
         return
     if key == pygame.K_v:
         g.version_display = not g.version_display
         return
예제 #2
0
 def do_key(self, key):
     if key in g.CROSS and not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             self.help2()
             return
         bu = buttons.check()
         if bu != '':
             self.do_button(bu)
             return
         g.show_help = False
         self.check_nos(1)
         return
     if key in g.CIRCLE:
         self.check_nos(3)
         return
     if key in g.RIGHT:
         self.mouse_right()
         return
     if key in g.LEFT:
         self.mouse_left()
         return
     if key in g.SQUARE:
         if self.sugar and self.cyan_button.get_sensitive():
             self.do_button('cyan')
         if not self.sugar and buttons.active('cyan'):
             self.do_button('cyan')
         return
     if key in g.TICK:
         self.change_level()
         return
     if key == pygame.K_v:
         g.version_display = not g.version_display
         return
예제 #3
0
 def click(self):
     cxy = (self.frame_cx, self.frame_cy)
     if utils.mouse_on_img1(self.frame, cxy):
         if self.carry:
             self.carry = False
             return True
         else:
             mx, my = g.pos
             self.dx = self.frame_cx - mx
             self.dy = self.frame_cy - my
             self.carry = True
             return True
     for ind in range(self.find_n - 1, -1, -1):
         lf = lookFor[ind]
         if not lf.found:
             if utils.mouse_on_img(lf.img, lf.xy):
                 if ind == self.find_ind[self.current_ind]:
                     lf.found = True
                     self.found += 1
                     if not self.next1():
                         self.complete = True
                         g.count += 1
                     return True
                 else:
                     return False
     return False
예제 #4
0
 def which(self):
     ln = len(self.z)
     b = None
     for ind in range(ln - 1, -1, -1):
         ball = self.z[ind]
         if ball.active:
             if utils.mouse_on_img1(self.blue, ball.c):
                 if ball.pan != None:
                     if self.pan_n[ball.pan] == 4:
                         if ball.posn != 3: break  # must be top in full pan
                 b = ball
                 break
     return b
예제 #5
0
 def check_active(self):
     img = g.turtles[0].img
     for i in range(6):
         ind = 5 - i
         t = g.turtles[ind]
         if t.active:
             x = g.txy[0] + t.x
             y = g.txy[1] + t.y
             if utils.mouse_on_img1(img, (x, y)):
                 t.active = False
                 g.carry_ind = ind
                 return True
     return False
예제 #6
0
 def do_click(self):
     if g.map1: return False
     if g.pages:
         country = self.pages.which()
         if country != None:
             self.map1.setup(country)
             self.map_on()
             return True
         return False
     l = self.ctry.which_oval()
     if l != None:
         self.ctry.do_letter(l)
         return True
     else:
         if g.pic == g.globe:
             if self.ctry.complete():
                 if utils.mouse_on_img1(g.pic, g.xyc):
                     self.pages_on()
                     return True
         return False
예제 #7
0
 def mouse_left(self):
     bu = ''
     cx = g.n_cx0
     cy = g.n_cy0
     c = None
     if not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             c = (cx + 4 * g.n_dx, cy)
         elif buttons.mouse_on('cyan'):
             self.mouse_magician()
             return
         elif buttons.mouse_on('green'):
             if buttons.active('cyan'):
                 bu = 'cyan'
             else:
                 self.mouse_magician()
                 return
         elif buttons.mouse_on('red'):
             bu = 'green'
         elif buttons.mouse_on('black'):
             bu = 'red'
         if bu != '':
             buttons.set_mouse(bu)
             return
     if c is None:
         c = (cx, cy)  # default to 1st no.
         for i in range(5):
             n = g.numbers[i]
             if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)):
                 c = (cx - g.n_dx, cy)
                 break
             cx += g.n_dx
     cx, cy = c
     cx += g.sy(.2)
     cy += g.sy(1.2)
     c = cx, cy
     pygame.mouse.set_pos(c)
     g.pos = c
     return
예제 #8
0
 def mouse_left(self):
     bu = ''
     cx = g.n_cx0
     cy = g.n_cy0
     c = None
     if not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             c = (cx + 4 * g.n_dx, cy)
         elif buttons.mouse_on('cyan'):
             self.mouse_magician()
             return
         elif buttons.mouse_on('green'):
             if buttons.active('cyan'):
                 bu = 'cyan'
             else:
                 self.mouse_magician()
                 return
         elif buttons.mouse_on('red'):
             bu = 'green'
         elif buttons.mouse_on('black'):
             bu = 'red'
         if bu != '':
             buttons.set_mouse(bu)
             return
     if c is None:
         c = (cx, cy)  # default to 1st no.
         for i in range(5):
             n = g.numbers[i]
             if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)):
                 c = (cx - g.n_dx, cy)
                 break
             cx += g.n_dx
     cx, cy = c
     cx += g.sy(.2)
     cy += g.sy(1.2)
     c = cx, cy
     pygame.mouse.set_pos(c)
     g.pos = c
     return
예제 #9
0
 def mouse_right(self):
     bu = ''
     if not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             bu = 'green'
             if buttons.active('cyan'):
                 bu = 'cyan'
         elif buttons.mouse_on('cyan'):
             bu = 'green'
         elif buttons.mouse_on('green'):
             bu = 'red'
         elif buttons.mouse_on('red'):
             bu = 'black'
         if bu != '':
             buttons.set_mouse(bu)
             return
     cx = g.n_cx0
     cy = g.n_cy0
     c = (cx, cy)  # default to 1st no.
     if not buttons.mouse_on('black'):
         for i in range(5):
             n = g.numbers[i]
             if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)):
                 if i == 4:
                     self.mouse_magician()
                     return
                 c = (cx + g.n_dx, cy)
                 break
             cx += g.n_dx
     cx, cy = c
     cx += g.sy(.2)
     cy += g.sy(1.2)
     c = cx, cy
     pygame.mouse.set_pos(c)
     g.pos = c
     return
예제 #10
0
 def mouse_right(self):
     bu = ''
     if not self.sugar:
         if utils.mouse_on_img1(g.magician, g.magician_c):
             bu = 'green'
             if buttons.active('cyan'):
                 bu = 'cyan'
         elif buttons.mouse_on('cyan'):
             bu = 'green'
         elif buttons.mouse_on('green'):
             bu = 'red'
         elif buttons.mouse_on('red'):
             bu = 'black'
         if bu != '':
             buttons.set_mouse(bu)
             return
     cx = g.n_cx0
     cy = g.n_cy0
     c = (cx, cy)  # default to 1st no.
     if not buttons.mouse_on('black'):
         for i in range(5):
             n = g.numbers[i]
             if utils.mouse_on_img_rect(g.n[n - 1], (cx, cy)):
                 if i == 4:
                     self.mouse_magician()
                     return
                 c = (cx + g.n_dx, cy)
                 break
             cx += g.n_dx
     cx, cy = c
     cx += g.sy(.2)
     cy += g.sy(1.2)
     c = cx, cy
     pygame.mouse.set_pos(c)
     g.pos = c
     return
예제 #11
0
    def run(self, restore=False):
        self.g_init()
        if not self.journal:
            utils.load()
        load_save.retrieve()
        if restore:
            self.restore_pattern()
        else:
            g.delay = (3 - g.level) * 400
        self.tu = my_turtle.TurtleClass()
        self.tu.current = [1, 1, 1, 3, 2]
        self.get_goal()
        if g.pattern == 1:
            self.tu.current = utils.copy_list(g.goal)
        self.tu.setup(self.colors[0])
        g.numbers = utils.copy_list(self.tu.current)
        #buttons
        x = g.sx(7.3)
        y = g.sy(16.5)
        dx = g.sy(2.6)

        if not self.sugar:
            buttons.Button("cyan", (x, y), True)
            x += dx
            buttons.off('cyan')
            buttons.Button("green", (x, y), True)
            x += dx
            buttons.Button("red", (x, y), True)
            x += dx
            buttons.Button("black", (x, y), True)
            x += dx
            self.slider = slider.Slider(g.sx(23.5), g.sy(21), 3, utils.YELLOW)

        self.mouse_1st_no()  # to 1st number
        if self.canvas is not None:
            self.canvas.grab_focus()
        ctrl = False
        pygame.key.set_repeat(600, 120)
        key_ms = pygame.time.get_ticks()
        going = True
        while going:
            if self.journal:
                # Pump GTK messages.
                while gtk.events_pending():
                    gtk.main_iteration()

            # Pump PyGame messages.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    if not self.journal:
                        utils.save()
                    going = False
                elif event.type == pygame.MOUSEMOTION:
                    g.pos = event.pos
                    g.redraw = True
                    if self.canvas is not None:
                        self.canvas.grab_focus()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    g.redraw = True
                    if g.big:
                        g.big = False
                    else:
                        bu = buttons.check()
                        if bu != '':
                            self.do_button(bu)
                            self.flush_queue()
                        elif not self.sugar:
                            if utils.mouse_on_img1(g.magician, g.magician_c):
                                self.help2()
                            elif utils.mouse_in(g.x1, g.y0, g.x1 + g.bw,
                                                g.y0 + g.bw):
                                self.big_pic()
                            elif self.slider.mouse():
                                g.delay = (3 - g.level) * 400
                            else:
                                g.show_help = False
                                self.check_nos(event.button)
                        else:
                            g.show_help = False
                            self.check_nos(event.button)
                elif event.type == pygame.KEYDOWN:
                    # throttle keyboard repeat
                    if pygame.time.get_ticks() - key_ms > 110:
                        key_ms = pygame.time.get_ticks()
                        if ctrl:
                            if event.key == pygame.K_q:
                                if not self.journal:
                                    utils.save()
                                going = False
                                break
                            else:
                                ctrl = False
                        if event.key in (pygame.K_LCTRL, pygame.K_RCTRL):
                            ctrl = True
                            break
                        self.do_key(event.key)
                        g.redraw = True
                        self.flush_queue()
                elif event.type == pygame.KEYUP:
                    ctrl = False
            if not going:
                break
            if self.tu.running:
                self.tu.move()
            if not g.crash_drawn:
                g.crash_drawn = True
                g.redraw = True
            if g.redraw:
                self.display()
                if g.version_display:
                    utils.version_display()
                g.screen.blit(g.pointer, g.pos)
                pygame.display.flip()
                g.redraw = False
            g.clock.tick(40)
예제 #12
0
    def run(self, restore=False):
        for event in pygame.event.get():
            if event.type==pygame.QUIT:
                return
            elif event.type == pygame.VIDEORESIZE:
                pygame.display.set_mode(event.size, pygame.RESIZABLE)
                break
        self.g_init()
        if not self.journal:
            utils.load()
        load_save.retrieve()
        if restore:
            self.restore_pattern()
        else:
            g.delay = (3 - g.level) * 400
        self.tu = my_turtle.TurtleClass()
        self.tu.current = [1, 1, 1, 3, 2]
        self.get_goal()
        if g.pattern == 1:
            self.tu.current = utils.copy_list(g.goals[0])
        self.tu.setup(self.colors[0])
        g.numbers = utils.copy_list(self.tu.current)
        # buttons
        x = g.sx(7.3)
        y = g.sy(16.5)
        dx = g.sy(2.6)

        if not self.sugar:
            buttons.Button("cyan", (x, y), True)
            x += dx
            buttons.off('cyan')
            buttons.Button("green", (x, y), True)
            x += dx
            buttons.Button("red", (x, y), True)
            x += dx
            buttons.Button("black", (x, y), True)
            x += dx
            self.slider = slider.Slider(g.sx(23.5), g.sy(21), 3, utils.YELLOW)

        self.mouse_1st_no()  # to 1st number
        if self.canvas is not None:
            self.canvas.grab_focus()
        ctrl = False
        pygame.key.set_repeat(600, 120)
        key_ms = pygame.time.get_ticks()
        going = True
        while going:
            if self.journal:
                # Pump Gtk messages.
                while Gtk.events_pending():
                    Gtk.main_iteration()

            # Pump PyGame messages.
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    if not self.journal:
                        utils.save()
                    going = False
                elif event.type == pygame.MOUSEMOTION:
                    g.pos = event.pos
                    g.redraw = True
                    if self.canvas is not None:
                        self.canvas.grab_focus()
                elif event.type == pygame.MOUSEBUTTONDOWN:
                    g.redraw = True
                    if g.big:
                        g.big = False
                    else:
                        bu = buttons.check()
                        if bu != '':
                            self.do_button(bu)
                            self.flush_queue()
                        elif not self.sugar:
                            if utils.mouse_on_img1(g.magician, g.magician_c):
                                self.help2()
                            elif utils.mouse_in(g.x1, g.y0, g.x1 + g.bw,
                                                g.y0 + g.bw):
                                self.big_pic()
                            elif self.slider.mouse():
                                g.delay = (3 - g.level) * 400
                            else:
                                g.show_help = False
                                self.check_nos(event.button)
                        else:
                            g.show_help = False
                            self.check_nos(event.button)
                elif event.type == pygame.KEYDOWN:
                    # throttle keyboard repeat
                    if pygame.time.get_ticks() - key_ms > 110:
                        key_ms = pygame.time.get_ticks()
                        if ctrl:
                            if event.key == pygame.K_q:
                                if not self.journal:
                                    utils.save()
                                going = False
                                break
                            else:
                                ctrl = False
                        if event.key in (pygame.K_LCTRL, pygame.K_RCTRL):
                            ctrl = True
                            break
                        self.do_key(event.key)
                        g.redraw = True
                        self.flush_queue()
                elif event.type == pygame.KEYUP:
                    ctrl = False
            if not going:
                break
            if self.tu.running:
                self.tu.move()
            if not g.crash_drawn:
                g.crash_drawn = True
                g.redraw = True
            if g.redraw:
                self.display()
                if g.version_display:
                    utils.version_display()
                g.screen.blit(g.pointer, g.pos)
                pygame.display.flip()
                g.redraw = False
            g.clock.tick(40)