Ejemplo n.º 1
0
 def __init__(self, game: GameView, grid_size: int):
     """Square grid, with a little space
     around the tiles.
     Args:
        game: The surrounding GameView object
     """
     self.game = game
     self.win = game.win
     self.background = graphics.Rectangle(
         graphics.Point(0, 0), graphics.Point(game.width, game.height))
     self.background.setFill("wheat")
     self.background.draw(self.win)
     self.cell_width = (game.width - MARGIN) / grid_size
     self.tile_width = self.cell_width - MARGIN
     self.cell_height = (game.height - MARGIN) / grid_size
     self.tile_height = self.cell_height - MARGIN
     self.tiles = []
     # Initially empty tile spaces
     for row in range(grid_size):
         row_tiles = []
         for col in range(grid_size):
             ul, lr = self.tile_corners(row, col)
             tile_background = graphics.Rectangle(ul, lr)
             tile_background.setFill("grey")
             tile_background.setOutline("white")
             tile_background.draw(self.win)
             row_tiles.append(tile_background)
         self.tiles.append(row_tiles)
Ejemplo n.º 2
0
 def tile_corners(self, r, c):
     top_left = m + c * self.cell_h_w
     top_right = top_left + self.tile_h_w
     bottom_left = m + r * self.cell_h_w
     bottom_right = bottom_left + self.tile_h_w
     left = g.Point(top_left, bottom_left)
     right = g.Point(top_right, bottom_right)
     return left, right
Ejemplo n.º 3
0
 def tile_corners(self, row, col):
     """upper left and lower right corners of tile at row,col"""
     ul_x = MARGIN + col * self.cell_width
     lr_x = ul_x + self.tile_width
     ul_y = MARGIN + row * self.cell_height
     lr_y = ul_y + self.tile_height
     ul = graphics.Point(ul_x, ul_y)
     lr = graphics.Point(lr_x, lr_y)
     return ul, lr
Ejemplo n.º 4
0
 def draw_segment(self, p1, p2, color="green"):
     """Draw segment between two points. Returns an identifier
     that can be used to erase that segment later.
     """
     p1_screen = self.tx.transform_pt(p1)
     p2_screen = self.tx.transform_pt(p2)
     seg = graphics.Line(graphics.Point(p1_screen.x, p1_screen.y),
                         graphics.Point(p2_screen.x, p2_screen.y))
     seg.setOutline(color)
     seg.draw(self.win)
     return seg
Ejemplo n.º 5
0
    def __init__(self, points):
        self.shape = Shape.Shape(points)
        self.name = "test"

        newPoints = []
        for point in self.shape.points:
            newPoints.append(graphics.Point(point.x, point.y))

        center = graphics.Point(self.shape.polygon.centroid.coords.xy[0].pop(),
                                self.shape.polygon.centroid.coords.xy[1].pop())

        self.mapText = graphics.Text(center, self.name)
Ejemplo n.º 6
0
 def bar(self, col: int, height: int, color, frac_width=1.0):
     if col > self.ncols:
         log.debug(f"Column {col} off chart")
         return
     thin_by = (1.0 - frac_width) * self.col_width
     right = col * self.col_width - thin_by
     left = (col - 1) * self.col_width + thin_by
     bottom = self.height
     top = self.height - (height * self.unit_height
                          )  # Measuring from top of window
     r = graphics.Rectangle(graphics.Point(left, bottom),
                            graphics.Point(right, top))
     r.setFill(color)
     r.draw(self.win)
Ejemplo n.º 7
0
 def __init__(self, grid: GridView, tile: model.Tile):
     """Display the tile on the grid.
     Internally there are actually two graphics objects:
     A background rectangle and text within it. The
     background rectangle has a visible outline until
     the first time it moves.
     """
     self.grid = grid
     self.win = grid.win
     self.row = tile.row
     self.col = tile.col
     self.value = tile.value
     ul, lr = grid.tile_corners(self.row, self.col)
     background = graphics.Rectangle(ul, lr)
     background.setFill(RAMP[self.value])
     background.setOutline(TILE_OUTLINE_NEW)
     self.background = background
     cx = (ul.getX() + lr.getX()) / 2.0
     cy = (ul.getY() + lr.getY()) / 2.0
     center = graphics.Point(cx, cy)
     label = graphics.Text(center, str(self.value))
     label.setSize(36)
     self.label = label
     background.draw(self.win)
     label.draw(self.win)
Ejemplo n.º 8
0
 def __init__(self, grid, r, c, color, val):
     super().__init__()
     self.grid = grid
     self.r = r
     self.c = c
     self.color = color
     self.val = val
     self.pos = g.Point(r, c)
