remove excess attrs from agent, adjust game_ui to this change
This commit is contained in:
parent
eba1b5cb41
commit
d2d4a9bdc3
@ -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
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user