2021-05-03 00:23:18 +02:00
|
|
|
from src.agent.map.gameMap import GameMap
|
2021-03-13 17:41:38 +01:00
|
|
|
from mesa.visualization.modules import CanvasGrid
|
2021-05-10 20:04:13 +02:00
|
|
|
from mesa.visualization.modules.TextVisualization import TextElement
|
2021-03-13 17:41:38 +01:00
|
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
|
|
|
|
|
|
|
|
2021-03-16 15:36:24 +01:00
|
|
|
def player_representation(agent):
|
2021-03-28 15:23:14 +02:00
|
|
|
portrayal = {"Shape": "sprites/hero.png",
|
2021-04-13 23:08:57 +02:00
|
|
|
"Layer": 1}
|
2021-03-16 15:36:24 +01:00
|
|
|
if agent.isBox:
|
2021-03-28 15:23:14 +02:00
|
|
|
portrayal["Shape"] = "sprites/box.png"
|
|
|
|
portrayal["Layer"] = 0
|
2021-03-30 14:17:54 +02:00
|
|
|
elif agent.isCreature:
|
2021-05-03 00:23:18 +02:00
|
|
|
portrayal["Shape"] = 'sprites/goblin.png'
|
2021-03-13 17:41:38 +01:00
|
|
|
return portrayal
|
|
|
|
|
2021-03-16 15:36:24 +01:00
|
|
|
grid = CanvasGrid(player_representation, 10, 10, 500, 500)
|
2021-05-10 20:04:13 +02:00
|
|
|
|
|
|
|
class MyTextElement(TextElement):
|
|
|
|
def render(self, model):
|
|
|
|
hp = str(model.get_hp())
|
|
|
|
position = str(model.get_position())
|
|
|
|
gold = str(model.get_gold())
|
|
|
|
|
|
|
|
return "Player hp: {}<br>Current position: {}<br>Player's gold: {}".format(
|
|
|
|
hp, position, gold)
|
|
|
|
|
2021-03-13 17:41:38 +01:00
|
|
|
server = ModularServer(GameMap,
|
2021-05-10 20:04:13 +02:00
|
|
|
[grid, MyTextElement()],
|
2021-03-13 17:41:38 +01:00
|
|
|
"Map",
|
2021-05-03 00:23:18 +02:00
|
|
|
{"x": 10, "y": 10})
|
2021-04-28 03:02:59 +02:00
|
|
|
server.port = 8081
|
2021-05-03 00:23:18 +02:00
|
|
|
server.launch()
|