Example #1
0
 def right_click(self):
     # load number
     x,y=self.load_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.load_n-=1
         if g.load_n<1: g.load_n=g.saved_n
         return True
     # save number
     x,y=self.save_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.save_n-=1
         if g.save_n<1: g.save_n=g.saved_n+1
         return True
     return False
Example #2
0
 def mouse_over(self):
     for i in range(10):
         c = self.centres[i]
         cx = c[0]
         cy = c[1]
         w2 = self.w2
         h2 = self.h2
         if utils.mouse_in(cx - w2, cy - h2, cx + w2, cy + h2):
             n = self.yes[i]
             v = value(n)
             s = suit(n)
             h = self.help1()
             if h == 'nos':
                 utils.display_number(v, c, g.font1, utils.CYAN,
                                      utils.ORANGE)
             elif h == 'odd_even':
                 if odd(v):
                     utils.display_number(v, c, g.font1, utils.CYAN,
                                          utils.RED)
                 else:
                     utils.display_number(v, c, g.font1, utils.RED,
                                          utils.CYAN)
             elif h == 'suit':
                 utils.centre_blit(g.screen, g.suits[s], c)
             elif h == 'colour':
                 img = g.red
                 if colour(n) == 'b': img = g.black
                 utils.centre_blit(g.screen, img, c)
             elif h == 'castle':
                 utils.centre_blit(g.screen, g.castle, c)
             elif h == 'castle_x':
                 utils.centre_blit(g.screen, g.castle_x, c)
             elif h == 'xo1':
                 utils.centre_blit(g.screen, g.xo1, c)
             return
Example #3
0
 def which(self):
     s=self.ss
     for sq in self.sqs:
         x=sq.x; y=sq.y
         if utils.mouse_in(x,y,x+s,y+s):
             return sq
     return None
Example #4
0
 def which(self):
     page = 1
     ind = 0
     while page < self.current:
         nr = 4
         if page == 6: nr = 3
         for r in range(nr):
             for c in range(6):
                 ind += 1
         page += 1
     y = 0
     dx = g.sy(32) / 6
     dy = g.sy(18.5) / 4
     nr = 4
     if page == 6: nr = 3
     for r in range(nr):
         x = g.sx(0)
         for c in range(6):
             if utils.mouse_in(x, y, x + dx, y + dy):
                 country = g.countries[ind][0]
                 return country
             x += dx
             ind += 1
             if ind == len(g.countries): return None
         y += dy
     return None
Example #5
0
 def check_mouse(self):
     if not self.complete():
         for locn in self.locns:
             if utils.mouse_in(locn.x, locn.y, locn.x + self.w,
                               locn.y + self.h):
                 self.green = locn
                 return True
     return False
Example #6
0
 def which(self):
     x1 = self.x1
     x2 = self.x2
     for i in range(1, 7):
         if utils.mouse_in(x1, self.y1, x2, self.y2): return i
         x1 += self.dx
         x2 += self.dx
     return 0
Example #7
0
 def in_box(self):
     for box in memory:
         if utils.mouse_in(box.x, box.y, box.x + self.rect_w,
                           box.y + self.rect_h):
             self.pc = box.ind
             self.clear_input()
             return True
     return False
Example #8
0
 def click(self):
     first=True
     for pce in self.pieces:
         if not first:
             if utils.mouse_in(pce.x,pce.y,pce.x+self.dd,pce.y+self.dd):
                 self.green=pce; return True
         first=False
     return False
Example #9
0
 def which(self):
     n = 1
     for item in self.items:
         x, y = item.x, item.y
         if utils.mouse_in(x, y, x + self.pic_w, y + self.pic_h):
             return n
         n += 1
     return 0
