Exemplo n.º 1
0
 def create_line(p0, p1, width):
     line = Line(p0, p1)
     line.setWidth(width)
     color = color_rgb(200, 200, 200)
     line.setOutline(color)
     line.setArrow("last")
     return line
Exemplo n.º 2
0
def draw_line(win, colour, point1, point2, current_tile):
    """Helper function for drawing lines."""
    current_line = Line(Point(*point1), Point(*point2))
    current_line.setWidth(2)
    current_line.setFill(colour)
    current_line.draw(win)
    current_tile.append(current_line)
Exemplo n.º 3
0
    def draw_mark(self, move: tuple) -> None:
        """ Draw a mark as specified by a move 
        :param move: a legal move: (selected_tile.x_pos, selected_tile.y_pos, player.mark)
        :return: none
        """

        if self.window is None:
            raise ValueError('Board has no open window!')

        tile_x, tile_y, mark = move

        grid_x, grid_y = self.coord_tile_to_grid(tile_x, tile_y)

        rad = self.tile_size * 0.3

        if mark == 'O':
            cir = Circle(Point(grid_x, grid_y), rad)
            cir.setOutline('blue')
            cir.setWidth(3)
            cir.draw(self.window)
        else:
            downstroke = Line(Point(grid_x - rad, grid_y - rad),
                              Point(grid_x + rad, grid_y + rad))
            upstroke = Line(Point(grid_x - rad, grid_y + rad),
                            Point(grid_x + rad, grid_y - rad))
            downstroke.setOutline('red')
            downstroke.setWidth(3)
            upstroke.setOutline('red')
            upstroke.setWidth(3)
            upstroke.draw(self.window)
            downstroke.draw(self.window)
Exemplo n.º 4
0
 def createWindow(self, N):
     """
     Create the graphics window.
     Arguments:
         self - the SkewerUI instance
         N - the capacity of the skewer
     """
     self.win = GraphWin("Shish Kebab", 800, 200)
     self.win.setCoords( \
         WIN_LOW_LEFT_X, \
         WIN_LOW_LEFT_Y - 0.1, \
         WIN_LOW_LEFT_X+(N+1)*FOOD_WIDTH, \
         WIN_UP_RIGHT_Y + 0.1 \
     )
     
     # draw skewer
     line = Line( \
         Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         Point(N, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0) \
     )
     line.setWidth(LINE_THICKNESS)
     line.draw(self.win)
     handle = Circle( \
         Point(N-.1, WIN_LOW_LEFT_Y+WIN_HEIGHT/2.0), \
         SKEWER_HANDLE_RADIUS \
     )
     handle.setFill(BKGD_COLOR)
     handle.setWidth(LINE_THICKNESS)
     handle.draw(self.win)
     self.items = []
Exemplo n.º 5
0
    def draw(self):
        if self.pulsing:
            color = 'red'
        else:
            color = 'black'

        target = self.target
        source = self.source
        line = Line(source.location, target.location)
        line.setWidth(1)
        line.setFill(color)
        line.setOutline(color)
        line.draw(self.brain.win)

        dx = target.location.x - source.location.x
        dy = target.location.y - source.location.y
        k = dy / dx if dx != 0 else dy
        k = abs(k)
        dd = 20
        sign_dx = -1 if dx < 0 else 1
        sign_dy = -1 if dy < 0 else 1
        dx = -sign_dx * dd / sqrt(k**2 + 1)
        dy = -sign_dy * k * dd / sqrt(k**2 + 1)
        # sleep(1)

        dp = Point(target.location.x + dx, target.location.y + dy)
        line = Line(dp, target.location)
        line.setWidth(3)
        line.setFill(color)
        line.draw(self.brain.win)
Exemplo n.º 6
0
    def draw_route(self, car, show_route):
        # TODO optimize to not have to redraw entire route each time
        self.clear_route(self.route)
        self.route = {}

        if not show_route:
            return

        line_width = 3
        line_color = color_rgb(20, 200, 20)
        p0 = Point(car.x, car.y)
        route = car.route[:]
        route.append(car.next_dest_id)
        for vertex_id in route[::-1]:
            intersection = self.intersections[vertex_id]
            p1 = Point(intersection.x, intersection.y)
            line = Line(p0, p1)
            line.setWidth(line_width)
            line.setOutline(line_color)
            self.route[vertex_id] = line
            p0 = p1

        old_route = {
            key: val
            for key, val in self.route.items() if key not in route
        }
        self.route = {
            key: val
            for key, val in self.route.items() if key in route
        }
        self.clear_route(old_route)

        for line in self.route.values():
            line.draw(self.canvas)
