Ejemplo n.º 1
0
    def add_object(self, i, j, kind=None, color=None, goalidx=None):
       """
       Add a new object to room (i, j)
       """

       if kind == None:
           kind = self._rand_elem(['key', 'ball', 'box'])

       if color == None:
           color = self._rand_color()

       assert kind in ['key', 'ball', 'box', 'goal', 'goalcolor']
       if kind == 'key':
           obj = Key(color)
       elif kind == 'ball':
           obj = Ball(color)
       elif kind == 'box':
           obj = Box(color)
       elif kind == 'goal':
           obj: Goal()
       elif kind =='goalcolor':
           obj = GoalColor('green')
           return self.put_obj(GoalColor(color), self.width - 2, self.height - (2*(1+goalidx)))

       return self.place_in_room(i, j, obj)
Ejemplo n.º 2
0
    def gen_mission(self):
        door, _ = self.add_door(1, 1, locked=True)

        # Put the key in the box, then place the box in the room
        key = Key(door.color)
        box = Box(self._rand_color(), key)
        self.place_in_room(1, 1, box)

        self.place_agent(1, 1)

        self.instrs = [Instr(action="open", object=Object(door.type))]
 def generate_grid(self, width, height):
     # Create an empty grid
     self.grid = Grid(width, height)
     for i in range(self.height):
         for j in range(self.width):
             self.put_object(Floor(), (i, j))
     # Place a goal square in the bottom-right corner
     # self.put_object(Goal(), (width - 1, height - 1))
     self.put_object(Key(color="yellow"), (width - 1, height - 1))
     f = partial(Wall, color="red")
     self.grid.horz_wall(0, height // 2, obj_type=f)
     # self.grid.set(width // 2, height // 2, Door(color='red', is_open=True, is_locked=False))
     self.grid.set(width // 2, height // 2, Floor())
     self.put_object(self.opponent_obj, self.opponent.current_position)
     self.put_object(self.player_obj, self.player.current_position)