Ejemplo n.º 9
0
 def __init__(self, game, grid_size):
     self.game = game
     self.win = game.win
     self.bg = g.Rectangle(g.Point(0, 0), g.Point(game.h_w, game.h_w))
     self.bg.setFill(black)
     self.bg.draw(self.win)
     self.cell_h_w = (game.h_w - m) / grid_size
     self.tile_h_w = self.cell_h_w - m
     self.tiles = []
     for r in range(grid_size):
         row_tiles = []
         for c in range(grid_size):
             left, right = self.tile_corners(r, c)
             tile_bg = g.Rectangle(left, right)
             tile_bg.setFill(white)
             tile_bg.draw(self.win)
             row_tiles.append(tile_bg)
         self.tiles.append(row_tiles)
Ejemplo n.º 10
0
    def __init__(self):

        self.map = Map()
        self.menu = Menu(self.map.window)
        self.messageBoard = MessageBoard(self.map.window,
                                         graphics.Point(300, 400),
                                         graphics.Point(500, 500))
        self.turn_indicator = MessageBoard(self.map.window,
                                           graphics.Point(200, 450),
                                           graphics.Point(300, 500))
        self.event_box = MessageBoard(self.map.window, graphics.Point(300, 0),
                                      graphics.Point(500, 100))

        self.nations = []
        self.regions = []

        self.load_nations()

        self.map.regions = self.regions
        self.selectedNation = None

        self.player_nation = self.nations[0]
        self.player_turn = True

        print(self.nations[0])
Ejemplo n.º 11
0
 def __init__(self,
              pxwidth: int,
              pxheight: int,
              ncols: int,
              v_min: int,
              v_max: int,
              autoflush=True,
              title="Chart",
              background=graphics.color_rgb(255, 255, 255)):
     self.width = pxwidth
     self.height = pxheight
     self.ncols = ncols
     self.win = graphics.GraphWin("Chart",
                                  pxwidth,
                                  pxheight,
                                  autoflush=autoflush)
     bkgrnd = graphics.Rectangle(graphics.Point(0, 0),
                                 graphics.Point(pxwidth, pxheight))
     bkgrnd.setFill(background)
     self.col_width = pxwidth / ncols
     self.unit_height = pxheight / (v_max - v_min)
     self._last_update = time.time()
Ejemplo n.º 12
0
 def lose(self, score=0):
     """Display 'Game Over' and close after next keystroke"""
     center = graphics.Point(self.width / 2.0, self.height / 2.0)
     if score:
         goodbye = "Game over. Your score: {}".format(score)
     else:
         goodbye = "Game over"
     splash = graphics.Text(center, goodbye)
     splash.setFace("times roman")
     splash.setSize(36)  # The largest font size supported by graphics.py
     splash.setTextColor("red")
     splash.draw(self.win)
     self.get_key()
     self.close()
Ejemplo n.º 13
0
    def __init__(self, window: graphics.GraphWin):
        self.nation = None
        self.window = window

        position1 = graphics.Point(0, 400)
        position2 = graphics.Point(200, 500)

        self.rect = graphics.Rectangle(position1, position2)
        self.rect.setOutline("black")
        self.rect.setFill("grey")

        self.text = None

        self.attackButton = Button('Attack', graphics.Point(0, 400), graphics.Point(50, 425))
        self.recruitButton = Button('Recruit', graphics.Point(50,400), graphics.Point(100, 425))
        self.recruit_amount = graphics.Entry(graphics.Point(125, 412.5), 4)
Ejemplo n.º 14
0
 def __init__(self, grid, t):
     self.grid = grid
     self.win = grid.win
     self.r = t.r
     self.c = t.c
     self.val = t.val
     left, right = grid.tile_corners(self.r, self.c)
     white = g.Rectangle(left, right)
     white.setFill(xo_colors[self.val])
     self.bg = white
     x = (left.getX() + right.getX()) / 2
     y = (left.getY() + right.getY()) / 2
     center = g.Point(x, y)
     label = g.Text(center, self.val)
     label.setSize(36)
     if self.val in nums:
         label.setFill("white")
     self.label = label
     white.draw(self.win)
     label.draw(self.win)
     self.x = x
     self.y = y
Ejemplo n.º 15
0
from graphics import graphics
from shapely import geometry

from nation import Nation

size = (1000, 1000)
window = graphics.GraphWin("Map", size[0], size[1])
window.setCoords(0, 0, 500, 500)
nations = []
points = []
graphics_points = []

rect = graphics.Rectangle(graphics.Point(0, 400), graphics.Point(200, 500))
rect.setFill("grey")
rect.draw(window)

previous_point = None

name_box = graphics.Entry(rect.getCenter(), 10)
name_box.draw(window)