Exemplo n.º 7
0
def make_new_line(g1, g2, lines, win):
    new_line = GraphLine(g1, g2)
    lines.append(new_line)
    g1.vertex.connect_node(g2.vertex)
    handle_possible_intersections(new_line, lines, win)
    win_line = Line(g1.point, g2.point)
    win_line.setWidth(3)
    win_line.draw(win)
Exemplo n.º 8
0
def draw_arrow(win, arrow_x, arrow_y):
    """Draw an arrow onto the given graphics window."""
    arrow_shaft = Circle(Point(arrow_x, arrow_y), 0.008).draw(win)
    arrow_shaft.setFill("brown")

    for x in (1, -1):
        fletching = Line(Point(arrow_x + 0.02, arrow_y + 0.02 * x),
                         Point(arrow_x - 0.02, arrow_y - 0.02 * x)).draw(win)
        fletching.setWidth(2)
        fletching.setFill("gray")
Exemplo n.º 9
0
def draw_iks(x, y):
    global items
    line1 = Line(Point(x*SIZE+PADDING, y*SIZE+PADDING), Point((x+1)*SIZE-PADDING, (y+1)*SIZE-PADDING))
    line1.setWidth(WIDTH)
    line1.draw(win)
    items.append(line1)
    line2 = Line(Point(x*SIZE+PADDING, (y+1)*SIZE-PADDING), Point((x+1)*SIZE-PADDING, (y)*SIZE+PADDING))
    line2.setWidth(WIDTH)
    line2.draw(win)
    items.append(line2)
Exemplo n.º 10
0
 def draw_horizontal_grid_lines():
     for i_row in range(n_rows + 1):
         x0 = left_margin
         y0 = upper_margin + i_row * cell_height
         pt0 = Point(x0, y0)
         pt1 = Point(x0 + grid_width, y0)
         line = Line(pt0, pt1)
         if i_row % order == 0:
             line.setWidth(thick)
         else:
             line.setWidth(0)
         line.draw(win)
Exemplo n.º 11
0
 def draw_vertical_grid_lines():
     for i_col in range(n_cols + 1):
         x0 = left_margin + i_col * cell_height
         y0 = upper_margin
         pt0 = Point(x0, y0)
         pt1 = Point(x0, y0 + grid_height)
         line = Line(pt0, pt1)
         if i_col % order == 0:
             line.setWidth(thick)
         else:
             line.setWidth(0)
         line.draw(win)
Exemplo n.º 12
0
def draw_patch_window():
    """
    9. Write a function draw_patch_window() (without parameters) which displays, in
    a graphics window of size 100 × 100 pixels, the patch design which is
    labelled with the final digit of your student number. The patch design
    should be displayed in red, as in the table. It's important that your
    program draws the patch design accurately, but don't worry if one pixel is
    chopped off at the edge of the window. Note that you don't need to draw a
    border around the patch design.
    """
    win = GraphWin("Patch design", 100, 100)
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(0, distance), Point(distance, 0))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(100 - distance, 0), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(distance, 100), Point(100, distance))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(0, distance), Point(100 - distance, 100))
        line.setFill("red")
        line.setWidth(2)
        line.draw(win)

    win.getMouse()
    win.close()
Exemplo n.º 13
0
    def draw_winning_line(self, start: tuple, end: tuple) -> None:
        """ Draw a line through the winning series of marks """

        if self.window is None:
            raise ValueError("Board does not have an open window!")

        start_x, start_y = self.coord_tile_to_grid(start[0], start[1])
        end_x, end_y = self.coord_tile_to_grid(end[0], end[1])

        pt1 = Point(start_x, start_y)
        pt2 = Point(end_x, end_y)

        line = Line(pt1, pt2)
        line.setWidth(4)
        line.setOutline('black')
        line.draw(self.window)
Exemplo n.º 14
0
    def __init__(self):

        self.lines = frame()

        steps = range(99, 499, 100)

        for y in steps:
            line = Line(Point(0, y), Point(499, y))
            line.setFill("blue")
            line.setWidth(5)
            self.lines.append(line)

        for x in steps:
            line = Line(Point(x, 0), Point(x, 499))
            line.setFill("blue")
            line.setWidth(5)
            self.lines.append(line)
Exemplo n.º 15
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill('red')
        c.draw(win)

    win.getMouse()
    win.close()
