Exemplo n.º 1
0
    def __init__(self, width: int, height: int, tiles: list, client):
        """
        :param width: Max screen width.
        :param height: Max screen height.
        :param tiles: A 2D list of integer values representing tile types.
        :param client: A client object for server communication.
        """
        super().__init__()

        self.client = client
        self.my_turn = False
        self.cur_enemy = ""

        self.SCREEN_WIDTH = width
        self.SCREEN_HEIGHT = height
        self.SCROLL_STEP_X = SCROLL_STEP * width
        self.SCROLL_STEP_Y = SCROLL_STEP * height
        self.TILE_ROWS = len(tiles)
        self.TILE_COLS = len(tiles[0])
        self.zoom = 0

        self.top_bar = TopBar(None, TOP_BAR_SIZE)
        self.unit_popup = UnitPopup(4 * TOP_BAR_SIZE, 4 * TOP_BAR_SIZE)
        self.update_popup = False  # used to only update pop-up once per opponent's move, otherwise game is laggy
        self.update_topbar = False  # used to update top bar if my city has been taken
        self.update_diplo = None  # will be updated to a tuple of (message, sender, is_rejectable)
        self.diplo_answered = threading.Event()
        self.city_popup = CityCreationPopup(4 * TOP_BAR_SIZE, 5 * TOP_BAR_SIZE)
        self.diplo_popup = DiplomaticPopup(9 * TOP_BAR_SIZE, 3 * TOP_BAR_SIZE, self.diplo_answered)
        self.end_popup = EndingPopup(6 * TOP_BAR_SIZE, 6 * TOP_BAR_SIZE)
        self.ranking = None
        self.tiles = tiles

        self.tile_sprites = arcade.SpriteList()
        # needs to be smarter tbh but depends on the size of a real map
        self.tile_size = int((height - self.top_bar.height) / self.TILE_ROWS) - MARGIN
        # in order to center the tiles vertically and horizontally
        self.centering_x = (width - self.TILE_COLS * (self.tile_size + MARGIN)) / 2
        self.centering_y = ((height - self.top_bar.height) - self.TILE_ROWS * (self.tile_size + MARGIN)) / 2

        for row in range(self.TILE_ROWS):
            for col in range(self.TILE_COLS):
                tile = Tile(col, row, self.tile_size, tiles[row][col])
                tile.center_x = col * (self.tile_size + MARGIN) + (self.tile_size / 2) + MARGIN + self.centering_x
                tile.center_y = row * (self.tile_size + MARGIN) + (self.tile_size / 2) + MARGIN + self.centering_y
                self.tile_sprites.append(tile)

        self.game_logic = GameLogic(self.tile_sprites, self.TILE_ROWS, self.TILE_COLS, self.client.players,
                                    self.client.nick)
        self.top_bar.me = self.game_logic.me
        self.city_view = CityView(self.top_bar)
        self.enemy_city_view = EnemyCityView(self.top_bar, self.city_view.app, self.client, self.game_logic.me)
        self.top_bar.update_treasury()

        threading.Thread(target=self.wait_for_my_turn).start()
Exemplo n.º 2
0
 def setUp(self) -> None:
     self.tiles = []
     # these have to be added in the order of bottom to top, left to right in order for get_tile(x, y) to work
     # so (0, 0), (1, 0), .... (COLUMNS_NUMBER-1, 0), (0, 1), (1, 1), ...
     # this is a linear map with, from left to right, a column of water, plains, hills, plains, mountains
     for y in range(5):
         self.tiles.append(Tile(0, y, 1, 0))
         self.tiles.append(Tile(1, y, 1, 1))
         self.tiles.append(Tile(2, y, 1, 2))
         self.tiles.append(Tile(3, y, 1, 1))
         self.tiles.append(Tile(4, y, 1, 3))
     self.game_logic = GameLogic(self.tiles, 5, 5, players=[("one", CIV_ONE, "gray"), ("two", CIV_TWO, "red")],
                                 my_nick="one")
Exemplo n.º 3
0
    def test_free_market_2(self):
        self.city.area.append(Tile(0, 0, 1, 0))

        before_goods = self.city.calculate_goods()
        self.city.buildings["Free Market"] = True
        after_goods = self.city.calculate_goods()
        self.assertEqual(after_goods["gold"], before_goods["gold"] + len(self.city.area) * 3)
Exemplo n.º 4
0
 def setUp_bigger(self):
     self.tiles = []
     for x in range(20):
         for y in range(20):
             self.tiles.append(Tile(x, y, 1, 1))
     self.game_logic = GameLogic(self.tiles,
                                 20,
                                 20,
                                 players=[("one", CIV_ONE, "gray"),
                                          ("two", CIV_TWO, "red")],
                                 my_nick="one")
     self.game_logic.add_unit(10, 10, "one", 'Settler', 1)
     settler = self.game_logic.get_tile(10, 10).occupant
     self.game_logic.build_city(settler, "stub")
Exemplo n.º 5
0
    def setUp(self) -> None:
        self.tiles = []
        # these have to be added in the order of bottom to top, left to right in order for get_tile(x, y) to work
        # so (0, 0), (1, 0), .... (COLUMNS_NUMBER-1, 0), (0, 1), (1, 1), ...
        # this is a linear map with, from left to right, a column of water, plains, hills, plains, mountains
        for y in range(5):
            self.tiles.append(Tile(0, y, 1, 0))
            self.tiles.append(Tile(1, y, 1, 1))
            self.tiles.append(Tile(2, y, 1, 2))
            self.tiles.append(Tile(3, y, 1, 1))
            self.tiles.append(Tile(4, y, 1, 3))
        self.game_logic = GameLogic(self.tiles, 5, 5, players=[("one", CIV_ONE, "gray"), ("two", CIV_TWO, "red")],
                                    my_nick="one")
        self.game_logic.add_unit(2, 2, "one", 'Settler', 1)
        self.settler = self.game_logic.get_tile(2, 2).occupant

        self.area = []
        self.area.append(Tile(0, 1, 1, 0))
        self.area.append(Tile(1, 1, 1, 0))
        self.area.append(Tile(2, 1, 1, 1))
        self.area.append(Tile(2, 2, 1, 2))
        self.area.append(Tile(0, 0, 1, 2))
        self.area.append(Tile(1, 2, 1, 3))

        self.game_logic.build_city(self.settler, "test_name")
        self.tile = self.settler.tile
        self.city = self.tile.city