Beispiel #1
0
def checkmousepos(x: int, y: int, w: int, h: int) -> bool:
    """
    Controlla se la posizione del mouse è all'interno del rettangolo di coordinate/dimensioni fornite.
    """
    x2 = g2d.mouse_position()[0]
    y2 = g2d.mouse_position()[1]
    return y < y2 < y + h and x < x2 < x + w
    def tick(self):
        global solved

        if g2d.key_pressed("LeftButton"):
            self._downtime = time()
        elif g2d.key_released("LeftButton"):
            mouse = g2d.mouse_position()
            x, y = mouse[0] // W, mouse[1] // H
            if time() - self._downtime > LONG_PRESS:
                self._game.flag_at(x, y)
            else:
                self._game.play_at(x, y)
            self.update_buttons()
        if g2d.key_pressed("a"):
            self._game.mark_auto()
        elif g2d.key_released("a"):
            self.update_buttons()
        if g2d.key_pressed("h"):
            self._game.user_helper()
        elif g2d.key_released("h"):
            self.update_buttons()
        if g2d.key_pressed("r"):
            if not solved:
                while not solved:
                    solved = self._game.solve_recursive(0)
            else:
                solved = False
                self._game.clear_board()
        elif g2d.key_released("r"):
            self.update_buttons()
Beispiel #3
0
def keydown(key):
    x, y = g2d.mouse_position()
    g2d.set_color((randrange(256), randrange(256), randrange(256)))
    if x <= 25 and y <= 25 and g2d.confirm("Exit?"):
        g2d.close_canvas()
    else:
        g2d.fill_circle((x, y), 25)
Beispiel #4
0
def tick():
    if g2d.key_pressed("LeftButton"):
        x, y = g2d.mouse_position()
        g2d.set_color((randrange(256), randrange(256), randrange(256)))
        if x <= 25 and y <= 25 and g2d.confirm("Exit?"):
            g2d.close_canvas()
        else:
            g2d.fill_circle((x, y), 25)
Beispiel #5
0
 def mouseup(self, code):
     if code == "LeftButton":
         pos = g2d.mouse_position()
         x, y = pos[0] // W, pos[1] // H
         if time() - self._downtime > LONG_PRESS:
             self._game.flag_at(x, y)
         else:
             self._game.play_at(x, y)
         self.update_buttons()
Beispiel #6
0
 def tick(self):
     if g2d.key_pressed("LeftButton"):
         self._downtime = time()
     elif g2d.key_released("LeftButton"):
         pos = g2d.mouse_position()
         x, y = pos[0] // W, pos[1] // H
         if time() - self._downtime > LONG_PRESS:
             self._game.flag_at(x, y)
         else:
             self._game.play_at(x, y)
         self.update_buttons()
Beispiel #7
0
 def tick(self):
     if g2d.key_pressed("LeftButton"):
         self._downtime = time()
     elif g2d.key_released("LeftButton"):
         mouse = g2d.mouse_position()
         x, y = mouse[0] // W, mouse[1] // H
         if 0<=mouse[0]<=W*self._game.cols() and 0<=mouse[1]<=H*self._game.rows():
             if time() - self._downtime > LONG_PRESS:
                 self._game.flag_at(x, y)
             else:
                 self._game.play_at(x, y)
         self.update_buttons()
     elif g2d.key_pressed("h"):
         if g2d.confirm("Are You Sure? The autocompletion may not complete it (for wrong moves at the beginning). Are you sure you want to continue?"):
             self._game.help()
             #self._game.help_cirle()
             #self._game.help_square()
             self.update_buttons()