Exemplo n.º 16
0
    def draw_grid(self, logic: bool = False) -> None:
        """ Draw the board's grid """
        window = self.window if not logic else self.logic_window
        if window is not None:
            # draw horizontals:
            for i in range(self.tile_size, self.window_height, self.tile_size):
                row_y = i
                line = Line(Point(0, row_y), Point(self.window_width, row_y))
                line.setOutline('black')
                line.setWidth(2)
                line.draw(window)

            # draw verticals
            for i in range(self.tile_size, self.window_width, self.tile_size):
                col_x = i
                line = Line(Point(col_x, 0), Point(col_x, self.window_height))
                line.setOutline('black')
                line.setWidth(2)
                line.draw(window)
Exemplo n.º 17
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("--size", type=int, default=3, help="Size of k")
    args = parser.parse_args()

    win = GraphWin("My Circle", WIN_SIZE, WIN_SIZE)

    k = args.size
    m = k * (k - 1) + 1
    r = min(pi * R / m * 0.50, 20)

    ds = DiffState(k)
    ds.search()

    points = []
    for i in range(m):
        ang = 2 * pi * i / m
        center = (CENTER[0] + R * sin(ang), CENTER[1] - R * cos(ang))
        points.append(Point(center[0], center[1]))

    if m < 20:
        for i in range(m):
            for j in range(i, m):
                if not (i in ds.current and j in ds.current):
                    l = Line(points[i], points[j])
                    l.draw(win)
                    l.setOutline(all_color)

    for i in range(m):
        for j in range(i, m):
            if i in ds.current and j in ds.current:
                l = Line(points[i], points[j])
                l.setWidth(3)
                l.draw(win)
                l.setOutline(set_color)

    for i in range(m):
        c = Circle(points[i], r)
        c.setFill("red")
        c.draw(win)

    win.getMouse()
    win.close()
Exemplo n.º 18
0
    def create_window(self, capacity):
        """
        Create the graphics window.
        :param capacity: the capacity of the skewer (for the window size)
        :return: None
        """

        self.win = GraphWin("Shish Kebab", 800, 200)
        self.win.setCoords(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y - 0.1,
                           WIN_LOW_LEFT_X + (capacity + 1) * FOOD_WIDTH,
                           WIN_UP_RIGHT_Y + 0.1)

        # draw skewer
        line = Line(Point(WIN_LOW_LEFT_X, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0),
                    Point(capacity, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0))
        line.setWidth(LINE_THICKNESS)
        line.draw(self.win)
        handle = Circle(
            Point(capacity - .1, WIN_LOW_LEFT_Y + WIN_HEIGHT / 2.0),
            SKEWER_HANDLE_RADIUS)
        handle.setFill(BKGD_COLOR)
        handle.setWidth(LINE_THICKNESS)
        handle.draw(self.win)
        self.items = []
Exemplo n.º 19
0
def draw_patch(win, x, y, colour):
    """Helper function for drawing a patch design."""
    for distance in (20, 40, 60, 80, 100):
        line = Line(Point(x, distance + y), Point(x + distance, y))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(x + 100 - distance, y), Point(x + 100, y + distance))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

    for distance in (20, 40, 60, 80):
        line = Line(Point(x + distance, y + 100), Point(x + 100, y + distance))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)

        line = Line(Point(x, y + distance), Point(x + 100 - distance, y + 100))
        line.setFill(colour)
        line.setWidth(2)
        line.draw(win)
Exemplo n.º 20
0
    def _setup(self):
        circle = Circle(Point(250, 250), self.r)  # set center and radius
        circle.setWidth(3)
        circle.draw(self.win)

        line = Line(Point(250, 225), Point(250, 285))
        line.setWidth(3)
        line.draw(self.win)

        line2 = Line(Point(280, 250), Point(250, 225))
        line2.setWidth(3)
        line2.draw(self.win)

        line3 = Line(Point(220, 250), Point(250, 225))
        line3.setWidth(3)
        line3.draw(self.win)
