diff --git a/server.py b/server.py index eeb22fa..1bdf8d9 100644 --- a/server.py +++ b/server.py @@ -1,22 +1,64 @@ -from model import GameMap +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 +from collections import defaultdict +import src.agent.ga_chromosome as ga def player_representation(agent): - portrayal = {"Shape": "sprites/hero.png", + portrayal = {"Shape": "sprites/heroE.png", "Layer": 1} - if agent.isBox: + 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: - portrayal["Shape"]='sprites/goblin.png' + 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) +def chest_content(agent): + if agent.isBox: + portrayal = {"Shape": "sprites/coin.jpg", + "Layer": 1} + return portrayal + +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: {}
Current position: {}
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() server = ModularServer(GameMap, - [grid], + [grid,Stats()], "Map", - {"x":10, "y":10}) -server.port = 8521 -server.launch() \ No newline at end of file + {"x": 10, "y": 10}) +server.port = 8081 +server.launch()