fixed placing monsters and boxes on the same cell (no longer possible)

This commit is contained in:
tubks 2021-03-30 23:36:19 +02:00
parent 1acb7d42d7
commit 2c1097d6a9
3 changed files with 13 additions and 11 deletions

View File

@ -69,6 +69,7 @@ class Creature(Agent):
damage = attackValue - defenseValue damage = attackValue - defenseValue
if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.mag_protection > 0): if (damage > 0) and (damage + self.weapon1.damage - opponent.armor.mag_protection > 0):
opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.mag_protection) opponent.health = opponent.health - (damage + self.weapon1.damage - opponent.armor.mag_protection)
def defaultAttack(self,opponent): def defaultAttack(self,opponent):
if self.weapon1.type == "Meele": if self.weapon1.type == "Meele":
self.meleeAttack(opponent) self.meleeAttack(opponent)

View File

@ -9,12 +9,12 @@ import random
x = 10 x = 10
y = 10 y = 10
step_counter = 0 step_counter = 0
boxes_number = 5 boxes_number = 10
creatures_number = 5 creatures_number = 10
class GameMap(Model): class GameMap(Model):
def __init__(self, x, y, boxes_number): def __init__(self, x, y):
self.grid = MultiGrid(x, y, False) self.grid = MultiGrid(x, y, False)
self.schedule = RandomActivation(self) # agenci losowo po kolei wykonują swoje akcje self.schedule = RandomActivation(self) # agenci losowo po kolei wykonują swoje akcje
# to jest potrzebne przy założeniu, że potwory chodzą? # to jest potrzebne przy założeniu, że potwory chodzą?
@ -30,23 +30,24 @@ class GameMap(Model):
for i in range(self.boxes_number): for i in range(self.boxes_number):
box = Box(i, self) box = Box(i, self)
self.schedule.add(box) #self.schedule.add(box)
x = self.random.randrange(self.grid.width) x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height) y = self.random.randrange(self.grid.height)
try: if self.grid.is_cell_empty((x, y)):
self.grid.place_agent(box, (x, y)) self.grid.place_agent(box, (x, y))
except: self.schedule.add(box)
else:
pass pass
for i in range(self.boxes_number, self.boxes_number+self.creatures_number): #taki range, żeby każdy agent miał poprawne unique_id for i in range(self.boxes_number, self.boxes_number+self.creatures_number): #taki range, żeby każdy agent miał poprawne unique_id
#creature = Creature(i, self) #creature = Creature(i, self)
creature = Creature(i, self, "Goblin", 0, 0, 0, 1, 1, WM2,A2, dice(6)) creature = Creature(i, self, "Goblin", 1, 1, 1, 1, 1, WM2,A2, dice(6))
self.schedule.add(creature)
x = self.random.randrange(self.grid.width) x = self.random.randrange(self.grid.width)
y = self.random.randrange(self.grid.height) y = self.random.randrange(self.grid.height)
try: if self.grid.is_cell_empty((x, y)):
self.grid.place_agent(creature, (x, y)) self.grid.place_agent(creature, (x, y))
except: self.schedule.add(creature)
else:
pass pass

View File

@ -17,6 +17,6 @@ grid = CanvasGrid(player_representation, 10, 10, 500, 500)
server = ModularServer(GameMap, server = ModularServer(GameMap,
[grid], [grid],
"Map", "Map",
{"x":10, "y":10, "boxes_number":5}) {"x":10, "y":10})
server.port = 8521 server.port = 8521
server.launch() server.launch()