forked from s464965/WMICraft
smart logs
This commit is contained in:
parent
c1d05eb1d1
commit
38b1d3eb68
@ -86,7 +86,7 @@ class Game:
|
||||
running = True
|
||||
grid = Grid(self.tiles)
|
||||
stats = Stats()
|
||||
logs = Logs()
|
||||
logs = Logs(self.screen)
|
||||
|
||||
knights_sprite_group = pygame.sprite.Group()
|
||||
monsters_sprite_group = pygame.sprite.Group()
|
||||
@ -118,7 +118,7 @@ class Game:
|
||||
castle_spawn.spawn()
|
||||
|
||||
# grid.put_on_tile(0, 0, knights_left[0])
|
||||
|
||||
i = 0 # log testing
|
||||
while running:
|
||||
self.screen.blit(self.bg, (0, 0))
|
||||
|
||||
@ -129,10 +129,13 @@ class Game:
|
||||
if event.type == pygame.KEYDOWN:
|
||||
if event.key == pygame.K_ESCAPE:
|
||||
running = False
|
||||
if event.key == pygame.K_SPACE: # log testing
|
||||
logs.enqueue_log(f'AI: Zmiana pozycji na (4, {i}).')
|
||||
i = i + 1
|
||||
|
||||
grid.update(self.screen)
|
||||
stats.draw(self.screen)
|
||||
logs.draw(self.screen)
|
||||
logs.draw()
|
||||
|
||||
knights_sprite_group.draw(self.screen)
|
||||
monsters_sprite_group.draw(self.screen)
|
||||
|
29
ui/logs.py
29
ui/logs.py
@ -1,3 +1,5 @@
|
||||
from queue import Queue
|
||||
|
||||
import pygame
|
||||
|
||||
from common.colors import FONT_DARK, ORANGE, WHITE
|
||||
@ -6,20 +8,31 @@ from common.helpers import draw_text
|
||||
|
||||
|
||||
class Logs:
|
||||
def __init__(self):
|
||||
self.grid = []
|
||||
def __init__(self, screen):
|
||||
self.log_queue = Queue(maxsize=7)
|
||||
self.screen = screen
|
||||
|
||||
def draw(self, screen):
|
||||
def draw(self):
|
||||
x = (GRID_CELL_PADDING + GRID_CELL_WIDTH) * COLUMNS + BORDER_WIDTH + 15
|
||||
y = 470
|
||||
|
||||
# background
|
||||
pygame.draw.rect(screen, WHITE, pygame.Rect(x, y, 340, 323), 0, BORDER_RADIUS)
|
||||
pygame.draw.rect(self.screen, WHITE, pygame.Rect(x, y, 340, 323), 0, BORDER_RADIUS)
|
||||
|
||||
# title
|
||||
draw_text('LOGS', FONT_DARK, screen, x + 120, y + 10, 36)
|
||||
pygame.draw.rect(screen, ORANGE, pygame.Rect(x, y + 65, 340, 3))
|
||||
draw_text('LOGS', FONT_DARK, self.screen, x + 120, y + 10, 36)
|
||||
pygame.draw.rect(self.screen, ORANGE, pygame.Rect(x, y + 65, 340, 3))
|
||||
|
||||
# texts
|
||||
draw_text('AI Blue: Zniszczyła fortecę (4, 8).', FONT_DARK, screen, x + 35, y + 90, 16)
|
||||
draw_text('AI Red: Zniszczyła fortecę (12, 5).', FONT_DARK, screen, x + 35, y + 120, 16)
|
||||
next_y = y + 90
|
||||
i = 0
|
||||
start = len(self.log_queue.queue) - 1
|
||||
for idx in range(start, -1, -1):
|
||||
draw_text(self.log_queue.queue[idx], FONT_DARK, self.screen, x + 35, next_y + i * 30, 16)
|
||||
i = i + 1
|
||||
|
||||
def enqueue_log(self, text):
|
||||
if self.log_queue.full():
|
||||
self.log_queue.get()
|
||||
self.log_queue.put(text)
|
||||
self.draw()
|
||||
|
Loading…
Reference in New Issue
Block a user