From d2d4a9bdc35a8344adb0ef7b4d8e989c0144d5d7 Mon Sep 17 00:00:00 2001 From: matixezor Date: Mon, 15 Mar 2021 21:10:23 +0100 Subject: [PATCH] remove excess attrs from agent, adjust game_ui to this change --- src/agent.py | 4 +--- src/game_ui.py | 18 +++++++++++------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/agent.py b/src/agent.py index a67276e..e80e88d 100644 --- a/src/agent.py +++ b/src/agent.py @@ -2,9 +2,7 @@ from const import SAPPER_IDLE class Agent: - def __init__(self, x: int = 0, y: int = 0, x_px: int = 0, y_px: int = 0): + def __init__(self, x: int = 0, y: int = 0): self.img = SAPPER_IDLE - self.x_px = x_px - self.y_px = y_px self.x = x self.y = y diff --git a/src/game_ui.py b/src/game_ui.py index 543a05c..85b9123 100644 --- a/src/game_ui.py +++ b/src/game_ui.py @@ -1,4 +1,4 @@ -import pygame +import pygame as pg from agent import Agent from environment import Environment @@ -9,13 +9,17 @@ class GameUi: def __init__(self, agent: Agent, env: Environment): self.agent = agent self.env = env - self.clock = pygame.time.Clock() - self.screen = pygame.display.set_mode((WIDTH, HEIGHT)) + self.clock = pg.time.Clock() + self.screen = pg.display.set_mode((WIDTH, HEIGHT)) def move(self, coord: str, shift: int): - setattr(self.agent, coord, getattr(self.agent, coord) + shift) for x in range(8): - setattr(self.agent, f'{coord}_px', getattr(self.agent, f'{coord}_px') + (shift * 10)) + setattr( + self.agent, + coord, + getattr(self.agent, coord) + (shift/8) if x != 7 + else int(getattr(self.agent, coord) + (shift/8)) + ) self.agent.img = SAPPER_RUNNING[x % 2] self.update() self.clock.tick(15) @@ -26,5 +30,5 @@ class GameUi: for x in range(10): for y in range(10): self.screen.blit(IMAGES[self.env.field[y][x]], (x * 80, y * 80)) - self.screen.blit(self.agent.img, (self.agent.x_px, self.agent.y_px)) - pygame.display.update() + self.screen.blit(self.agent.img, (self.agent.x * 80, self.agent.y * 80)) + pg.display.update()