resolve endregion problem
This commit is contained in:
parent
047ef87bab
commit
291e028a8a
@ -9,7 +9,6 @@ from domain.world import World
|
||||
|
||||
|
||||
class RandomCatMoveCommand(Command):
|
||||
|
||||
def __init__(self, world: World, cat: Cat) -> None:
|
||||
super().__init__()
|
||||
self.world = world
|
||||
@ -24,15 +23,17 @@ class RandomCatMoveCommand(Command):
|
||||
if not cat.busy:
|
||||
while True:
|
||||
cat.direction = randint(0, 3)
|
||||
if not ((cat.direction == 0 and cat.y == 0)
|
||||
or (cat.direction == 1 and cat.x == self.world.width - 1)
|
||||
or (cat.direction == 2 and cat.y == self.world.height - 1)
|
||||
or (cat.direction == 3 and cat.x == 0)):
|
||||
if not (
|
||||
(cat.direction == 0 and cat.y == 0)
|
||||
or (cat.direction == 1 and cat.x == self.world.width - 1)
|
||||
or (cat.direction == 2 and cat.y == self.world.height - 1)
|
||||
or (cat.direction == 3 and cat.x == 0)
|
||||
):
|
||||
break
|
||||
|
||||
if cat.direction == 0: # up
|
||||
if cat.busy:
|
||||
move_vector = (0, - 1)
|
||||
move_vector = (0, -1)
|
||||
cat.busy = not cat.busy
|
||||
if cat.direction == 1: # right
|
||||
if cat.busy:
|
||||
@ -54,10 +55,16 @@ class RandomCatMoveCommand(Command):
|
||||
end_x = cat.x + move_vector[0]
|
||||
end_y = cat.y + move_vector[1]
|
||||
|
||||
if end_x > self.world.width - 1 or end_y > self.world.height - 1 or end_x < 0 or end_y < 0:
|
||||
if (
|
||||
end_x > self.world.width - 1
|
||||
or end_y > self.world.height - 1
|
||||
or end_x < 0
|
||||
or end_y < 0
|
||||
):
|
||||
return
|
||||
|
||||
self.world.obstacles[cat.x][cat.y].remove(cat)
|
||||
cat.x = end_x
|
||||
cat.y = end_y
|
||||
self.world.obstacles[end_x][end_y].append(cat)
|
||||
# endregion cat random movement
|
||||
|
Loading…
Reference in New Issue
Block a user