def examineEnemy(self, thisRoom, object): for e in self.rooms[thisRoom].enemies: if e.name == object: description = e.description std.prettyPrint(object.capitalize(), [description]) return True return False
def useObject(self, item): returnStatus = False itemValue = self.map.rooms[self.currentRoom].use[item] if item == 'button' or item == 'lever': print(itemValue['description']) # TODO Revisit buttons. Whhat else should they be able to do? for action in itemValue: if action == 'unlock': self.map.unlockAction(self.currentRoom, itemValue[action][1], itemValue[action][0]) elif action == 'spawn': self.map.spawnAction(self.currentRoom, itemValue[action], self.resources) # Actions are single use, remove from the map once used del self.map.rooms[self.currentRoom].use[item] returnStatus = True elif item == 'chest' or item == 'crate': # Pretty print container contents to user itemValueNames = [] for i in itemValue: itemValueNames.append(self.resources['items'][i]['name']) std.prettyPrint(item, itemValueNames) # The user can take all or none of the items in the container if 'y' == std.optionParse('Take all the items?', ['y', 'n']): self.player.getItems(itemValue, self.resources) # Actions are single use, remove from the map once used del self.map.rooms[self.currentRoom].use[item] returnStatus = True else: print('Unexpected item.') return returnStatus
def look(self, thisRoom): body = [] body.append(self.rooms[thisRoom].description) body.append('') # Display connection information connList = self.rooms[thisRoom].connections if connList: body.append(f'There are a few connections from this room:') for k, v in connList.items(): body.append(f' To the {k.capitalize()} is {v.capitalize()}') else: body.append('There are no connections in this room.') # Display enemy information enemyList = self.rooms[thisRoom].enemies if enemyList: body.append('') enemyNames = [e.name for e in enemyList] enemyDescriptions = [e.description for e in enemyList] body.append(f'There are a few enemies here:') for k, v in zip(enemyNames, enemyDescriptions): body.append(f' {k} : {v}') std.prettyPrint(self.rooms[thisRoom].title, body) return True
def examineObject(self, thisRoom, object): for o in self.rooms[thisRoom].examine: if o == object: description = self.rooms[thisRoom].examine[o] std.prettyPrint(object.capitalize(), [description]) return True return False
def printStats(self): header = f'{self.pName} the {self.pClass.capitalize()}' # Get the printable text body = [] if self.upgradesAvailable: body.append(f'Lvl ({self.upgradesAvailable}): {self.level}') else: body.append(f'Lvl: {self.level}') body.append(f'Exp: {self.exp} / {MAX_EXP}') body.append('') body.append(f'HP: {self.hp} / {self.MAX_HP}') body.append(f'Gold: {self.gold}') body.append('') body.append(f"ATK: {self.stats['atk'][0]}..{self.stats['atk'][1]}") body.append(f"INT: {self.stats['int'][0]}..{self.stats['int'][1]}") body.append(f"DEF: {self.stats['def'][0]}..{self.stats['def'][1]}") if self.abilities: prettyAbilities = [ self.abilities[a]['name'] for a in self.abilities.keys() ] body.append('') body.append('Abilities: ' + ', '.join(prettyAbilities)) # Hand off the print to the helper std.prettyPrint(header, body)
def help(self): # Get the printable text body = [] for k, v in self.verbs.items(): body.append(f'{k}: {v}') # Hand off the print to the helper std.prettyPrint('HELP', body) return True
def displayMap(self, options, player): # Initalize data structures mapLen = int(math.sqrt(len(self.rooms.keys()))) mapArr = [[' ' for x in range(mapLen)] for y in range(mapLen)] eastConn = [[' ' for x in range(mapLen)] for y in range(mapLen)] southConn = [[' ' for x in range(mapLen)] for y in range(mapLen)] # (Optionally) Print the legend if options == '-l': body = [] body.append('S : Save Room') body.append('~ : Hidden') std.prettyPrint('Map Legend', body) # Create 2D map and border arrays for room in self.rooms.values(): roomCoord = room.coordinates roomIcon = room.icon # If the player has the area map, display the icon if player.inInventory(f"{room.area} Area Map"): mapArr[roomCoord[0]][roomCoord[1]] = roomIcon # If this is an empty room, display filled in icon elif room.title == 'empty': mapArr[roomCoord[0]][roomCoord[1]] = '#' # Else, display a fog else: mapArr[roomCoord[0]][roomCoord[1]] = '~' # If this room has connections, note them on the map connections = room.connections.keys() strVal = ' ' if 'east' not in connections: strVal = '|' eastConn[roomCoord[0]][roomCoord[1]] = strVal strVal = ' +' if 'south' not in connections: strVal = '---+' southConn[roomCoord[0]][roomCoord[1]] = strVal # Piece together the map and display print('+' + ('---+' * len(mapArr))) for i in range(len(mapArr)): # Print the rooom information rowStr = '|' for j in range(len(mapArr[i])): rowStr += f' {mapArr[i][j]} {eastConn[i][j]}' print(rowStr) # Print the divider information dividerStr = '+' for d in southConn[i]: dividerStr += d print(dividerStr) return True
def getAbility(self, stat): ability = abStructure[stat] # Report ability to the player body = [] body.append( f"You collected the {ability['name']} and recieved a new ability.") body.append(f"The relic reads: {ability['description']}") std.prettyPrint('New Ability', body) # Give the ability self.abilities[stat] = ability
def battle(self, e, statTuple): # Enemy battle information statType = statTuple[0] eStatVal = statTuple[1] # Get the players battle value from within the range pStatVal = randint(self.stats[statType][0], self.stats[statType][1]) # Prepare for pretty print body = [] body.append(f'{self.pName}: {pStatVal}') body.append(f"{e.name}: {eStatVal}") std.prettyPrint(f'{statType} Battle', body) return pStatVal > eStatVal
def printEquipment(self, options): if not ''.join([str(e) for e in self.equipment.values()]): print('You are not wearing any equipment.') return False # Get the printable text body = [] for pos, e in self.equipment.items(): if e: if options == '-l': # Long print description body.append(f'[{pos}] {e.name}: {e.description}') else: body.append(f'[{pos}] {e.name}') # Hand off the print to the helper std.prettyPrint('EQUIPMENT', body)
def topTrumpBattle(self, e): eStats = list(e.stats.keys()) # Report the stats comparison body = [] body.append(f"{self.pName} vs. {e.name}") for s in eStats: pStatMin = self.stats[s][0] pStatMax = self.stats[s][1] eStat = e.stats[s] body.append(f'{s}: {pStatMin}..{pStatMax} vs. {eStat}') # Hand off the print to the helper std.prettyPrint('Stat Comparison', body) # Ask player which stat to battle selectedStat = std.optionParse('Select stat to use in battle:', eStats) # Get the enemy value and return the battle statTuple = (selectedStat, e.stats[selectedStat]) return self.battle(e, statTuple)
def introSequence(): print( ' _____ __ __ ______ _ _ _______ _ _ _____ ______ ' ) print( ' /\ | __ \ \ \ / / | ____| | \ | | |__ __| | | | | | __ \ | ____|' ) print( ' / \ | | | | \ \ / / | |__ | \| | | | | | | | | |__) | | |__ ' ) print( ' / /\ \ | | | | \ \/ / | __| | ` | | | | | | | | _ / | __| ' ) print( ' / ____ \ | |__| | \ / | |____ | |\ | | | | |__| | | | \ \ | |____ ' ) print( '/_/ \_\ |_____/ \/ |______| |_| \_| |_| \____/ |_| \_\ |______|\n' ) # Get the player name pName = input('Welcome adventurer. What shall I call you? ') # Display classes to user and get the player class pClasses = { 'Brute': 'A bullheaded fighter with lots of strength but no tactical defense.', 'Scholar': 'An intelligent master of the books; saved little time for strength training.', 'Defender': 'A defensive master with average strength and little time for intellect.' } body = [] for k, v in pClasses.items(): body.append(f'{k}: {v}') std.prettyPrint('Class Selection', body) pClass = std.optionParse('Select your class:', list(pClasses.keys())) return (pName, pClass)
def examine(self, noun, options): if noun is None: print('Please specify an object.') return False object = (noun + ' ' + ' '.join(options)).strip() examineSuccess = False # 1) Examine objects in the room (if they are there) if not examineSuccess: examineSuccess = self.map.examineObject(self.currentRoom, object) # 2) Examine enemies in the room if not examineSuccess: examineSuccess = self.map.examineEnemy(self.currentRoom, object) # 3) Examine objects in the player inventory if not examineSuccess: for i in self.player.inventory: if i.name == object: description = i.description std.prettyPrint(object.capitalize(), [description]) examineSuccess = True return examineSuccess
def printInventory(self, options): if not self.inventory: print('Your inventory is empty.') return False # Get the inventory list with counts countItems = {} for i in self.inventory: if i.name in countItems: countItems[i.name] += 1 else: countItems[i.name] = 1 # Get the printable body body = [] for k, v in countItems.items(): c = f'({v}) ' if v > 1 else '' # Only print counts greater than 1 if options == '-l': # Long print description body.append(f'{c}{k}: {i.description}') else: body.append(f'{c}{k}') # Hand off the print to the helper std.prettyPrint('INVENTORY', body)