HouseDimir

HouseGenerator

May 26th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. import re
  2. import sys
  3. import math
  4. import random as rand
  5.  
  6. # The end result is intended to look like a list name House
  7. # that contains objects inside representing each floor. These
  8. # objects should also contain the rooms, which should contain
  9. # k-v pairs representing the type of room, as well as where
  10. # the windows and doors are positioned in the walls of the room
  11. # as shown below.
  12.  
  13. # House = [Floor1, Floor2, Floor3]
  14. # Floor1 = [Room_1, Room_2, Room_3, Room_4, staircase_1]
  15. # Room_1 = {rType : Kitchen, door_1 : middle,
  16. #           door_2 : outside, window : center}
  17. # staircase_1 = (bottom)
  18.  
  19. door_pos = ['inside', 'middle', 'outside']
  20. window_pos = ['left', 'center', 'right']
  21. stair_pos = ['top', 'left', 'bottom', 'right']
  22. room_type = ['Bathroom_1', 'Bathroom_2', 'Kitchen', 'Livingroom', 'Bedroom_1', 'Bedroom_2', 'Master_Bedroom', 'Master_Bathroom']
  23.  
  24. House = []
  25. Floor1 = []
  26. Floor2 = []
  27. Floor3 = []
  28. Room_1 = {}
  29. Room_2 = {}
  30. Room_3 = {}
  31. Room_4 = {}
  32.  
  33. def Room1Gen():
  34.     rtype = rand.sample(room_type, 1)
  35.     door_1 = rand.sample(door_pos, 1)
  36.     door_2 = rand.sample(door_pos, 1)
  37.     window = rand.sample(window_pos, 1)
  38.     Room_1['rtype'] = rtype[0]
  39.     Room_1['door_1'] = door_1[0]
  40.     Room_1['door_2'] = door_2[0]
  41.     Room_1['window'] = window[0]
  42.     for i in Room_1:
  43.         yield Room_1[i]
  44.  
  45. def Room2Gen():
  46.     rtype = rand.sample(room_type, 1)
  47.     door_1 = rand.sample(door_pos, 1)
  48.     door_2 = rand.sample(door_pos, 1)
  49.     window = rand.sample(window_pos, 1)
  50.     Room_2['rtype'] = rtype[0]
  51.     Room_2['door_1'] = door_1[0]
  52.     Room_2['door_2'] = door_2[0]
  53.     Room_2['window'] = window[0]
  54.     for i in Room_2:
  55.         yield Room_2[i]
  56.  
  57. def Room3Gen():
  58.     rtype = rand.sample(room_type, 1)
  59.     door_1 = rand.sample(door_pos, 1)
  60.     door_2 = rand.sample(door_pos, 1)
  61.     window = rand.sample(window_pos, 1)
  62.     Room_3['rtype'] = rtype[0]
  63.     Room_3['door_1'] = door_1[0]
  64.     Room_3['door_2'] = door_2[0]
  65.     Room_3['window'] = window[0]
  66.     for i in Room_3:
  67.         yield Room_3[i]
  68.  
  69. def Room4Gen():
  70.     rtype = rand.sample(room_type, 1)
  71.     door_1 = rand.sample(door_pos, 1)
  72.     door_2 = rand.sample(door_pos, 1)
  73.     window = rand.sample(window_pos, 1)
  74.     Room_4['rtype'] = rtype[0]
  75.     Room_4['door_1'] = door_1[0]
  76.     Room_4['door_2'] = door_2[0]
  77.     Room_4['window'] = window[0]
  78.     for i in Room_4:
  79.         yield Room_4[i]
  80.  
  81. room1 = Room1Gen()
  82. room2 = Room2Gen()
  83. room3 = Room3Gen()
  84. room4 = Room4Gen()
  85.  
  86. try:
  87.     for i in range(5):
  88.         next(room1)
  89.         next(room2)
  90.         next(room3)
  91.         next(room4)
  92. except StopIteration:
  93.     pass
  94.  
  95. Floor1.append(Room_1)
  96. Floor1.append(Room_2)
  97. Floor1.append(Room_3)
  98. Floor1.append(Room_4)
  99. House.append(Floor1)
  100. print('These are the rooms in Floor 1:')
  101. print(Floor1, '\n \n')
  102. print('Here are the floors in the House:', end=' ')
  103. print(House)
Add Comment
Please, Sign In to add comment