def __init__(self, hp, gold, inv, name): self.gold = gold self.hp = hp self.name = name self.inv = inventory() self.max_hp = 20 self.armor = 0
def __init__(self, id_prefix, pos=sc([0, 0, 0]), mass=100000.0): global id_count if type(pos) == sc: self.position = pos else: self.position = sc(pos) self.inventory = items.inventory() self.identifier = id_prefix + "-" + "%06i" % id_count self.heading = Quaternion() id_count += 1 global objects objects.append(self) logging.info("New object: " + str(self))
def combat(boss, player): border = "---------------------" print("") print("The big bad", boss.name, " appears!") print(border) print( "Known througout the galaxy as a menace, you are charged with taking down this darkest of evils" ) print("Are you strong enough to face the oncoming storm?") print(border) print("player stats:") print(border) player.getStats() time.sleep(1) print("") print(border) print("enemy stats:") print(border) boss.getStats() if boss.SPD > player.SPD: curTurn = "Enemy" elif player.SPD > boss.SPD: curTurn = "Player" else: if random.randint(1, 2) == 1: curTurn = "Player" else: curTurn = "Enemy" fled = False while player.HP > 0 and boss.HP > 0 and not fled: if curTurn == "Player": print("Select your Action: >Physical >Energy >Item") selection = "" while (selection not in ("Physical", "Energy", "Flee", "Item")): selection = input("-->").title() if selection == "Physical": print("You attack the", boss.name, "with physical weapons") time.sleep(1) boss.takePDamage(player.PHY) curTurn = "Enemy" elif selection == "Energy": print("You use energy weapons on the", boss.name) time.sleep(1) boss.takeEDamage(player.ENG) curTurn = "Enemy" elif selection == "Item": print("pick and item to use: ") player, curTurn = items.inventory(player) elif selection == "Flee": print("You can not run from a trainer battle.") elif selection == "Item": pass #list of usable items #use "while selection not in" to make sure input is an item #activate item buff #remove item from inventory elif curTurn == "Enemy": atType = random.randint(1, 100) if boss.PHY >= boss.ENG: if atType > 10: print("The big bad", boss.name, "fires upon you with physical weapons!") time.sleep(1) player.takePDamage(boss.PHY) else: print("The big bad", boss.name, "fires energy weapons! Those are hot stuff!") time.sleep(1) player.takeEDamage(boss.ENG) elif boss.PHY < boss.ENG: if atType > 10: print("The big bad", boss.name, "uses energy weapons! Those are hot stuff!") time.sleep(1) player.takeEDamage(boss.ENG) else: print("The big bad", boss.name, "fires upon you with physical weapons!") time.sleep(1) player.takePDamage(boss.PHY) else: print("An Error Occured...") curTurn = "Player" if player.HP <= 0: print("-----------------") print( "You faught valiantly in the final battle but alass, the big bad ", boss.name, " was too much for you. \n Better luck next time!") print("-----------------") playerRes = "L" elif fled == True: print("wait, how did you? um... this isn't suposed to be possible...") time.sleep(1) print("well, guess we are here now.") time.sleep(1) print("maybe you should close this window.") time.sleep(10) print("why are you still here?") time.sleep(2) print( "are you looking for an easter egg? because there isn't one, this is a serious error, you were never meant to get here." ) time.sleep(10) print("you aren't going to close this are you?") time.sleep(1) print("fine, i'll do it myself.") player.HP = 0 playerRes = "L" pass else: playerRes = "W" return player, playerRes
def main(): try: validResponse = False while not validResponse: loadSave = str( input("Would you like to load an existing save? [Y/N]? ")) if loadSave == "Y" or loadSave == "N": validResponse = True else: print("That is not yes or no") if loadSave == "N": print("Beginning Game") player = CharCreator.main() board = createBoard(7, 7, player) elif loadSave == "Y": fileName = str(input("Input Saved Game's FileName")) board, player = load(fileName + ".sav") board.printBasicBoard() #main - handles the overarching game #load save (y/n)? #if no #create the player #create the board #if yes, load given save file. #check to make sure the file is a pickle file containing a legit save. #display the board #display character stats and other relevant info playerWon = False playerDead = False SPECIALCHAR = 100 UP = 72 DOWN = 80 LEFT = 75 RIGHT = 77 Q = 113 S = 115 I = 105 D = 100 T = 116 ordList = [SPECIALCHAR, UP, DOWN, LEFT, RIGHT, Q, S, I, D, T, 224] system("cls") print( "On the following map, you are marked as a 'P', enemies are 'E', various spacial anomalies are 'A' and your final challenge is marked as 'B'" ) time.sleep(5) while not playerWon and not playerDead: #check if the player has won, or is dead. if either is true move to the appropriate endGame function, else move on system("cls") print(board.printBasicBoard()) print( "Use the Arrow Keys to move, Q to Quit, S to Save, I to access inventory, or D to access stats: " ) currentLoc = player.getLoc() startTile = board.getBoard()[currentLoc[1] - 1][currentLoc[0] - 1] playerChoice = ord(getch()) if playerChoice in ordList: if playerChoice == 224: playerMove = ord(getch()) board, player = move(board, player, playerMove) newCoord = player.getLoc() currentTile = board.getBoard()[newCoord[1] - 1][newCoord[0] - 1] if isinstance(currentTile, gameObjects.EnemyTile): player, combatResolution = combat.combat( currentTile.getEnemy(), player) if combatResolution == "W": currentTile.removeEnemy() board.setTile(newCoord[0], newCoord[1], gameObjects.MapTile(playerOcc=True)) elif combatResolution == "L": playerDead = True break elif combatResolution == "R": board, player = moveAway(board, player) time.sleep(2) elif isinstance(currentTile, gameObjects.BossTile): encountersNeeded = 5 if player.getEncounters() >= 5: player, combatResolution = bossCombat.combat( currentTile.getBoss(), player) if combatResolution == "W": playerWon = True break elif combatResolution == "L": playerLost = True break else: print( "You are not yet strong enough to face the boss, you must prove your mettle against at least 5 enemies first" ) moveAway(board, player) elif isinstance(currentTile, gameObjects.AnomalyTile): anomaly = currentTile.getAnomaly() player = encounter.main(anomaly, player) board.setTile(newCoord[0], newCoord[1], gameObjects.MapTile(playerOcc=True)) elif playerChoice == I: player, curTurn = items.inventory(player) elif playerChoice == Q: print("Press Q to quit immediately or S to save first") playerChoice = ord(getch()) if playerChoice == Q: break elif playerChoice == S: save(board, player) elif playerChoice == S: save(board, player) #clear screen print("Game Saved") print("Press Any Key to Exit") key = ord(getch("...")) #command to close window elif playerChoice == I: player.useItem() elif playerChoice == D: player.getStats() print("------------") input("Press Enter to Continue") elif playerChoice == T: player.getStats() print("Press Any Key to Continue...") playerKey = getch() else: print("Invalid") #player presses key move -> [UP/DOWN/LEFT/RIGHT ARROWS] OR Q [Quit] OR S [Save] OR I [Inventory] #player moves #MOVE() #player moves to an occupied tile #encounter = True #check if the tile contains the final boss #if the tile does contain the boss check the players number of enemy defeats #if the player has defeated enough enemies ask the player if they want to fight the boss #if yes initiate a battle with the final boss - combat.py #if you lose game over -playerLoses() #elif you win game won -playerWins() #else if player doesnt have enough encounters or dont want to fight, move the player away #move the player one tile based on RNG and position (Up,down,left,right) #loop random moves until a valid move is found. #while not valid move #moveAway() #if the tile doesnt contain the boss, check for an enemy or anomaly #if there is an enemy, fight it #if the player wins, display {encouragment} {celebration} and replace their current tile with a PlayerTile #elif the player loses, end the game {possibly lose a life}? #elif the player runs, move them 1 tile randomly #update the enemyTile with the enemies state after battle #else if there is an anomaly, player encounters the anomaly #set anomaly tile to player occupied #player moves to unoccupied tile #redraw board #use item #asks the player to choose an item from their inventory or cancel #if the player wants to use an item that is single use, warn them it will be wasted #if they still want to use it, use the item #else loop back to top #save #use a save function to save the board. #the board contains all objects and tiles and everything in play, so we should just need to save that one object. #quit #warns the player to save first [Q] to quit, [S] to save #if they choose to save, run the save function #else terminate the program. if playerWon == True: system("cls") print("You have emerged victorious from a dangerous galaxy") time.sleep(2) print( "By defeating the galactic boss you have earned the praises of all who know you, rest well hero" ) time.sleep(2) print("Your Final Stats") print("-------------") print(player.getStats()) time.sleep(10) elif playerLost == True: print("You have fallen to the evils of the galaxy") print("Fare thee well in the next life") time.sleep(10) else: pass except Exception as e: logging.basicConfig(filename='app.log', level=logging.INFO) logging.exception(e)
def combat(enemy, player): system("cls") print() print("An", enemy.name, "appears!") print("---------------------") print("Your Stats:") print("---------------------") player.getStats() time.sleep(1) print("") print("---------------------") print("Enemy Stats:") print("---------------------") enemy.getStats() if enemy.SPD > player.SPD: curTurn = "Enemy" elif player.SPD > enemy.SPD: curTurn = "Player" else: if random.randint(1, 2) == 1: curTurn = "Player" else: curTurn = "Enemy" fled = False while player.HP > 0 and enemy.HP > 0 and not fled: if curTurn == "Player": print("Choose Your Action!") print("---------------------") print() print(">Physical >Energy >Flee >Item") print() print(enemy.getArt()) selection = "" while (selection not in ("Physical", "Energy", "Flee", "Item")): selection = input("-->").title() if selection == "Physical": print("You attack the", enemy.name, "with physical weapons") time.sleep(1) enemy.takePDamage(player.PHY) curTurn = "Enemy" elif selection == "Energy": print("You use energy weapons on the", enemy.name) time.sleep(1) enemy.takeEDamage(player.ENG) curTurn = "Enemy" elif selection == "Item": print("Pick an item to use: ") player, curTurn = items.inventory(player) elif selection == "Flee": if enemy.SPD != 1337: roll = random.randint(1, 100) if player.SPD > enemy.SPD: fleeChance = 90 else: fleeChance = 50 if roll <= fleeChance: print("-----------") print("you Fled") print("-----------") fled = True time.sleep(1) else: print("failed to flee") time.sleep(1) curTurn = "Enemy" else: print("failed to flee") time.sleep(1) elif curTurn == "Enemy": atType = random.randint(1, 100) if enemy.PHY >= enemy.ENG: if atType > 10: print("The", enemy.name, "attacks with physical weapons!") time.sleep(1) player.takePDamage(enemy.PHY) else: print("The", enemy.name, "uses energy weapons!") time.sleep(1) player.takeEDamage(enemy.ENG) elif enemy.PHY < enemy.ENG: if atType > 10: print("The", enemy.name, "uses energy weapons!") time.sleep(1) player.takeEDamage(enemy.ENG) else: print("The", enemy.name, "attacks with physical weapons!") time.sleep(1) player.takePDamage(enemy.PHY) else: print("An Error Occured...") curTurn = "Player" if player.HP <= 0: print("-----------------") print("You Died") print("-----------------") playerRes = "L" elif fled == True: playerRes = "R" pass else: player.encounter() ranDrop = random.randint(0, 5) level = enemy.getLV() pickedItem = itemList[ranDrop][level] items.addItem(pickedItem) time.sleep(1.5) system("cls") print() print() print() oswidth = os.get_terminal_size().columns print("Item Drop Acquired!".center(oswidth)) print("--------------------------".center(oswidth)) string = "You got " + pickedItem.name print(string.center(oswidth)) print("--------------------------".center(oswidth)) time.sleep(3) playerRes = "W" return player, playerRes