SHARE
TWEET

Untitled

a guest Jun 24th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import functools
  2. from quests import *
  3. import quests
  4. from enemy import *
  5.  
  6.  
  7. class Level:
  8.     def __init__(self, rooms, floor):
  9.         self.rooms = rooms
  10.         self.floor = floor
  11.  
  12.     def can_move(self, x, y):
  13.         if x in [0, 1] and y in [0, 1, 2]:
  14.             return True
  15.         return False
  16.  
  17.     def print_map(self, x, y):
  18.         for row in self.rooms:
  19.             print(repr(row[0]) + '\t' + repr(row[1]))
  20.  
  21.     def is_cleared(self):
  22.         rooms_with_quest = []
  23.         for row in self.rooms:
  24.             for room in row:
  25.                 if room.quest is not None:
  26.                     rooms_with_quest.append(room)
  27.         # print(rooms_with_quest)
  28.         is_cleared = True
  29.         print(rooms_with_quest)
  30.         for room in rooms_with_quest:
  31.             print(room.quest.completed)
  32.             is_cleared = is_cleared and room.quest.completed
  33.         return is_cleared
  34.  
  35.  
  36. class Room:
  37.     def __init__(self, name, desc, x, y, items, quest, enemy):
  38.         self.name = name
  39.         self.desc = desc
  40.         self.x = x
  41.         self.y = y
  42.         self.items = items
  43.         self.quest = quest
  44.         self.enemy = enemy
  45.  
  46.     def __str__(self):
  47.         return self.name + ' - ' + self.desc.lower()
  48.  
  49.     def __repr__(self):
  50.         return self.name
  51.  
  52.     def enter(self):
  53.         print(self.desc)
  54.  
  55.  
  56. def level_generator(number_of_levels):
  57.     levels = []
  58.     rooms_1 = open("rooms/rooms_1.txt", 'r')
  59.     rooms_2 = None
  60.     rooms_3 = None
  61.     for i in range(number_of_levels):
  62.         rooms = room_generator(rooms_1)
  63.         levels.append(Level(rooms, i + 1))
  64.     rooms_1.close()
  65.     return levels
  66.  
  67.  
  68. def room_generator(rooms_d):
  69.     rooms_out = []
  70.     for i in range(3):
  71.         rooms_in = []
  72.         for j in range(2):
  73.             rooms_desc = (rooms_d.readline().rstrip(), rooms_d.readline().rstrip())
  74.             if i == 2 and j == 0:
  75.                 rooms_in.append(Room(rooms_desc[0], rooms_desc[1], j, i, [], Quest(quests.check_number), Enemy(
  76.                     "troll", {"health": 200, "strength": 20}
  77.                 )))
  78.             else:
  79.                 rooms_in.append(Room(rooms_desc[0], rooms_desc[1], j, i, [], None, None))
  80.  
  81.         rooms_out.append(rooms_in)
  82.     return rooms_out
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top