示例#1
0
 def create_gamefield(file_path):
     with open(file_path) as f:
         str_field = f.read().split('\n')
     f.close()
     game_info = str_field.pop(0).split()
     width = int(game_info[0]) + 2
     bonuses_count = int(game_info[1])
     mutable_walls = []
     movable = []
     gamefield = []
     Gamefield_creator.create_wall_line(gamefield, width)
     for i in range(len(str_field)):
         string = str_field[i]
         string = string[0:width]
         field_line = []
         field_line.append(wi.Wall_Immutable(c.Position(0, i + 1)))
         for j in range(len(string)):
             game_object = cells.get(string[j])
             if not game_object:
                 raise InvalidFileException
             position = c.Position(j + 1, i + 1)
             if issubclass(game_object, m.Movable):
                 field_line.append(ec.Empty(position))
                 movable.append((game_object, position))
             else:
                 if game_object is wm.Wall_Mutable:
                     field_line.append(game_object(
                         position, ex.ExplosionType(int(string[j]))))
                 else:
                     field_line.append(game_object(position))
                 if isinstance(field_line[- 1], wm.Wall_Mutable):
                     mutable_walls.append(field_line[len(field_line) - 1])
         while len(field_line) < width - 1:
             field_line.append(ec.Empty(c.Position(len(field_line), i + 1)))
         field_line.append(wi.Wall_Immutable(
             c.Position(len(field_line), i + 1)))
         gamefield.append(field_line)
     Gamefield_creator.create_wall_line(gamefield, width)
     gamefield[1][1] = ec.Empty(c.Position(1, 1))
     Gamefield_creator.randomize_bonuses(mutable_walls, bonuses_count)
     return gamefield, movable
示例#2
0
 def action(self, gamefield, tick_time):
     if self.collected:
         gamefield[self._position.y][self._position.x] = ec.Empty(
             self._position)
     else:
         return
示例#3
0
 def action(self, gamefield, tick_time):
     self.timer -= tick_time
     if self.timer <= 0:
         from modules import empty_cell as ec
         gamefield[self._position.y][self._position.x] = ec.Empty(self._position) if not self.bonus\
             else self.bonus(self._position)