color_box = graphics.Entry(rect.getCenter(), 10)
color_box.move(0, -30)
color_box.draw(window)
while True:
    clickedPoint = window.getMouse()

    if 0 < clickedPoint.getX() < 200 and 400 < clickedPoint.getY() < 500:
        tempNation = Nation(name_box.getText(), color_box.getText(), 1000,
                            points)
Ejemplo n.º 16
0
 def to_graphics_points(self):
     graphics_points: List[graphics.Point] = []
     for point in self.points:
         graphics_points.append(graphics.Point(point.x, point.y))
     return graphics_points
Ejemplo n.º 17
0
    def find_correct_tile(self):
        v = 0
        x_positions = []
        for r in range(self.s):
            for c in range(self.s):
                if self.tiles[r][c].val == "X":
                    x_positions.append(g.Point(r, c))
        p1 = x_positions[0]
        p2 = x_positions[1]
        if (p2.x - p1.x == 1 and p2.y == p1.y):
            if p2.x == 2:
                value = self.tiles[int(p2.x - 2)][int(p1.y)].val
                v = self.tiles[int(p2.x - 2)][int(p1.y)]
                if value == "O":
                    v = 0
            else:
                value = self.tiles[int(p2.x + 1)][int(p1.y)].val
                v = self.tiles[int(p2.x + 1)][int(p1.y)]
                if value == "O":
                    v = 0
        if (p2.y - p1.y == 1 and p2.x == p1.x):
            if p2.y == 2:
                value = self.tiles[int(p1.x)][int(p2.y - 2)].val
                v = self.tiles[int(p1.x)][int(p2.y - 2)]
                if value == "O":
                    v = 0
            else:
                value = self.tiles[int(p1.x)][int(p2.y + 1)].val
                v = self.tiles[int(p1.x)][int(p2.y + 1)]
                if value == "O":
                    v = 0
        if (p2.x - p1.x == 2 and p2.y == p1.y):
            if p2.x == 2:
                value = self.tiles[int(p2.x - 1)][int(p1.y)].val
                v = self.tiles[int(p2.x - 1)][int(p1.y)]
                if value == "O":
                    v = 0
        if (p2.y - p1.y == 2 and p2.x == p1.x):
            if p2.y == 2:
                value = self.tiles[int(p1.x)][int(p2.y - 1)].val
                v = self.tiles[int(p1.x)][int(p2.y - 1)]
                if value == "O":
                    v = 0

        # Diagonals
        if (p1.x == 0 and p1.y == 0):
            if (p2.x == 1 and p2.y == 1):
                value = self.tiles[2][2].val
                v = self.tiles[2][2]
                if value == "O":
                    v = 0
            if (p2.x == 2 and p2.y == 2):
                value = self.tiles[1][1].val
                v = self.tiles[1][1]
                if value == "O":
                    v = 0
        if (p1.x == 1 and p1.y == 1 and p2.x == 2 and p2.y == 2):
            value = self.tiles[0][0].val
            v = self.tiles[0][0]
            if value == "O":
                v = 0

        if (p2.x == 0 and p2.y == 0):
            if (p1.x == 1 and p1.y == 1):
                value = self.tiles[2][2].val
                v = self.tiles[2][2]
                if value == "O":
                    v = 0
            if (p1.x == 2 and p1.y == 2):
                value = self.tiles[1][1].val
                v = self.tiles[1][1]
                if value == "O":
                    v = 0
        if (p2.x == 1 and p2.y == 1 and p1.x == 2 and p1.y == 2):
            value = self.tiles[0][0].val
            v = self.tiles[0][0]
            if value == "O":
                v = 0

        if (p1.x == 0 and p1.y == 2):
            if (p2.x == 1 and p2.y == 1):
                value = self.tiles[2][0].val
                v = self.tiles[2][0]
                if value == "O":
                    v = 0
            if (p2.x == 2 and p2.y == 0):
                value = self.tiles[1][1].val
                v = self.tiles[1][1]
                if value == "O":
                    v = 0
        if (p1.x == 1 and p1.y == 1 and p2.x == 2 and p2.y == 0):
            value = self.tiles[0][2].val
            v = self.tiles[0][2]
            if value == "O":
                v = 0

        if (p2.x == 0 and p2.y == 2):
            if (p1.x == 1 and p1.y == 1):
                value = self.tiles[2][0].val
                v = self.tiles[2][0]
                if value == "O":
                    v = 0
            if (p1.x == 2 and p1.y == 0):
                value = self.tiles[1][1].val
                v = self.tiles[1][1]
                if value == "O":
                    v = 0
        if (p2.x == 1 and p2.y == 1 and p1.x == 2 and p1.y == 0):
            value = self.tiles[0][2].val
            v = self.tiles[0][2]
            if value == "O":
                v = 0

        return v