r_foyer = Room(title="Foyer", description="""Dim light filters in from the south. Dusty passages run north and east.""") r_overlook = Room(title="Grand Overlook", description="""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.""") r_narrow = Room(title="Narrow Passage", description="""The narrow passage bends here from west to north. The smell of gold permeates the air.""") r_treasure = Room(title="Treasure Chamber", description="""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.""") r_outside.save() r_foyer.save() r_overlook.save() r_narrow.save() r_treasure.save() # Link rooms together r_outside.connectRooms(r_foyer, "n") r_foyer.connectRooms(r_outside, "s") r_foyer.connectRooms(r_overlook, "n") r_overlook.connectRooms(r_foyer, "s") r_foyer.connectRooms(r_narrow, "e") r_narrow.connectRooms(r_foyer, "w") r_narrow.connectRooms(r_treasure, "n") r_treasure.connectRooms(r_narrow, "s") players=Player.objects.all() for p in players: p.currentRoom=r_outside.id p.save()
def generate_rooms(self, size_x, size_y, num_rooms): ''' create a room at the center, for 4 possible neighbors (n,e,s,w) create neighbor. move to created neighbors, for 3 possible new neighbors create neighbor. room_prob - set chance that a neighbor is created ''' # Initialize the grid self.grid = [None] * size_y self.width = size_x self.height = size_y for i in range(len(self.grid)): self.grid[i] = [None] * size_x # Create room at center of grid, push to queue x = size_x // 2 y = size_y // 2 curr_room = Room(id=1, title="Treasure Chamber", description="""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.""", x=x, y=y) self.grid[y][x] = curr_room curr_room.save() q = deque([(x, y)]) # Create rooms until num_rooms created room_count = 2 while room_count < num_rooms: curr_loc = q.popleft() # print("HERHERHER") # print(curr_loc) x = curr_loc[0] y = curr_loc[1] curr_room = self.grid[y][x] # check each direction, if there is not a room put that location on the q, create a room there, connect it to current room # n_to if y < (size_y - 2): if not self.grid[y + 1][x]: if self.prob_add_room(x, y + 1, room_count): q.append((x, y + 1)) # for whatever reason need to run connect rooms for each direction...not saving properly if trying to do destinationRoom.save() curr_room.connectRooms(self.grid[y + 1][x], 'n') self.grid[y + 1][x].connectRooms(curr_room, 's') print("n connection") print(f"current: {self.grid[y][x].id}") print(f"curr n_to: {self.grid[y][x].n_to}") print(f"n_to: {self.grid[y+1][x].id}") print(f"n_to s_to: {self.grid[y+1][x].s_to}") room_count += 1 # s_to if y > 0: if not self.grid[y - 1][x]: if self.prob_add_room(x, y - 1, room_count): q.append((x, y - 1)) curr_room.connectRooms(self.grid[y - 1][x], 's') self.grid[y - 1][x].connectRooms(curr_room, 'n') room_count += 1 # e_to if x < (size_x - 2): if not self.grid[y][x + 1]: if self.prob_add_room(x + 1, y, room_count): q.append((x + 1, y)) curr_room.connectRooms(self.grid[y][x + 1], 'e') self.grid[y][x + 1].connectRooms(curr_room, 'w') room_count += 1 # w_to if x > 0: if not self.grid[y][x - 1]: if self.prob_add_room(x - 1, y, room_count): q.append((x - 1, y)) curr_room.connectRooms(self.grid[y][x - 1], 'w') self.grid[y][x - 1].connectRooms(curr_room, 'e') room_count += 1
room88.save() room89.save() room90.save() room91.save() room92.save() room93.save() room94.save() room95.save() room96.save() room97.save() room98.save() room99.save() room100.save() # Link rooms together room1.connectRooms(room2, "s") room2.connectRooms(room1, "n") room2.connectRooms(room3, "s") room3.connectRooms(room2, "n") room3.connectRooms(room4, "s") room4.connectRooms(room3, "n") room4.connectRooms(room5, "s") room5.connectRooms(room4, "n") room5.connectRooms(room6, "s") room6.connectRooms(room5, "n") room6.connectRooms(room7, "s")
def create(): print("Create star system...") Room.objects.all().delete() # create rooms epsilon_lyrae = Room( title="Epsilon Lyrae", description= "Famously known as being a double star – two stars in one with each star is also a double. The double double star!", locx=250, locy=60) alpha_lyrae = Room( title="Alpha Lyrae (Vega, Fidis, Harp Star)", description= "Brightest star in Lyra constellation and the fifth brightest star in the sky.", locx=308, locy=110) zeta1_lyrae = Room( title="Zeta1 Lyrae", description= "Contains as many as 7 individual stars. However is often over looked by near by neighbors.", locx=288, locy=168) delta2_lyrae = Room( title="Delta2 Lyrae", description= "Pulsating luminous giant star consisting of one super hot blue star, next to a yellow star.", locx=187, locy=183) gamma_lyrae = Room( title="Gamma Lyrae (Sulafat)", description= "Second-brightest star in the northern constellation and can be seen with the naked eye from Earth.", locx=147, locy=338) beta_lyrae = Room( title="Beta Lyrae", description= "'Made of 2 stars that are so close that their shapes are heavily distorted by mutual gravitation forces: the stars have ellipsoidal shapes.", locx=236, locy=325) # save newly created rooms epsilon_lyrae.save() alpha_lyrae.save() zeta1_lyrae.save() delta2_lyrae.save() gamma_lyrae.save() beta_lyrae.save() # create links between rooms epsilon_lyrae.connectRooms(alpha_lyrae, "s") alpha_lyrae.connectRooms(epsilon_lyrae, "n") alpha_lyrae.connectRooms(zeta1_lyrae, "s") zeta1_lyrae.connectRooms(alpha_lyrae, "n") zeta1_lyrae.connectRooms(beta_lyrae, "s") zeta1_lyrae.connectRooms(delta2_lyrae, "w") delta2_lyrae.connectRooms(gamma_lyrae, "s") delta2_lyrae.connectRooms(zeta1_lyrae, "e") gamma_lyrae.connectRooms(delta2_lyrae, "n") gamma_lyrae.connectRooms(beta_lyrae, "e") beta_lyrae.connectRooms(zeta1_lyrae, "n") beta_lyrae.connectRooms(gamma_lyrae, "w") # reset all players to starting room players = Player.objects.all() for p in players: p.currentRoom = epsilon_lyrae.id p.save()
def create_rooms(): Room.objects.all().delete() r_outside = Room(title="Outside Cave Entrance", description="North of you, the cave mount beckons") r_foyer = Room( title="Foyer", description="""Dim light filters in from the south. Dusty passages run north and east.""") r_overlook = Room( title="Grand Overlook", description="""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.""") r_narrow = Room(title="Narrow Passage", description="""The narrow passage bends here from west to north. The smell of gold permeates the air.""") r_treasure = Room(title="Treasure Chamber", description="""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.""") r_outside.save() r_foyer.save() r_overlook.save() r_narrow.save() r_treasure.save() # Link rooms together r_outside.connectRooms(r_foyer, "n") r_foyer.connectRooms(r_outside, "s") r_foyer.connectRooms(r_overlook, "n") r_overlook.connectRooms(r_foyer, "s") r_foyer.connectRooms(r_narrow, "e") r_narrow.connectRooms(r_foyer, "w") r_narrow.connectRooms(r_treasure, "n") r_treasure.connectRooms(r_narrow, "s") players = Player.objects.all() for p in players: p.currentRoom = r_outside.id p.save()