Example #10
0
 def do_click(self, button):
     # load number
     x, y = self.load_c
     d = self.load_d
     if utils.mouse_in(x - d, y - d, x + d, y + d):
         if g.load_n != None:
             if button == 1:
                 g.load_n += 1
                 if g.load_n > g.saves_n: g.load_n = 1
             if button == 3:
                 g.load_n -= 1
                 if g.load_n < 1: g.load_n = g.saves_n
         return
     # save number
     x, y = self.save_c
     d = self.load_d
     if utils.mouse_in(x - d, y - d, x + d, y + d):
         if button == 1:
             g.save_n += 1
             if g.save_n > g.saves_n + 1: g.save_n = 1
         if button == 3:
             g.save_n -= 1
             if g.save_n < 1: g.save_n = g.saves_n + 1
         return
     if button == 3:
         self.didg.rotate()
         return
     if button == 1:
         # shapes
         if self.didg.which_shape(): return
         # colours
         if self.didg.which_colour(): return
         # drawing area
         x, y = g.surf_xy
         if utils.mouse_in(x, y, x + g.surf_w, y + g.surf_h):
             if g.carry:
                 dx = g.carry_img.get_width() / 2
                 dy = g.carry_img.get_height() / 2
                 xy = (g.pos[0] - dx - x, g.pos[1] - dy - y)
                 g.surf.blit(g.carry_img, xy)
                 g.redraw = True
                 return
         # nowhere so put down
         g.carry = False
Example #11
0
 def which_colour(self):
     x, y = self.colours_xy
     w, h = self.colours_wh
     for ind in range(len(colours)):
         if utils.mouse_in(x, y, x + w, y + h):
             g.colour_ind = ind
             self.make_carry()
             return True
         y += h
     return False
Example #12
0
 def check_mouse(self):
     ind = 0
     for locn in locations:
         if utils.mouse_in(locn.x, locn.y, locn.x + self.gw,
                           locn.y + self.gh):
             if ind == 0:
                 self.orange = locations[1]
             else:
                 self.orange = locn
             return
         ind += 1
Example #13
0
 def which_pile(self):
     y = g.y1
     for r in range(1, 10):
         x = g.x1
         for c in range(1, piles[r] + 1):
             if c == piles[r]:
                 if utils.mouse_in(x, y, x + g.d, y + g.d):
                     return r
             x += g.dx1
         y += g.dy1
     return 0
Example #14
0
 def mouse_move(self):
     n = self.n
     y = self.y0
     d = self.w0 + self.dw0
     for r in range(n):
         x = self.x0
         for c in range(n):
             if utils.mouse_in(x, y, x + self.w0, y + self.w0):
                 self.green = (r, c)
                 return
             x += d
         y += d
Example #15
0
 def which_pile(self):
     y = squares[0].y
     dx = g.sy(.8)
     dy = g.d + g.space
     for r in range(1, 10):  # 1..9
         x = g.sx(.2)
         for i in range(1, piles[r] + 1):
             if i == piles[r]:
                 if utils.mouse_in(x, y, x + g.d, y + g.d): return r
             x += dx
         y += dy
     return 0
Example #16
0
 def n_pad(self):
     x0, y0 = self.n_xy
     y = y0
     ind = 0
     for r in range(4):
         x = x0
         for c in range(3):
             if utils.mouse_in(x, y, x + self.n_dx, y + self.n_dy):
                 return (7, 8, 9, 4, 5, 6, 1, 2, 3, 0, 'back', 'enter')[ind]
             x += self.n_dx
             ind += 1
         y += self.n_dy
     return None
def shape_click(mouse_button):
    if utils.mouse_in(g.basic_x, g.basic_y, g.basic_w, g.basic_h):
        if mouse_button == 2: return True  # ignore middle button
        if mouse_button == 1:
            g.shape += 1
            if g.shape == len(g.shapes): g.shape = 0
        if mouse_button == 3:
            g.shape -= 1
            if g.shape < 0: g.shape = len(g.shapes) - 1
        player.reset()
        return True
    else:
        return False
