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
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)
def defaultAttack(self,opponent):
if self.weapon1.type == "Meele":
self.meleeAttack(opponent)

View File

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

View File

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