Skip to content

Commit

Permalink
display server info
Browse files Browse the repository at this point in the history
  • Loading branch information
vpoulailleau committed Apr 12, 2024
1 parent cb3db93 commit da7b557
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 11 deletions.
4 changes: 2 additions & 2 deletions space_collector/viewer/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ def resize(self, small_window: bool):
self.SCORE_WIDTH = 500
self.SCORE_MARGIN = 100
self.SCORE_FONT_SIZE = 24
self.SCORE_TEAM_SIZE = 200
self.SCORE_TEAM_SIZE = 190
self.MAP_MARGIN = 170
else:
self.SCREEN_WIDTH = 800
self.SCREEN_HEIGHT = 600
self.SCORE_WIDTH = 300
self.SCORE_MARGIN = 50
self.SCORE_FONT_SIZE = 20
self.SCORE_TEAM_SIZE = 100
self.SCORE_TEAM_SIZE = 105
self.MAP_MARGIN = 50

self.SCORE_TIME_MARGIN = 100
Expand Down
19 changes: 15 additions & 4 deletions space_collector/viewer/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ class TeamData:


class Score:
def __init__(self):
def __init__(self, addr: str, port: int):
self.sprite_list = arcade.SpriteList()
self.teams_data: list[TeamData] = []
self.time = 0
self.nb_planets = None
self.port = port
self.addr = addr

def setup(self) -> None:
font_file = files("space_collector.viewer").joinpath("images/Sportrop.ttf")
Expand All @@ -81,6 +83,15 @@ def draw(self) -> None:
2,
size=constants.SCORE_FONT_SIZE,
)
draw_text(
f"{self.addr}:{self.port}",
constants.SCORE_MARGIN,
constants.SCORE_HEIGHT
- constants.SCORE_TIME_MARGIN
- constants.SCORE_TEAM_SIZE // 4,
1,
size=constants.SCORE_FONT_SIZE,
)
for index, team_data in enumerate(
sorted(self.teams_data, key=lambda td: td.score)
):
Expand All @@ -97,22 +108,22 @@ def draw(self) -> None:
draw_text(
"BLOCKED",
constants.SCORE_MARGIN,
team_offset - constants.SCORE_TEAM_SIZE // 5,
team_offset - constants.SCORE_TEAM_SIZE // 4,
team_data.team,
size=constants.SCORE_FONT_SIZE - 5,
)
else:
draw_text(
f"Score: {team_data.score}",
constants.SCORE_MARGIN,
team_offset - constants.SCORE_TEAM_SIZE // 5,
team_offset - constants.SCORE_TEAM_SIZE // 4,
team_data.team,
size=constants.SCORE_FONT_SIZE - 5,
)
draw_text(
f"Planets: {team_data.nb_saved_planets}/{team_data.nb_planets}",
constants.SCORE_MARGIN,
team_offset - 2 * constants.SCORE_TEAM_SIZE // 5,
team_offset - 2 * constants.SCORE_TEAM_SIZE // 4,
team_data.team,
size=constants.SCORE_FONT_SIZE - 5,
)
Expand Down
2 changes: 1 addition & 1 deletion space_collector/viewer/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ def __init__(self, server_addr: str, port: int) -> None:
logging.info("Start network")
Thread(target=network_thread, daemon=True, args=[server_addr, port]).start()
logging.info("Start GUI")
gui_thread()
gui_thread(server_addr, port)
8 changes: 4 additions & 4 deletions space_collector/viewer/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@


class Window(arcade.Window):
def __init__(self) -> None:
def __init__(self, addr: str, port: int) -> None:
super().__init__(
constants.SCREEN_WIDTH, constants.SCREEN_HEIGHT, constants.SCREEN_TITLE
)
arcade.set_background_color(arcade.csscolor.BLACK)
self.background = SpaceBackground()
self.score = Score()
self.score = Score(addr, port)
self.players: list[Player] = [Player(team) for team in range(4)]

def setup(self) -> None:
Expand Down Expand Up @@ -49,8 +49,8 @@ def on_draw(self):
self.score.draw()


def gui_thread() -> None:
window = Window()
def gui_thread(addr: str, port: int) -> None:
window = Window(addr, port)
try:
window.setup()
arcade.run()
Expand Down

0 comments on commit da7b557

Please sign in to comment.