def arrange_contents(self, gb): # Run a road along one edge of the map. Stick everything else in a # sub-rect to arrange there. Keep track of the civilized areas. self.wilds = rooms.Room(width=self.width - 10, height=self.height, anchor=anchors.west, parent=self) self.wilds.area = pygame.Rect(0, 0, self.wilds.width, self.wilds.height) self.wilds.FUZZY_FILL_TERRAIN = maps.LOGROUND self.wilds.GAPFILL = gapfiller.MonsterFiller(spacing=16) self.wilds.DEFAULT_ROOM = self.DEFAULT_ROOM self.civilized_bits = list() for r in self.contents[:]: if hasattr(r, "area") and r is not self.wilds: self.contents.remove(r) self.wilds.contents.append(r) if context.CIVILIZED in r.tags: self.civilized_bits.append(r) # Create the road. self.road = pygame.Rect(self.area.x + self.area.width - 10, self.area.y, 7, self.area.height) self.roadbits = list() for y in range(10): x = self.area.x + self.area.width - 10 + random.randint(0, 2) roadseg = rooms.Room(width=5, height=self.height // 10, parent=self) roadseg.area = pygame.Rect(x, y * roadseg.height, roadseg.width, roadseg.height) self.roadbits.append(roadseg)
def seed(): global _maze _maze.clear() _maze = { (0, 0): rooms.ItemRoom(0, 0, "Outside Cave Entrance", "North of you, the cave mount beckons", [items.Sword()]), (0, -1): rooms.Room( 0, -1, "Foyer", """Dim light filters in from the south. Dusty passages run north and east."""), (0, -2): rooms.Room( 0, -2, "Grand Overlook", """A steep cliff appears before you, falling into the darkness. Ahead to the north, a light flickers in the distance, but there is no way across the chasm."""), (1, -1): rooms.Room( 1, -1, "Narrow Passage", """The narrow passage bends here from west to north. The smell of gold permeates the air."""), (1, -2): rooms.Room( 1, -2, "Treasure Chamber", """You've found the long-lost treasure chamber! Sadly, it has already been completely emptied by earlier adventurers. The only exit is to the south."""), }
def new(self, type, **attrs): if type.lower() == 'room': to_build = rooms.Room() dictname = self.roomdict elif type.lower() == 'thing': to_build = things.Thing() dictname = self.thingdict elif type.lower() == 'npc': to_build = people.Person() dictname = self.npcdict else: errors.unknown_type(type) return if not attrs or 'name' not in attrs.keys(): to_build.name = errors.nameless_item(type.lower()) to_build.setprops(**attrs) dictname[to_build.name] = to_build if (type.lower() == 'thing' or type.lower() == 'npc') and not to_build.ref_name: defaultname = to_build.name.replace(' ', '') to_build.ref_name = defaultname errors.no_ref_name(defaultname) self.save_type(type.lower()) return to_build
def test_setprops(): room = rooms.Room(name='helloroom') newthings = {'description': "this is a room", "invent": ["egg", "bacon"]} room.setprops(newthings) print room.__dict__
def test_path_mirroring(): room1 = rooms.Room(name='one', description='this is room one') room2 = rooms.Room(name='two', description='this is room two') room3 = rooms.Room(name='three', description='this is room three') rooms.phonebook = {'one': room1, 'two': room2, 'three': room3} room1.add_paths({'e': 'two'}) room2.add_paths({'s': 'three'}) rooms.mirror_paths() testplayer.location = 'one' testplayer.go('e') testplayer.go('w') testplayer.go('e') testplayer.go('s') testplayer.go('n') testplayer.go('w')
def __init__(self): self.room_set = {} for r in range(self.__num_rows): for c in range(self.__num_cols): room_name = chr(65 + r) + str(c + 1) self.room_set[room_name] = rooms.Room(room_name) for r, l in self.__room_linkage1.items(): for k, i in l.items(): l[k] = self.room_set[i] for k in self.room_set: self.room_set[k].add_paths(self.__room_linkage1[k]) self.__cur_room = self.room_set['A1']
def load(self, player): namefile = raw_input("What name did you save under? ") save_game = open(namefile.lower() + "_save.json") states = json.load(save_game) player_states = states[0] room_states = states[1] thing_states = states[2] npc_states = states[3] for att, player_data in player_states.iteritems(): player.__dict__.update(player_data) for name, room_data in room_states.iteritems(): rooms.phonebook[name] = rooms.Room() rooms.phonebook[name].__dict__.update(room_data) for name, thing_data in thing_states.iteritems(): things.objectlist[name] = things.Thing() things.objectlist[name].__dict__.update(thing_data) for name, npc_data in npc_states.iteritems(): people.npclist[name] = people.Person() people.npclsit[name].__dict__.update(npc_data)
# Child of Character class Enemy(Character): # Currently don't need code in here pass # - Main # Used for testing code associated with this module so this code should only run when it is main if (__name__ == "__main__"): # Tkinter setup root = tk.Tk() root.geometry("300x100+100+100") start_room = rooms.Room("The Entrance", n=True) end_room = rooms.Room("The Bee Room", s=True, n=start_room) # Initialise a map game_map = rooms.Map([[start_room], [end_room]], start_room, end_room) # String var name name = "Jordan Hay" # Create player object player = Player(name, game_map) player.inventory().add_items([ items.Item("Bees"), items.Weapon("A HIVE FULL OF BEES", 10, 300), items.Armour("Honeycomb Kneepads", 100), items.Potion("10mL Syringe full of Honey", 10)
class Character_Turn(Event): def __init__(self, init_count, init_tiebreak, character): super().__init__({}) self.event_information['Initiative Count'] = init_count self.event_information['Initiative Tiebreaker'] = init_tiebreak self.event_information['Power User'] = character def execute_event(self): turn = self.event_information['Power User'].generate_turn() turn.execute_actions() self.event_information['Initiative Round'] += 1 self.add_to_environment(self.event_information['Environment']) if __name__ == "__main__": r1 = rooms.Room() men = character.CharacterGenerators.default_char("Doctor Menlo", 10, "Defense") cer = character.CharacterGenerators.default_char("Cerulean", 10, "Toughness") men_loc = rooms.Room_Object(0, 0, 0, men, r1) cer_loc = rooms.Room_Object(0, 0, 0, cer, r1) vm = powers.Attack("Voltaic Manipulator", "Ranged Combat: Hypersuit Blasters", 10, "Dodge", character.Character.get_toughness, character.Character.get_toughness,
def arrange_contents(self, gb): # Divide the map into two segments. if random.randint(1, 2) == 1: horizontal_river = True subzone_height = (self.height - 10) // 2 # Horizontal river z1 = rooms.Room() z1.area = pygame.Rect(0, 0, self.width, subzone_height) z1.special_c["bridge_anchor"] = anchors.south z2 = rooms.Room() z2.area = pygame.Rect(0, 0, self.width, subzone_height) z2.area.bottomleft = self.area.bottomleft z2.special_c["bridge_anchor"] = anchors.north river = pygame.Rect(0, 0, self.width, 7) else: horizontal_river = False subzone_width = (self.width - 10) // 2 # Vertical river z1 = rooms.Room() z1.area = pygame.Rect(0, 0, subzone_width, self.height) z1.special_c["bridge_anchor"] = anchors.east z2 = rooms.Room() z2.area = pygame.Rect(0, 0, subzone_width, self.height) z2.area.topright = self.area.topright z2.special_c["bridge_anchor"] = anchors.west river = pygame.Rect(0, 0, 7, self.height) if random.randint(1, 2) == 1: z1, z2 = z2, z1 z1.GAPFILL = gapfiller.MonsterFiller() z1.DEFAULT_ROOM = self.DEFAULT_ROOM z2.GAPFILL = gapfiller.MonsterFiller() z2.DEFAULT_ROOM = self.DEFAULT_ROOM river.center = self.area.center self.fill(gb, river, floor=maps.WATER, wall=None) self.fill(gb, river.inflate(3, 3), wall=None) # Locate the bridge, before_bridge, and after_bridge rooms, creating them # if none currently exist. bridge = self.special_c.get("bridge") or self.special_c.setdefault( "bridge", rooms.FuzzyRoom(parent=self)) before_bridge = self.special_c.get( "before_bridge") or self.special_c.setdefault( "before_bridge", self.DEFAULT_ROOM(parent=self)) after_bridge = self.special_c.get( "after_bridge") or self.special_c.setdefault( "after_bridge", self.DEFAULT_ROOM(parent=self)) before_bridge.anchor = z1.special_c["bridge_anchor"] after_bridge.anchor = z2.special_c["bridge_anchor"] # Go through the remaining rooms, sorting each into either z1 or z2 z1_turn = True for r in self.contents[:]: if isinstance(r, Room): if r is bridge: r.area = pygame.Rect(0, 0, r.width, r.height) r.area.center = self.area.center elif r is before_bridge: self.contents.remove(r) z1.contents.append(r) elif r is after_bridge: self.contents.remove(r) z2.contents.append(r) elif context.ENTRANCE in r.tags: self.contents.remove(r) z1.contents.append(r) elif context.GOAL in r.tags: self.contents.remove(r) z2.contents.append(r) elif z1_turn: self.contents.remove(r) z1.contents.append(r) z1_turn = False else: self.contents.remove(r) z2.contents.append(r) z1_turn = True self.contents += (z1, z2)
def control(self, connectionSocket, addr): self.connectionSocket_list.append(connectionSocket) data = receiveSomething(connectionSocket) clientNO = data[0] self.isInroom[clientNO] = False while True: data = receiveSomething(connectionSocket) if type(data) == bool: continue if data[0] == "getRoom": sendSomething(connectionSocket, self.room_ID) print(clientNO, "update room") elif data[0] == "newRoom": self.room_ID_lock.acquire() for i in range(0, 100): if i not in self.room_ID: self.room_ID.append(i) self.room_list_lock.acquire() self.room_list[i] = rooms.Room(clientNO, i) self.room_list[i].enter(clientNO, data[1]) self.room_list_lock.release() data = [True, i] self.isInroom[clientNO] = data[1] _thread.start_new_thread(self.sendPlayerInfo, (connectionSocket, clientNO)) print(clientNO, "create room", data[1]) break if i == 99: data = [False] self.room_ID_lock.release() sendSomething(connectionSocket, data) elif data[0] == "enterRoom": self.room_ID_lock.acquire() if data[2] not in self.room_ID: data = [False] else: self.room_list_lock.acquire() self.room_list[data[2]].enter(clientNO, data[1]) self.room_list_lock.release() data = [True, data[2]] self.isInroom[clientNO] = data[1] _thread.start_new_thread(self.sendPlayerInfo, (connectionSocket, clientNO)) print(clientNO, "enter room", data[1]) self.room_ID_lock.release() sendSomething(connectionSocket, data) elif data[0] == "exitRoom": self.isInroom[clientNO] = False self.room_ID_lock.acquire() self.room_list_lock.acquire() self.room_list[data[1]].exit(clientNO) if not self.room_list[data[1]].players.keys(): self.room_list.pop(data[1]) self.room_ID.remove(data[1]) self.room_list_lock.release() self.room_ID_lock.release() print(clientNO, "exit room", data[1]) sendSomething(connectionSocket, "OK") elif data[0] == "start": self.isInroom[clientNO] = False print(clientNO, "start game") sendSomething(connectionSocket, "OK") time.sleep(1) break elif data[0] == "myplayer_info": self.room_list_lock.acquire() self.room_list[self.isInroom[clientNO]].enter( clientNO, data[1]) self.room_list_lock.release() print('hahahha') print('receive:', data[1]) clientNO = data[1] self.info_lock.acquire() self.info[clientNO] = { 'name': data[2], 'pos': self.positions[clientNO - 1], 'color': data[3] } self.info_lock.release() self.clientNum_lock.acquire() self.clientNum += 1 self.clientNum_lock.release() while self.clientNum < self.clientSum: time.sleep(0.1) self.send_lock.acquire() sendSomething(connectionSocket, self.info) sendSomething(connectionSocket, self.plat_id) sendSomething(connectionSocket, self.props_matrix) sendSomething(connectionSocket, self.monst_matrix) self.startgame_lock.acquire() self.startgame += 1 self.startgame_lock.release() self.send_lock.release() while self.startgame < self.clientSum: time.sleep(0.1) while True: data = receive(connectionSocket) if data == False: continue self.info_lock.acquire() self.info[clientNO] = data self.info_lock.release() self.update_client() connectionSocket.close()
#setup_world.py import rooms import items import persons #Room A A = rooms.Room('Testroom A') #Room B B = rooms.Room('Testroom B') B.desc = 'Testroom B is kind of an empty test room.' B.items = [items.Dagger('rusty dagger'), items.Ring("white gold ring")] #Room C C = rooms.Room('Testroom C') #Room D D = rooms.Room('Testroom D') #Exits A.exits = {B: ['forest', 'east'], C: ['river', 'north']} B.exits = {A: ['house', 'west'], D: ['shed', 'south']} C.exits = [B, D] D.exits = [A, B, C, D] #Set of rooms in game roomset = {A, B, C, D} #Startroom startroom = B
10)), characters.Enemy( "The Beekeeper", 48, 20, items.Weapon("Smoker", 1, 15), items.Armour("Beekeeping Suit", 3), [items.Potion("Honeycomb", 30), items.Weapon("Pry Tool", 5, 20)]), characters.Enemy("Larry", 10, 15, items.Weapon("Advice", -10, 10), None), characters.Enemy("Imaginos", 100, 30, items.Weapon("Staff of the Ether", 10, 20), None, [items.Potion("Ether", 50)]) ] # -- Map/Rooms # Special rooms toilet = rooms.Room("Toilet", s=True) cellar = rooms.Room("Cellar", n=True, w=toilet) entrance_hall = rooms.Room("Entrance Hall", n=True) crypt = rooms.Room("THE CRYPT") crypt.add_enemy(dracula) # Add dracula to the crypt # Create Map of rooms castle_map = rooms.Map( [[ rooms.Room("Dressing Room", e=True, s=True), rooms.Room("Bathroom", w=True), rooms.Room("Sun Room", s=True), rooms.Room("Kitchen", s=True, e=True), rooms.Room("Pantry", w=True) ], [
def main(): print("_________________________________________") print("HOME Building") while True: try: living_room_size = float( input("Please enter size of your living room: ")) break except ValueError: print("Error....Please enter in a number!") while True: try: kitchen_size = float(input("Please enter size of your kitchen: ")) break except ValueError: print("Error...Please enter in a number!") while True: try: dining_size = float( input("Please enter size of your dining room: ")) break except ValueError: print("Error...Please enter in a number!") while True: try: number_bed_rooms = int( input("Please enter the number of bedrooms: ")) break except ValueError: print("Error...Please enter in a number!") """Set items for the Room Object""" my_rooms = {} for i in range(number_bed_rooms): while True: try: my_bedroom = float( input("Please enter size of bedroom {}: ".format(i + 1))) break except ValueError: print("Error...Please enter in a number") # Update the dictionary my_rooms.update({"Bedroom{}".format(i + 1): my_bedroom}) my_rooms.update({ "Living Room": living_room_size, "Kitchen": kitchen_size, "Dinning Room": dining_size }) # the_gas = input("Please enter in 'yes' or 'no' if your house has gas: ").lower() # the_water = input("Please enter 'yes' or 'no' if you house has water: ").lower() rooms_1 = rooms.Room() rooms_1.set_square_feet(my_rooms) # rooms_1.set_gas(the_gas) # rooms_1.set_water(the_water) """Drop rooms attribute into House Object""" house = buildings.House(rooms_1.get_square_feet()) """Call the function for Polymorphism and print""" print("\nHOME") print("____________________") print("Your Home Siding is: {}".format(house.get_siding())) get_total_square_feet(house) # Commercial Building """Set items for the Room Object""" print("_________________________________________") print("COMMERCIAL Building") while True: try: number_rooms = int( input( "Please enter the number of rooms in your commercial building: " )) break except ValueError: print("Error...Please enter in a number!") my_com_rooms = {} for i in range(number_rooms): while True: try: my_room = float( input("Please enter size of room {}: ".format(i + 1))) break except ValueError: print("Error...Please enter in a number!") # Update the Dictionary my_com_rooms.update({"room{}".format(i + 1): my_room}) rooms_2 = rooms.Room() rooms_2.set_square_feet(my_com_rooms) print("\nCOMMERCIAL BUILDING") print("____________________") com_building = buildings.Commercial(rooms_2.get_square_feet()) print("Your Commercial Building Siding is: {}".format( com_building.get_siding())) # Call the Polymorphism function get_total_square_feet(com_building)
def control(self, connectionSocket, addr): data = receiveSomething(connectionSocket) clientNO = data[0] self.isInroom[clientNO] = False while True: data = receiveSomething(connectionSocket) if type(data) == bool: continue if data[0] == "getRoom": sendSomething(connectionSocket, ["getRoom", self.room_ID]) print(clientNO, "update room") elif data[0] == "newRoom": self.room_ID_lock.acquire() for i in range(0, 100): if i not in self.room_ID: self.room_ID.append(i) self.room_list_lock.acquire() self.room_list[i] = rooms.Room(clientNO, i) self.room_list[i].enter(clientNO, data[1]) self.room_list_lock.release() data = [True, i] self.isInroom[clientNO] = data[1] _thread.start_new_thread(self.sendPlayerInfo, (connectionSocket, clientNO)) print(clientNO, "create room", data[1]) self.initGame(data[1]) break if i == 99: data = [False] self.room_ID_lock.release() sendSomething(connectionSocket, ["newRoom", data]) elif data[0] == "enterRoom": self.room_ID_lock.acquire() if data[2] not in self.room_ID: data = [False] else: self.room_list_lock.acquire() self.room_list[data[2]].enter(clientNO, data[1]) self.room_list_lock.release() data = [True, data[2]] self.isInroom[clientNO] = data[1] _thread.start_new_thread(self.sendPlayerInfo, (connectionSocket, clientNO)) print(clientNO, "enter room", data[1]) self.room_ID_lock.release() sendSomething(connectionSocket, data) elif data[0] == "exitRoom": self.isInroom[clientNO] = False self.room_ID_lock.acquire() self.room_list_lock.acquire() self.room_list[data[1]].exit(clientNO) if not self.room_list[data[1]].players.keys(): self.room_list.pop(data[1]) self.room_ID.remove(data[1]) self.room_list_lock.release() self.room_ID_lock.release() print(clientNO, "exit room", data[1]) sendSomething(connectionSocket, "OK") elif data[0] == "start": tmp, self.isInroom[clientNO] = self.isInroom[clientNO], False print(clientNO, "start game") self.game(data, connectionSocket) self.isInroom[clientNO] = tmp elif data[0] == "myplayer_info": self.room_list_lock.acquire() self.room_list[self.isInroom[clientNO]].enter( clientNO, data[1]) self.room_list_lock.release() elif data[0] == "return room": _thread.start_new_thread(self.sendPlayerInfo, (connectionSocket, clientNO))