50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
from src.agent.map.gameMap import GameMap
|
|
from mesa.visualization.modules import CanvasGrid
|
|
from mesa.visualization.modules.TextVisualization import TextElement
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
|
from src.decisiontree import create_model
|
|
from src.direction import Direction
|
|
|
|
|
|
def player_representation(agent):
|
|
portrayal = {"Shape": "sprites/heroE.png",
|
|
"Layer": 1}
|
|
if agent.isPlayer and agent.direction==Direction.N:
|
|
portrayal["Shape"] = "sprites/heroN.png"
|
|
elif agent.isPlayer and agent.direction == Direction.W:
|
|
portrayal["Shape"] = "sprites/heroW.png"
|
|
elif agent.isPlayer and agent.direction == Direction.S:
|
|
portrayal["Shape"] = "sprites/heroS.png"
|
|
elif agent.isBox:
|
|
portrayal["Shape"] = "sprites/box.png"
|
|
portrayal["Layer"] = 0
|
|
elif agent.isCreature:
|
|
if agent.name=='Goblin':
|
|
portrayal["Shape"] = 'sprites/goblin.png'
|
|
elif agent.name=='Skeleton':
|
|
portrayal["Shape"] = 'sprites/skeletonArcher.png'
|
|
return portrayal
|
|
|
|
grid = CanvasGrid(player_representation, 10, 10, 500, 500)
|
|
|
|
class PlayerStats(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)
|
|
# class FightStats(TextElement):
|
|
# def render(self, model):
|
|
# if model.player.combat:
|
|
# return model.player.describe_situation(model.player.opponent, model.player.strategy)
|
|
# else:
|
|
# return "Not fighting"
|
|
server = ModularServer(GameMap,
|
|
[grid, PlayerStats()],
|
|
"Map",
|
|
{"x": 10, "y": 10})
|
|
create_model()
|
|
server.port = 8081
|
|
server.launch()
|