def new_game(): global birthdaysuit, barehands config.turns = 0 #create the dungeon floor list config.floors = [] config.current_floor = 0 #create list of nodes config.nodes = [] config.flares = [] #create object representing the player armor_component = game.Armor(ac=0) item_component = game.Item(armor=armor_component) birthdaysuit = game.Object(0, 0, '[', 'Birthday Suit (worn)', libtcod.dark_orange, item = item_component) weapon_component = game.Weapon(mindmg=1, maxdmg=3, hitdie=2) item_component = game.Item(weapon=weapon_component) barehands = game.Object(0, 0, ')', 'Bare hands (wielded)', libtcod.light_blue, item = item_component) scanner_component = game.Scanner() item_component = game.Item(scanner=scanner_component) def_scanner = game.Object(0, 0, 's', 'Scanner', libtcod.dark_green, item = item_component) fighter_component = game.Fighter(plclass='Hellstronaut', ac=0, str=10, dex=10, con=10, int=10, fth=10, per=10, equipweapon=barehands, equiparmor=birthdaysuit, equipscanner=def_scanner, equipheadlamp=None, equiptank=None, equipcamo=None, hitdie = 0, mindmg = 0, maxdmg = 0, hp=100, defense=2, power=5, o2=200, death_function=game.player_death) config.player = game.Object(0, 0, '@', 'Dwayne', libtcod.white, blocks=True, fighter=fighter_component) mapgen.make_map() config.floors.append([config.map, config.objects, config.nodes, config.flares]) gfx.initialize_fov() #create inventory config.inventory = [] config.inventory.append(def_scanner) def_scanner.item.equip_scanner() #create the list of game messages and their colors, starts empty config.game_msgs = [] config.game_state = 'playing' #a warm welcoming message! gfx.message('Welcome to Hell.', libtcod.red)
def load_game(): #open the previously saved shelve and load the game data file = shelve.open('savegame', 'r') config.map = file['map'] config.objects = file['objects'] config.player = config.objects[file['player_index']] #get index of player in objects list and access it config.beast = config.objects[file['player_index']] #get index of player in objects list and access it config.floors = file['floors'] config.current_floor = file['current_floor'] config.inventory = file['inventory'] config.game_msgs = file['config.game_msgs'] config.game_state = file['config.game_state'] file.close() gfx.initialize_fov()
def go_to_floor(dest): #pdb.set_trace() if dest > (len(config.floors)-1): #floor has not been generated yet, so generate it #store previous floor config.floors[config.current_floor][0] = config.map config.floors[config.current_floor][1] = config.objects config.floors[config.current_floor][2] = config.nodes config.floors[config.current_floor][3] = config.flares mapgen.make_map() config.floors.append([config.map, config.objects, config.nodes, config.flares]) else: #floor has been generated config.map = config.floors[dest][0] config.objects = config.floors[dest][1] config.nodes = config.floors[dest][2] config.flares = config.floors[dest][3] if dest < config.current_floor: #ascending for object in config.objects: if object.stairs and object.stairs.direction == "down": #find location of stairs_down from destination floor and place config.player there config.player.x = object.x config.player.y = object.y break elif dest > config.current_floor: #descending for object in config.objects: if object.stairs and object.stairs.direction == "up": #find location of stairs_down from destination floor and place config.player there config.player.x = object.x config.player.y = object.y break else: gfx.message('Something\'s kinda weird.', libtcod.red) config.current_floor = dest gfx.initialize_fov()