Example #18
0
 def click(self):
     self.red_ind = None
     self.yellow_ind = None
     g.wrong = False
     for sq in self.squares:
         if utils.mouse_in(sq.x, sq.y, sq.x + self.d, sq.y + self.d):
             if len(self.colours) > 0:
                 colr = self.colours.pop()
                 sq.colrs.append(colr)
             else:
                 if len(sq.colrs) < 5:
                     sq.colrs = [None] + sq.colrs
             return True
     return False
Example #19
0
 def do_click(self):
     # load number
     x,y=self.load_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.load_n+=1
         if g.load_n>g.saved_n: g.load_n=1
         return True
     # save number
     x,y=self.save_c; d=self.load_d
     if utils.mouse_in(x-d,y-d,x+d,y+d):
         g.save_n+=1
         if g.save_n>(g.saved_n+1): g.save_n=1
         return True
     if self.sim.in_box(): return True
     # help (printer image)
     if utils.mouse_on_img(self.sim.printer,self.sim.printer_xy):
         g.help_on=True; buttons.off('help'); return
     n=self.sim.n_pad()
     if n==None: return False
     if n=='enter': self.do_key(13); return True
     if n=='back': self.do_key(8); return True
     if len(self.sim.inos)==4: self.sim.inos=self.sim.inos[1:]
     self.sim.inos.append(n)
     return True
Example #20
0
 def click(self):
     x = self.x0
     y = self.y0
     ind1 = 0
     for l in self.given:
         if utils.mouse_in(x, y, x + self.w, y + self.h):
             if not self.taken[ind1]:
                 self.taken[ind1] = True
                 self.ans += l
             return True
         x += self.w
         ind1 += 1
     x = self.x0
     y = self.y1
     ind1 = 0
     for l in self.ans:
         if utils.mouse_in(x, y, x + self.w, y + self.h):
             self.put_back(l)
             self.ans = self.ans[:ind1] + self.ans[ind1 + 1:]
             g.state = 2
             return True
         x += self.w
         ind1 += 1
     return False
Example #21
0
 def right_click(self):
     self.red_ind = None
     self.yellow_ind = None
     g.wrong = False
     for sq in self.squares:
         if utils.mouse_in(sq.x, sq.y, sq.x + self.d, sq.y + self.d):
             if len(sq.colrs) > 0:
                 colr = sq.colrs.pop()
                 self.colours.append(colr)
                 if len(sq.colrs) > 0:
                     t = sq.colrs.pop()
                     if t == None: sq.colrs = []
                     else: sq.colrs.append(t)
             return True
     return False
def target_click(mouse_button):
    if utils.mouse_in(aim.top_left[0], aim.top_left[1], aim.side, aim.side):
        if len(g.shapes) > 7:
            if mouse_button == 2: return True  # ignore middle button
            aim.clear()
            if mouse_button == 1:
                g.aim_n += 1
                if g.aim_n == len(my_turtle.aims): g.aim_n = 0
            if mouse_button == 3:
                g.aim_n -= 1
                if g.aim_n < 0: g.aim_n = len(my_turtle.aims) - 1
            aim_setup()
            player.reset()
        return True
    else:
        return False
Example #23
0
 def square_click(self):
     self.mark_fail = False
     self.red = None
     self.colr_n = utils.CREAM
     n = self.n
     y = self.y0
     d = self.w0 + self.dw0
     for r in range(n):
         x = self.x0
         for c in range(n):
             if utils.mouse_in(x, y, x + self.w0, y + self.w0):
                 self.do_square(r, c)
                 return True
             x += d
         y += d
     return False
Example #24
0
 def do_click(self):
     if self.som.click():
         self.flush_queue()
         return True
     d = g.n_d
     d2 = d / 2
     if g.n == 4: x, y = g.n_c4
     else: x, y = g.n_c5
     if utils.mouse_in(x - d2, y - d2, x + d2, y + d2):
         if g.n == 4:
             self.som = self.som5
             g.n = 5
         else:
             self.som = self.som4
             g.n = 4
         return True
     return False