Exemplo n.º 21
0
 def X_make(p2):
     upper = p2.getX()
     lower = p2.getY()
     # Lower left Box
     if (p2.getX() < 2 and p2.getY() < 3):
         X_mark = Line(Point(-.5, 2.5), Point(1.5, .5))
         X_mark2 = Line(Point(-.5, .5), Point(1.5, 2.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][0] = 'X'
     # Left column middle box
     elif (p2.getX() < 2 and p2.getY() < 6):
         X_mark = Line(Point(-0.8, 5.5), Point(1.5, 3.5))
         X_mark2 = Line(Point(-.8, 3.5), Point(1.5, 5.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][0] = 'X'
     # Top left box
     elif (p2.getX() < 2 and p2.getY() < 9):
         X_mark = Line(Point(-.8, 8.5), Point(1.5, 6.5))
         X_mark2 = Line(Point(-.8, 6.5), Point(1.5, 8.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][0] = 'X'
     # Bottom row middle box
     elif (p2.getX() < 5 and p2.getY() < 3):
         X_mark = Line(Point(2.5, 2.5), Point(4.5, .5))
         X_mark2 = Line(Point(4.5, 2.5), Point(2.5, .5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][1] = 'X'
     # Middle row middle box
     elif (p2.getX() < 5 and p2.getY() < 6):
         X_mark = Line(Point(2.5, 5.5), Point(4.5, 3.5))
         X_mark2 = Line(Point(2.5, 3.5), Point(4.5, 5.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][1] = 'X'
     # Top row middle box
     elif (p2.getX() < 5 and p2.getY() < 9):
         X_mark = Line(Point(2.5, 8.5), Point(4.5, 6.5))
         X_mark2 = Line(Point(4.5, 8.5), Point(2.5, 6.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][1] = 'X'
     # Bottom row rightmost box
     elif (p2.getX() < 8 and p2.getY() < 3):
         X_mark = Line(Point(5.5, .5), Point(7.5, 2.5))
         X_mark2 = Line(Point(5.5, 2.5), Point(7.5, .5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[2][2] = 'X'
     # Right column middle box
     elif (p2.getX() < 8 and p2.getY() < 6):
         X_mark = Line(Point(5.5, 3.5), Point(7.5, 5.5))
         X_mark2 = Line(Point(5.5, 5.5), Point(7.5, 3.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[1][2] = 'X'
     # right column top box
     elif (p2.getX() < 8 and p2.getY() < 9):
         X_mark = Line(Point(5.5, 8.5), Point(7.5, 6.5))
         X_mark2 = Line(Point(5.5, 6.5), Point(7.5, 8.5))
         X_mark.setOutline('blue')
         X_mark.setWidth(3)
         X_mark2.setOutline('blue')
         X_mark2.setWidth(3)
         X_mark.draw(win)
         X_mark2.draw(win)
         board[0][2] = 'X'
Exemplo n.º 22
0
    def action():
        O_player = 0
        X_player = 0
        # This will count how many times the mouse has been clicked on the window
        Mouse_click = 0

        vert_line1 = Line(Point(.5, 0), Point(.5, 9))
        vert_line1.setWidth(3)
        vert_line2 = Line(Point(3.5, 0), Point(3.5, 9))
        vert_line2.setWidth(3)
        vert_line3 = Line(Point(6.5, 0), Point(6.5, 9))
        vert_line3.setWidth(3)

        hori_line1 = Line(Point(-1, 1.5), Point(8, 1.5))
        hori_line1.setWidth(3)
        hori_line2 = Line(Point(-1, 4.5), Point(8, 4.5))
        hori_line2.setWidth(3)
        hori_line3 = Line(Point(-1, 7.5), Point(8, 7.5))
        hori_line3.setWidth(3)

        diag_line1 = Line(Point(-1, 0), Point(8, 9))
        diag_line1.setWidth(3)
        diag_line2 = Line(Point(-1, 9), Point(8, 0))
        diag_line2.setWidth(3)

        while not winner(O_player, X_player):
            leave()
            p1_turn = Text(Point(5, -.5), 'Player 1\'s turn')
            p1_turn.draw(win)
            p1 = win.getMouse()
            Mouse_click += 1
            O_make(p1)

            # Checks for O's Vertically
            if board[2][0] == 'O':
                if board[1][0] == 'O':
                    if board[0][0] == 'O':
                        vert_line1.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break

            elif board[0][1] == 'O':
                if board[1][1] == 'O':
                    if board[2][1] == 'O':
                        vert_line2.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break

            elif board[0][2] == 'O':
                if board[1][2] == 'O':
                    if board[2][2] == 'O':
                        vert_line3.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break

            # Checks for O's horizontally
            if board[2][0] == 'O':
                if board[2][1] == 'O':
                    if board[2][2] == 'O':
                        hori_line1.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[1][0] == 'O':
                if board[1][1] == 'O':
                    if board[1][2] == 'O':
                        hori_line2.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[0][0] == 'O':
                if board[0][1] == 'O':
                    if board[0][2] == 'O':
                        hori_line3.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break

            # Checks for O's diagonally
            if board[2][0] == 'O':
                if board[1][1] == 'O':
                    if board[0][2] == 'O':
                        diag_line1.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[0][0] == 'O':
                if board[1][1] == 'O':
                    if board[2][2] == 'O':
                        diag_line2.draw(win)
                        O_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 1 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            # Checking to see if nobody won, which leads to a tie
            if Mouse_click == 9:
                Tie_Message = Text(Point(3.5, 9.5), 'It\'s a Tie!!!')
                Tie_Message.draw(win)
                quit_message = Text(Point(5, -1.5),
                                    'Click the quit button to leave.')
                quit_message.draw(win)
                win.getMouse()
                win.close()
                break

            p1_turn.undraw()
            p2_turn = Text(Point(7, -.5), 'Player 2\'s turn')
            p2_turn.draw(win)

            p2 = win.getMouse()
            Mouse_click += 1
            X_make(p2)
            p2_turn.undraw()
            # Checks X's veritcally
            if board[2][0] == 'X':
                if board[1][1] == 'X':
                    if board[0][0] == 'X':
                        vert_line1.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[2][1] == 'X':
                if board[1][1] == 'X':
                    if board[0][1] == 'X':
                        vert_line2.draw(win)
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[2][2] == 'X':
                if board[1][2] == 'X':
                    if board[0][2] == 'X':
                        vert_line3.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            # Checks X's Horizontally
            if board[2][0] == 'X':
                if board[2][1] == 'X':
                    if board[2][2] == 'X':
                        hori_line1.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[1][0] == 'X':
                if board[1][1] == 'X':
                    if board[1][2] == 'X':
                        hori_line2.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[0][0] == 'X':
                if board[0][1] == 'X':
                    if board[0][2] == 'X':
                        hori_line3.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            if board[2][0] == 'X':
                if board[1][1] == 'X':
                    if board[0][2] == 'X':
                        diag_line1.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
            elif board[0][0] == 'X':
                if board[1][1] == 'X':
                    if board[2][2] == 'X':
                        diag_line2.draw(win)
                        X_player += 1
                        win_message = Text(Point(3.5, 9.5), 'Player 2 wins!!!')
                        win_message.draw(win)
                        quit_message = Text(Point(5, -1.5),
                                            'Click the quit button to leave.')
                        quit_message.draw(win)
                        win.getMouse()
                        win.close()
                        break
Exemplo n.º 23
0
from graphics import GraphWin, Line, Circle, Oval, Point

win = GraphWin(width=620, height=250)

line = Line(Point(10, 10), Point(190, 190))
line.setWidth(2)
line.draw(win)

circle = Circle(Point(350, 110), 100)
circle.setWidth(2)
circle.draw(win)

ellipse = Oval(Point(510, 10), Point(610, 190))
ellipse.setWidth(2)
ellipse.draw(win)

win.getMouse()
Exemplo n.º 24
0
frown_cover.setWidth(0)
frown_cover.draw(win)

# Tongue - Circle & Polygon Combo with Black Vertical Line
tongue_tip = Circle(Point(299, 405), 30)
tongue_tip.setFill(color_rgb(90, 255, 84))
tongue_tip.setWidth(3)
tongue_tip.draw(win)

tongue = Rectangle(Point(269, 403), Point(329, 348))
tongue.setFill(color_rgb(90, 255, 84))
tongue.setWidth(0)
tongue.draw(win)

tongue_ctr = Line(Point(299, 348), Point(299, 385))
tongue_ctr.setWidth(4)
tongue_ctr.draw(win)

tongue_edge_L = Line(Point(269, 348), Point(269, 410))
tongue_edge_L.setFill('black')
tongue_edge_L.setWidth(3)
tongue_edge_L.draw(win)

tongue_edge_R = tongue_edge_L.clone()
tongue_edge_R.move(60, 0)
tongue_edge_R.draw(win)

# Black Border
border = Circle(Point(299, 299), 350)
border.setFill('')
border.setWidth(200)
Exemplo n.º 25
0
def pause_menu(right):

	start = 500 if right else 0
	prior = len(gw.items)

	pause_overlay = Image(Point(500, 250), MAP / "pause_overlay.png")
	pause_overlay.draw(gw)


	# Everything for the Character Information
	info_box = Rectangle(Point(551 - start, 100), Point(959 - start, 400))
	info_box.setFill(color_rgb(50, 50, 50))
	info_box.setWidth(3)
	info_box.draw(gw)

	# The Character Icon
	info_icon = Image(Point(613 - start, 163), MAPS / "characters" / f"{player.character_class}_portrait.png")
	info_icon.draw(gw)

	# Shows the Header that includes the player's name and level.
	info_header = Text(Point(572 - start, 179))
	info_header.setAnchor("w")
	info_header.setSize(22)
	info_header.setText(f"      {player.name + f'LV: {player.lvl}'.rjust(16)[len(player.name):]}\n      HP:\n      EXP:\nItems:")
	info_header.draw(gw)

	# Draw the HP bar.
	hp_bar = Bar(player.current_HP, player.base_HP, "red", Point(750 - start, 149), Point(948 - start, 173))
	hp_bar.show()


	# Draws the EXP bar
	exp_bar = Bar(player.current_EXP, player.next_EXP, "green", Point(750 - start, 179), Point(948 - start, 203))
	exp_bar.show()

	# Lists off the player's current inventory.
	info_header_underline = Line(Point(573 - start, 240), Point(937 - start, 240))
	info_header_underline.setWidth(1)
	info_header_underline.setOutline("white")
	info_header_underline.draw(gw)
	info_footer = Text(Point(573 - start, 246))
	info_footer.setAnchor("nw")
	info_footer.setSize(14)
	info_footer.setText(inventory())
	info_footer.draw(gw)

	
	# Lists off the pause menu options.
	choice_box = Rectangle(Point(start + 125, 165), Point(start + 370, 335))
	choice_box.setFill(color_rgb(50, 50, 50))
	choice_box.setWidth(3)
	choice_box.draw(gw)

	choice_text = Text(Point(start + 260, 250))
	choice_text.setAnchor("c")
	choice_text.setSize(20)
	choice_text.setText("Resume\nDrink Potion\nEat Apple\nSave Game\nQuit Game")
	choice_text.draw(gw)
	

	selector = Polygon(Point(start + 137, 183), Point(start + 137, 195), Point(start + 154, 189))
	selector.setFill("red")
	selector.draw(gw)

	selection = 0
	saved = False

	while True:
		
		while True:
			key = gw.checkKey().lower()

			if key != "":
				if key in ["space", "return"]:
					break

				elif key in ["escape"]:
					while selection > 0:
						selector.move(0, -30)
						selection -= 1


				if key in ["up", "w", "left", "a"]:
					selection = (selection - 1) % 5
					if selection != 4:
						selector.move(0, -30)
					else:
						selector.move(0, 120)


				elif key in ["down", "s", "right", "d"]:
					selection = (selection + 1) % 5
					if selection != 0:
						selector.move(0, 30)
					else:
						selector.move(0, -120)

		# Resume Game
		if selection == 0:
			for i in gw.items[prior:]: i.undraw()
			return

		# Drink Potion
		if selection == 1:
			if player.items["Potions"] == 0:
				dialogue("You have no more potions to drink.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Potions"] -= 1
				player.current_HP += round(randint(4, 10) * 4.2)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Eat Apple
		if selection == 2:
			if player.items["Apples"] == 0:
				dialogue("You have no more apples to eat.", right=right)
			elif player.current_HP == player.base_HP:
				dialogue("You are already at max HP", right=right)
			else:
				player.items["Apples"] -= 1
				player.current_HP += randint(1, 4)
				if player.current_HP > player.base_HP:
					player.current_HP = player.base_HP
				hp_bar.update(player.current_HP, player.base_HP)

		# Save Game
		if selection == 3:
			saved = True
			save_state = open("save_state.txt", "w")  
			
			stats_to_save = [player.character_class, player.name, player.lvl, player.attack, player.defense, 
				player.current_HP, player.base_HP, player.current_SP, player.base_SP, player.current_EXP, player.next_EXP,
				player.gold, player.items, game_stats
			]

			line_to_save = ''
			for i in stats_to_save:
				line_to_save = line_to_save + str(i) + "\n"

			save_state.write(b64encode(line_to_save.encode("UTF-8")).decode("UTF-8"))
			save_state.close()

			dialogue("Game saved.", right=right)

		# Quit Game
		if selection == 4:

			if not saved:
				dialogue(f"You have not saved recently.")

			if dialogue("Are you sure you want to quit?", ["Yes", "No"], right=right) == 0:
				raise GameOver('Town Quit')

		info_footer.setText(inventory())