mudar parte gráfica para pygame
This commit is contained in:
@ -25,7 +25,8 @@ for pos_y in range(0, mapa.dimensao[0]):
|
|||||||
print(f"{tmp_agente.estrategia[0]:2}", end='')
|
print(f"{tmp_agente.estrategia[0]:2}", end='')
|
||||||
print("")
|
print("")
|
||||||
|
|
||||||
Gui.App(mapa)
|
# Gui.App(mapa)
|
||||||
|
Gui.main(mapa)
|
||||||
|
|
||||||
print(mapa)
|
print(mapa)
|
||||||
pos_y = random.randint(0, tamanho_mundo[0]-1)
|
pos_y = random.randint(0, tamanho_mundo[0]-1)
|
||||||
|
|||||||
@ -1,8 +1,82 @@
|
|||||||
|
import sys
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
from tkinter import ttk
|
from tkinter import ttk
|
||||||
|
import pygame as pg
|
||||||
|
from modules.agente import Agente
|
||||||
from modules.mapa import Mapa
|
from modules.mapa import Mapa
|
||||||
|
|
||||||
|
flags = 0
|
||||||
|
|
||||||
|
|
||||||
|
def devolveCor(agente: Agente) -> tuple[int, int, int, int]:
|
||||||
|
match agente.estrategia:
|
||||||
|
case "Neutro":
|
||||||
|
return (255, 255, 255, 0)
|
||||||
|
case "Tit4Tat":
|
||||||
|
return (255, 255, 0, 0)
|
||||||
|
case "Vingativo":
|
||||||
|
return (255, 0, 0, 0)
|
||||||
|
case "Lunatico":
|
||||||
|
return (0, 0, 255, 0)
|
||||||
|
case _:
|
||||||
|
return (0, 0, 0, 0)
|
||||||
|
|
||||||
|
|
||||||
|
def criarTabuleiro(
|
||||||
|
surface: pg.Surface,
|
||||||
|
dimensao_tabuleiro: tuple[int, int],
|
||||||
|
mapa: Mapa,
|
||||||
|
) -> None:
|
||||||
|
dimensoes_surface_principal: tuple[int, int] = surface.get_size()
|
||||||
|
max_altura: int = int(
|
||||||
|
(dimensoes_surface_principal[0]-20)/dimensao_tabuleiro[0])
|
||||||
|
max_largura: int = int(
|
||||||
|
(dimensoes_surface_principal[1]-20)/dimensao_tabuleiro[1])
|
||||||
|
tamanho_quadrado: int = max_altura if max_altura < max_largura else max_largura
|
||||||
|
cor_quadrado: tuple[int, int, int, int]
|
||||||
|
|
||||||
|
for pos_y in range(0, dimensao_tabuleiro[0]):
|
||||||
|
for pos_x in range(0, dimensao_tabuleiro[1]):
|
||||||
|
agente: Agente | None = mapa.posicao((pos_y, pos_x))
|
||||||
|
cor_quadrado = devolveCor(agente)
|
||||||
|
pg.draw.rect(surface,
|
||||||
|
cor_quadrado,
|
||||||
|
[10+(tamanho_quadrado*pos_y),
|
||||||
|
10+(tamanho_quadrado*pos_x),
|
||||||
|
tamanho_quadrado, tamanho_quadrado],
|
||||||
|
0)
|
||||||
|
|
||||||
|
|
||||||
|
def main(mapa: Mapa | None):
|
||||||
|
if mapa is None:
|
||||||
|
print("SEM MAPA!!")
|
||||||
|
pg.init()
|
||||||
|
janela = pg.display.set_mode((1280, 800), flags)
|
||||||
|
pg.display.set_caption("Game Theory of Life")
|
||||||
|
clock = pg.time.Clock()
|
||||||
|
|
||||||
|
running: bool = True
|
||||||
|
cor1: tuple[int, int, int, int] = (255, 0, 0, 0)
|
||||||
|
cor2: tuple[int, int, int, int] = (0, 255, 0, 0)
|
||||||
|
|
||||||
|
while running:
|
||||||
|
for event in pg.event.get():
|
||||||
|
if event.type == pg.QUIT:
|
||||||
|
running = False
|
||||||
|
if event.type == pg.KEYDOWN:
|
||||||
|
if event.key == pg.K_q:
|
||||||
|
running = False
|
||||||
|
if event.key == pg.K_c:
|
||||||
|
# trocar cor
|
||||||
|
pass
|
||||||
|
# (367, 250)
|
||||||
|
criarTabuleiro(janela, mapa.dimensao, mapa)
|
||||||
|
pg.display.flip()
|
||||||
|
clock.tick(60)
|
||||||
|
|
||||||
|
pg.quit()
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
|
|
||||||
class Frame_Mapa(ttk.Frame):
|
class Frame_Mapa(ttk.Frame):
|
||||||
def __init__(self, mapa: Mapa):
|
def __init__(self, mapa: Mapa):
|
||||||
|
|||||||
Reference in New Issue
Block a user