Example #25
0
 def right_click(self):
     self.no = False
     for sq in squares:
         if utils.mouse_in(sq.x, sq.y, sq.x + self.side, sq.y + self.side):
             if not sq.visible:
                 d = self.side / 2
                 g.glow_c = sq.x + d, sq.y + d
                 g.ms = -1
                 g.glow = g.red
                 sq.visible = True
                 if sq.v > 0 and sq.v < 6:
                     self.count += 1
                     self.no = True
                 else:
                     g.glow = g.gold
             return True
     return False
Example #26
0
 def map_display(self):
     g.screen.fill(g.bgd_colour)
     x0 = g.sx(1)
     y0 = g.sy(6)
     d = g.sy(2.7)
     g.screen.blit(g.map2, (x0, y0))
     y = y0
     ind = 0
     for r in range(4):
         x = x0
         for c in range(4):
             if utils.mouse_in(x, y, x + d, y + d):
                 self.rooms[ind].display1(g.sx(13.5), g.sy(2))
                 return
             x += d
             ind += 1
         y += d
 def check_nos(self, mouse_button):
     w = g.n[3].get_width()
     h = g.n[3].get_height()  # "4" is widest
     x1 = g.n_cx0 - w / 2
     y1 = g.n_cy0 - h / 2
     x2 = g.n_cx0 + w / 2
     y2 = g.n_cy0 + h / 2
     for pos in range(5):
         if utils.mouse_in(x1, y1, x2, y2):
             self.tu.changed = True
             self.tu.running = False
             if mouse_button == 1:
                 self.inc_numbers(pos)
             elif mouse_button == 3:
                 self.dec_numbers(pos)
             return True
         x1 += g.n_dx
         x2 += g.n_dx
     return False
Example #28
0
 def which_shape(self):
     for shape in shapes:
         x = shape.x
         y = shape.y
         d = g.sy(1.5)
         w = shape.w
         if w < d:
             x -= (d - w) / 2
             w = d
         h = shape.h
         if h < d:
             y -= (d - h) / 2
             h = d
         if utils.mouse_in(x, y, x + w, y + h):
             g.carry_shape = shape
             self.make_carry()
             g.carry = True
             return True
     return False
Example #29
0
 def check_nos(self, mouse_button):
     w = g.n[3].get_width()
     h = g.n[3].get_height()  # "4" is widest
     x1 = g.n_cx0 - w / 2
     y1 = g.n_cy0 - h / 2
     x2 = g.n_cx0 + w / 2
     y2 = g.n_cy0 + h / 2
     for pos in range(5):
         if utils.mouse_in(x1, y1, x2, y2):
             self.tu.changed = True
             self.tu.running = False
             if mouse_button == 1:
                 self.inc_numbers(pos)
             elif mouse_button == 3:
                 self.dec_numbers(pos)
             return True
         x1 += g.n_dx
         x2 += g.n_dx
     return False
Example #30
0
 def click(self):
     n = 0
     d = g.sy(.5)
     for edge in self.edges:
         if not edge.gold:
             x1 = edge.x1 + d
             y1 = edge.y1 - d
             x2 = edge.x2 - d
             y2 = edge.y2 + d
             if utils.mouse_in(x1, y1, x2, y2):
                 self.last = None
                 edge.gold = True
                 self.edge_flash = None
                 if not self.check_boxes():
                     self.ms = pygame.time.get_ticks()
                     g.state = 2
                 return True
         n += 1
         if n == 30: d = -d
     return False
Example #31
0
 def menu_click(self):
     d = g.sy(.22)
     w = g.sy(7.73)
     h = g.sy(3.68)
     y0 = g.sy(1)
     y = y0
     n = 0
     for r in range(5):
         x = d
         for c in range(4):
             n += 1
             if utils.mouse_in(x, y, x + w, y + h):
                 self.jigsaw_n = n
                 g.state = 2
                 g.screen.fill(utils.CYAN)
                 utils.centre_blit(g.screen, g.wait, (g.sx(16), g.sy(11)))
                 pygame.display.flip()
                 return
             x += w + d
         y += h + d
Example #32
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)