2021-06-22 22:21:03 +02:00
|
|
|
from src.agent.map.gameMap import GameMap
|
2021-03-13 17:41:38 +01:00
|
|
|
from mesa.visualization.modules import CanvasGrid
|
2021-06-22 22:21:03 +02:00
|
|
|
from mesa.visualization.modules.TextVisualization import TextElement
|
2021-03-13 17:41:38 +01:00
|
|
|
from mesa.visualization.ModularVisualization import ModularServer
|
2021-06-22 22:21:03 +02:00
|
|
|
#from src.decisiontree import create_model
|
|
|
|
from src.direction import Direction
|
|
|
|
from collections import defaultdict
|
|
|
|
import src.agent.ga_chromosome as ga
|
2021-03-13 17:41:38 +01:00
|
|
|
|
2021-03-16 15:36:24 +01:00
|
|
|
def player_representation(agent):
|
2021-06-22 22:21:03 +02:00
|
|
|
portrayal = {"Shape": "sprites/heroE.png",
|
2021-04-13 23:08:57 +02:00
|
|
|
"Layer": 1}
|
2021-06-22 22:21:03 +02:00
|
|
|
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:
|
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-06-22 22:21:03 +02:00
|
|
|
if agent.name=='Goblin':
|
|
|
|
portrayal["Shape"] = 'sprites/goblin.png'
|
|
|
|
elif agent.name=='Skeleton':
|
|
|
|
portrayal["Shape"] = 'sprites/skeletonArcher.png'
|
|
|
|
return portrayal
|
|
|
|
|
|
|
|
def chest_content(agent):
|
|
|
|
if agent.isBox:
|
|
|
|
portrayal = {"Shape": "sprites/coin.jpg",
|
|
|
|
"Layer": 1}
|
2021-03-13 17:41:38 +01:00
|
|
|
return portrayal
|
|
|
|
|
2021-06-22 22:21:03 +02:00
|
|
|
grid = CanvasGrid(player_representation, 10, 10, 700, 700)
|
|
|
|
image=CanvasGrid(chest_content, 1, 1, 200, 200)
|
|
|
|
class Stats(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 ChestContent(CanvasGrid):
|
|
|
|
# def render(self,model):
|
|
|
|
# grid_state = defaultdict(list)
|
|
|
|
# portrayal = self.chest_content(agent)
|
|
|
|
# portrayal["x"] = 0
|
|
|
|
# portrayal["y"] = 0
|
|
|
|
# grid_state[portrayal["Layer"]].append(portrayal)
|
|
|
|
# return
|
|
|
|
# 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"
|
|
|
|
ga.create_model()
|
2021-03-13 17:41:38 +01:00
|
|
|
server = ModularServer(GameMap,
|
2021-06-22 22:21:03 +02:00
|
|
|
[grid,Stats()],
|
2021-03-13 17:41:38 +01:00
|
|
|
"Map",
|
2021-06-22 22:21:03 +02:00
|
|
|
{"x": 10, "y": 10})
|
|
|
|
server.port = 8081
|
|
|
|
server.launch()
|