def main_game_loop(hero): print(hero.name) game_levels = ("room", "boss", "room", "room", "boss", "end") for level in range(len(game_levels)): # cause everything is zero index LEVEL = level + 1 game_level = game_levels[level] print("You are at level {}: {}".format(LEVEL, game_level)) print_slow("What would you like to do?" + "\n") choice = base_choices() while choice != "explore": if choice == "inventory": hero.view_inventory() choice = base_choices() if choice == "quit": quit("Only cowards run from glory...") room(hero, LEVEL, game_level) hero.level_up() LEVEL += 1 # proceed to junction # handle room should not proceed if inventory option chosen if hero.health <= 0: break print("Well played! Game over...")
def __init__( self, no_rooms_wide=2, no_rooms_long=2, room_width=10, room_length=10, init_room_visibility=True, ): self.no_rooms_wide = no_rooms_wide self.no_rooms_long = no_rooms_long self.room_width = room_width self.room_length = room_length temp_room = room() self.no_door = temp_room.no_door # value used for no door self.rooms = [] # rooms is list of room objects for room_no in range(self.no_rooms_wide * self.no_rooms_long): self.rooms.append( room( size=(self.room_length, self.room_width), doors=(self.no_door, self.no_door, self.no_door, self.no_door), # Doors, none windows=(0, 0, 0, 0), # Windows, none visible=init_room_visibility, )) self.room_map = np.empty((self.no_rooms_long, self.no_rooms_wide), dtype=int) for vert_room in range(self.no_rooms_long): for horiz_room in range(self.no_rooms_wide): self.room_map[vert_room, horiz_room] = (vert_room * self.no_rooms_wide + horiz_room)
def current_room(): print("You are in room:", ROOM_NUMBER, "\n") room(ROOM_NUMBER) response = input( "You see two doors, one to the left, and one to your right! Which one do you want to open?\n" ) response = validate_input(response) if response == "left": enter_left_room() if response == "right": enter_right_room()
def initRoomListFromDB(self, sqlMana=None): sql = 'select ID from room where houseID = %d' % self.ID res = sqlMana.query(sql) for temp in res: tempRoom = room() tempRoom.readInfoFromDB(temp.get('ID'), sqlMana) self.roomList.append(tempRoom)
def build_house(self,pos): r = rooms.room(pos,self) r.type = 'house' r.generate() r.randomize() self.map[pos[0]][pos[1]] = r
def build_field(self,pos): r = rooms.room(pos,self) r.type = 'field' r.flags['sunlit'] = True r.randomize() self.map[pos[0]][pos[1]] = r
def build_clearing(self,pos): r = rooms.room(pos,self) r.type = 'clearing' r.flags['sunlit'] = True r.randomize() self.map[pos[0]][pos[1]] = r
def game_loop(karbar: user): # values karakters = values.karakters_game_loop() dict_user_karakter = OrderedDict() my_bot = defs(values.bot_token()) keyboard_game_init = values.game_loop_keyboard_init() user_id = karbar.ID SQL = values.sql_connect() cursor = SQL.cursor() server = room(karbar) server_loc = server.server_loc # مرحله حذف شدن کاراکتر اول x = my_bot.random_karakter() my_bot.send_group(server_loc, 'سیستم', 'کاراکتر %s حذف شد' % x[0]) karakters.remove(x[0]) # مرحله انتخاب کاراکتر شانسی x = my_bot.random_karakter(karakters, 7) c = 0 cursor.execute('SELECT ID FROM %s' % server_loc) users_id_server = cursor.fetchall() for har_user in users_id_server: my_bot.send_message(har_user[0], 'کاراکتر شما هست: %s' % x[c]) dict_user_karakter[karakters[c]] = har_user c += 1 # خود بازی my_bot.change_keyboard(user_id, keyboard_game_init) for message in my_bot.get_message(): my_bot.change_keyboard(user_id, keyboard_game_init) if message['from'] == user_id: if message['type'] == 'TEXT': if message['body'][0:2] == '//': # اجرا کردن دستور کیبورد vorodi = message['body'] if vorodi == '//exit_game': if my_bot.exit_game(user_id, server_loc): my_bot.send_message(user_id, 'باموقیت از سرور خارج شدید') tmp_message = 'کاربر %s از بازی خارج شد و شهرش نابود شد' % karbar.name my_bot.send_group(server_loc, 'سیستم', tmp_message) main_page(karbar) if vorodi == '//magics': my_bot.magics_game(user_id) if vorodi == '//daraiy_ha': my_bot.daraiy_ha_game(user_id, server) my_bot.change_keyboard(user_id, keyboard_game_init) else: my_bot.send_group(server_loc, karbar.name, message['body'], keyboard_game_init) else: my_bot.send_message(user_id, 'فرمت پیام صحیح نیست', keyboard_game_init)
def generate(self): for pos in [[0,-1],[-1,0],[1,0],[0,1]]: r = rooms.room((self.loc[0]+pos[0],self.loc[1]+pos[1]),var._c) r.parent_pos = self.loc r.type = self.type r.flags['sunlit'] = True r.green = self.green - 10 r.walk_dir = self.walk_dir r.randomize() var._c.map[self.loc[0]+pos[0]][self.loc[1]+pos[1]] = r
def load_rooms(path): f = open(path+"/rooms.txt","r") data = f.read() data = data.split(";") loaded_rooms = [] if data[len(data)-1] == "\n" or data[len(data)-1] == "\n\n" or data[len(data)-1] == "": del data[len(data)-1] for room in data: room = room.split(",") room[0] = room[0].strip("\n") vars()[room[0]] = rooms.room(room[0],room[1],room[2],room[3],room[4],room[5],room[6],room[7],room[8]) loaded_rooms.append(vars()[room[0]]) return loaded_rooms
def createHouseStructure(self, roomList): print 'in createHouseStructure' self.roomList = [] roomNum = len(roomList) for roomName in roomList: flag = True while (flag): flag = False tempPosX = random.randint(0, self.width * 2 / 3 - 1) tempPosY = random.randint(0, self.height * 2 / 3 - 1) for tempRoom in self.roomList: if (tempPosX == tempRoom.getLeft() and tempPosY == tempRoom.getTop()): flag = True break newRoom = room(-1, roomName, tempPosX, tempPosX, tempPosY, tempPosY) self.roomList.append(newRoom) # print 'end of seed create' endFlag = False while (not endFlag): endFlag = True for tempRoom in self.roomList: # right add flag = True newRight = tempRoom.getRight() + 1 if (newRight >= self.width): flag = False for tempY in range(tempRoom.getTop(), tempRoom.getBottom() + 1): for existRoom in self.roomList: if (existRoom.isInRoom(newRight, tempY)): flag = False break if (newRight - tempRoom.getLeft() > self.width / 3): flag = False break if (flag == False): break if (flag): tempRoom.setRight(newRight) endFlag = False # bottom add flag = True newBottom = tempRoom.getBottom() + 1 if (newBottom >= self.height): flag = False for tempX in range(tempRoom.getLeft(), tempRoom.getRight() + 1): for existRoom in self.roomList: if (existRoom.isInRoom(tempX, newBottom)): flag = False break if (newBottom - tempRoom.getTop() > self.height / 3): flag = False break if (flag == False): break if (flag): tempRoom.setBottom(newBottom) endFlag = False # print 'loop' flag = True for tempRoom in self.roomList: if (tempRoom.getSquare() < (self.height * self.width) / roomNum / 4): flag = False if (not flag): self.createHouseStructure(roomList)
y_offset = 0 x_offset = 0 if x_offset or y_offset: # If a valid direction, dir, was given. self.map[2 * y + 1 + y_offset][2 * x + 1 + x_offset] = barrier else: print("Direction is not valid.") else: print("Coordinates out of bounds.") if __name__ == "__main__": a = adventure(2, 3) ### Rooms room = rooms.room() red_room = rooms.red_room() blue_room = rooms.blue_room() green_room = rooms.green_room() goal = rooms.final_room() a.add_room(room, 1, 1) a.add_room(red_room, 0, 0) a.add_room(blue_room, 0, 1) a.add_room(green_room, 0, 2) a.add_room(goal, 1, 2) ### Barriers passage = barriers.passage() passage_2 = barriers.passage()
import rooms home = rooms.room('Home',[0,0]) home.message = 'Welcome to the pyventure homesquare' field = rooms.room('Field',[1,0]) field.message = 'You stand in a large empty field' factory = rooms.room('Factory',[2,0]) factory.message = 'You arrive in a large factory with broken windows vista'
small_box_item_list = [small_emerald, large_diamond, pile_of_gold_coins] small_box = workbench.workbench('A small box', descriptions.small_box_description, 3, small_box_item_list) # create the items lists rustic_bench_items_list = [ small_bowl, medium_bowl, small_knife, slimey_goo, small_pick ] metal_bench_items_list = [large_bowl, large_knife, small_hammer, small_box] # Initialize all the workbenches rustic_bench = workbench.workbench('Rustic workbench', descriptions.rustic_bench_description, 10, rustic_bench_items_list) metal_bench = workbench.workbench('Metal workbench', descriptions.metal_bench_description, 20, metal_bench_items_list) restraining_table = workbench.workbench( 'Restraining table', descriptions.restraining_table_description, 15, []) # # Initialize all the rooms entry_room = rooms.room('Entry', descriptions.entry_description, ['West'], [thatched_matt]) hallway = rooms.room('Hallway', descriptions.hallway_description, ['East', 'West'], [torch]) chamber = rooms.room('Chamber', descriptions.chamber_description, ['West', 'East', 'South'], [rustic_bench, metal_bench, restraining_table]) # Initialize the dungeon
def build_road(self,pos): r = rooms.room(pos,self) r.type = 'road' r.flags['sunlit'] = True self.map[pos[0]][pos[1]] = r
#python import rooms import items import people import npcs import weapons import armors centralRooms=[ #(location, adjacent rooms[n,s,e,w], description, dark, inventory, containers, monsters, bed, people, secret passageways[n,s,e,w]) rooms.room(0, [3,1,-1,-1], "\nYou are in a small cellar.\nThere is a stairwell to the north.\nThere is a small crack in the wall to the south that you may be able to fit through.", True, [], {}, [], False, [], [False, False, False, False]), rooms.room(1, [0,2,-1,-1], "\nYou are in a small winding rocky corridor.\nThere is a small opening to the north.\nThe corridor continues south.", True, [], {}, [], False, [], [False, False, False, False]), rooms.room(2, [1,-1,-1,-1], "\nYou are in a small cave.\nThere is a waterfall filling a pool of water to the south.\nThere is a small crack in the wall to the north that you may be able to fit through.", True, [items.item("gem")], {}, [npcs.npc("bugbear",10,2,4)], False, [], [False, False, False, False]), rooms.room(3, [5,0,4,6], "\nYou are in a small kitchen.\nThere is a table with three chairs in front of you.\nIn the northwest corner of the room there is an oven.\nIn the northeast corner there is a cupboard.\nThere are doors to the north, east, and west.\nTo the south is a staricase descending down.", False, [], {"cupboard":[False,items.item("garlic"),items.item("salt"),items.healthPotion()]}, [], False, [], [False, False, False, False]), rooms.room(4, [7,-1,10,3], "\nYou are in the backyard of an old log house.\nThere is an old battered door on the side of the house to your west.\nThere are paths into the woods to the east and north.", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(5, [-1,3,-1,8], "\nYou are in a rectangular room.\nThere is a long table that appears to have hosted many meals in the center of the room.\nThere is cake on the table.\nOutside of the table and doors to the south and west there is not much here.", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(6, [8,-1,3,9], "\nYou are in a small cozy room.\nThere is a fireplace that does not appear to have been used in quite some time.\nThere are two lounge charis in the center of the room.\nThere are doors to the north, east, and west.\nThe west wall has two boarded up windows on either side of the door.", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(7, [-1,-1,4,9], "\nYou are on a wooded pathway.\nThe path continues to the east and west.", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(8, [-1,6,5,-1], "\nYou are in a tiny room.\nThere is a disheveled bed in the corner of the room.\nThere are doors to the south and east.", False, [], {}, [], True, [], [False, False, False, False]), rooms.room(9, [7,12,6,-1], "\nYou are on the porch of an old wooden house.\nThe house has a door to the east.\nOn either side of the door are boarded up windows.\nThere is a mail box infront of the door.\nThere is a garden path to the north and a road leading south.", False, [], {"mailbox":[False,items.item("letter")]}, [], True, [], [False, False, False, False]),
def main(): lounge = room('lounge') player_one = player('Lincoln') player_two = player('Sunny') # player_three = player('David') player_one.join(lounge) player_two.join(lounge) # player_three.join(lounge) randomCard(lounge, 'Lincoln', 7) # randomCard(lounge, 'David', 3) randomCard(lounge, 'Sunny', 7) lounge.lastCard = lounge.cards_not_used[randint( -1, len(lounge.cards_not_used)-1)] while analyseCard(lounge.lastCard)[1] == '+2' or analyseCard(lounge.lastCard)[1] == '+4' or analyseCard(lounge.lastCard)[1] == 'Reverse' or analyseCard(lounge.lastCard)[1] == 'Skip': lounge.lastCard = lounge.cards_not_used[randint( -1, len(lounge.cards_not_used)-1)] lounge.currentColour = analyseCard(lounge.lastCard)[0] lounge.currentType = analyseCard(lounge.lastCard)[1] lounge.plusCount = 0 import os # try: # while True: # try: # p = lounge.players[lounge.playTurn[lounge.currentPlayer]] # except KeyError: # raise GameCompleted # Tips='Press . for more card' # accepted=False # while not accepted: # os.system('cls') # print('Now',p.pid,'is playing:') # print('Last card:',lounge.currentColour,analyseCard(lounge.lastCard)[3]) # for c in p.allCards(): try: while lounge: y = False p = False alreadyM = False unable = False Tip = 'Press . for more card.' chosen = [] while y == False: try: x = lounge.playTurn[lounge.currentPlayer] x = lounge.players[x] except: raise GameCompleted os.system('cls') print('Now', x.pid, 'is playing...') lasta = analyseCard(lounge.lastCard) print('Last card:', lounge.currentColour, lasta[3]) print('You have', len(x.allCards()), 'cards:') for z in x.allCards(): print(z, x.cards[z].ccolour, x.cards[z].cdescription, end='', sep='\t') if z in chosen: print('\tCHOSEN:'+str(chosen.index(z)+1)) else: print('') if Tip != '': print('* '+Tip) Tip = 'Press . for more card or press enter to submit.' if lounge.plusCount > 0: print('* Pending +'+str(lounge.plusCount) + '. Choose a +2 or +4 to avoid it.') i = input('>') if i == '': if len(chosen) == 0: Tip = 'Please choose at least 1 card or press . for more card.' unable = True continue if not x.play(chosen): Tip = 'Unable to play those cards. Please try other cards.' unable = True chosen = [] else: chosen = [] continue if i == '.': if alreadyM: cards.applyPlus(lounge,x) lounge.nextPlayer() break alreadyM = True Tip = 'Press . if you still can not make a selection.' randomCard(lounge, x, 1) y = False continue if i in x.allCards(): if i in chosen: chosen.remove(i) else: chosen.append(i) elif len(i) == 2 and i in [ll[:2] for ll in x.allCards()]: for ii in x.allCards(): if ii[:2] == i: if ii in chosen: chosen.remove(ii) else: chosen.append(ii) else: if unable == False: Tip = 'You do not own that card.' unable = False except GameCompleted: print('Game Ended')
e1.add_skill(M1,"n") e1.add_skill(M1,"n") e1.add_skill(M5,"n") e1.add_loot(A8) success = combat.encounter(p1,e1) if success == (True): print("Finished!") else: print("Finished!") elif action == 3: e1.add_loot(A8) e1.display_loot() print("WAITING...") time.sleep(3) e1.drop_loot(p1) elif action == 4: p1.display_all() e1.display_all() elif action == 5: stats=["hp","atk","def","mag","agl"] growth=[] for i in range(0,5): ele = int(input(stats[i]+": ")) growth.append(ele) p1.add_growths(growth) for i in range(0,5): print(stats[i] + ": " + str(p1.weights[i]) + "%") elif action == 6: r1=rooms.room("c",p1.level) r1.display() r1.enter(p1)
def addRoom(self, name): r = room(name) self.rooms[name] = r return r
#!/usr/bin/python import rooms import items import people import npcs import weapons import armors castleRooms = [ #(location, adjacent rooms[n,s,e,w], description, dark, inventory, containers, monsters, bed, people, secret passageways[n,s,e,w]) rooms.room(34, [36, 37, 35, 32], "\n34", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(35, [47, 48, -1, 34], "\n35", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(36, [-1, -1, 38, 34], "\n36", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(37, [-1, 39, 38, 34], "\n37", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(38, [36, 37, 40, -1], "\n38", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(39, [37, 41, 42, -1], "\n39", False, [], {}, [], False, [], [False, False, True, False]), rooms.room(40, [-1, -1, 43, 38], "\n40", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(41, [39, -1, -1, -1], "\n41", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(42, [-1, 44, -1, 39], "\n42", False, [], {}, [], False, [], [False, False, False, False]), rooms.room(43, [-1, -1, 46, 40], "\n43", False, [], {}, [], False, [], [False, False, True, False]),
def appendRoom(self, ID, roomType, centerPosX, centerPosY, width, height): newRoom = room(-1, roomType, centerPosX, centerPosY, width, height) roomList.append(newRoom) return