def play_game(self, player): print("Watch the ball!") time.sleep(0.5) clear() self.print_animation() print( "Could you follow? Tell me, under which cup is the ball? (left, middle, right)" ) a = str(input("> ")).lower() valid_options = ["left", "middle", "right"] while a not in valid_options: print("Come on... play the game!") a = str(input("> ")).lower() x = random.randint(1, 3) if x == 1: position = "left" elif x == 2: position = "middle" elif x == 3: position = "right" if a == position: print("Not bad, you got it right.") self.result(x) return 1 else: print("Sorry, no luck this time.") self.result(x) return 0
def movement(destination): if (myPlayer.location == "b1" and destination == "c1") or (myPlayer.location == "c1" and destination == "b1"): print( "Do you want do 'swim' over the river or go over the the bridge in the west?" ) answer = input("> ") if answer == "swim": if random.random() < 0.2: factor = random.random() print("Unfortunately you get attacked by a snake.") print("You get " + str(factor * 10) + " damage.") myPlayer.health_cur -= factor * 10 if myPlayer.health_cur < 0: print("You died.") time.sleep(2) game_over() if (myPlayer.location == "b2" and destination == "c2") or (myPlayer.location == "c2" and destination == "b2"): BridgeGuard(myPlayer) myPlayer.location = destination print("You have moved to the " + zonemap[myPlayer.location]["ZONENAME"] + ".") time.sleep(2) clear()
def show_stats(self): """ This function shows the stats of the player. """ clear() print("#" * screen_width) print("") print("Name:" + " " * (20 - len("Name:")) + self.name) print("Class:" + " " * (20 - len("Class:")) + self.play_class) print("Level:" + " " * (20 - len("Level:")) + str(self.level)) print("Gold:" + " " * (20 - len("Gold:")) + str(self.gold)) # Gold ergänzt print("EP:" + " " * (20 - len("EP:")) + str(self.ep)) print("Health:" + " " * (20 - len("Health:")) + str(self.health_cur) + "/" + str(self.health_max)) print("Mana:" + " " * (20 - len("Mana:")) + str(self.mp_cur_max[0]) + "/" + str(self.mp_cur_max[1])) print("Armor:" + " " * (20 - len("Armor:")) + str(self.armor)) print("Weapon:" + " " * (20 - len("Weapon:")) + self.weapon.name + " with " + str(self.weapon.damage) + " damage") print("") print("#" * screen_width) print("") print("Press ENTER to continue.") input() clear()
def intro(self, player): print("Hey!", end=" ") time.sleep(1) print(" " + player.name) time.sleep(1) speech_manipulation( "Come over here for a second, I have an offer for you.", 0.08) time.sleep(1) clear() print( "You look like a trustworthy adventure. I have a problem, you see, and I need help. My farm was raided by some bandits and I have nothing left to eat." ) time.sleep(3) print( "They left a note with a message. I have it in my house. Would you come take a look and help me?" ) ant = str(input("> ")).lower() if ant not in ["yes", "y"]: print("Oh. I thought you were the one to save me...") time.sleep(2) else: speech_manipulation("Thank you!!", 0.08) time.sleep(1) print(" ") speech_manipulation( "** You follow the man through a narrow street. After you turn a corner everything is black!", 0.065) time.sleep(1) clear() time.sleep(2)
def fishing(self): """ The player can go fishing in the water if he has a fishingrot. Adds fish to the inventory. :return: """ if self.location in ["a4", "c1", "c2" ] and "fishingrot" in self.inventory: p = random.random() if p > 0.95: print("You get an old, stinky boot. *urgh*") if "Old, stinky boot" not in self.inventory: self.inventory["Old, stinky boot"] = 1 else: self.inventory["Old, stinky boot"] += 1 elif p > 0.5: print("You got a nice, fresh fish") if "fish" not in self.inventory: self.inventory["fish"] = 1 else: self.inventory["fish"] += 1 else: print( "You got nothing for now. But you can fish all day long.") else: print( "Well you can try to fish here. But you will not get any more than some dirt." ) time.sleep(2) clear()
def write_notebook(self): """ This function gives the possibility to write into the notebook. """ clear() print("#" * screen_width) print("#" + " " * int((screen_width - len("NOTEBOOK")) / 2 - 1) + "NOTEBOOK" + " " * int((screen_width - len("NOTEBOOK")) / 2 - 1) + "#") print("#" * screen_width) print( "\nYou can escape the notebook with writing 'END' in the last line." ) print("\nOlder Entries:\n") with open("../notebook.txt", "r") as notebook: for line in notebook.readlines(): print("> " + line, end="") print("\nAppend the following lines:\n") with open("../notebook.txt", "a") as notebook: while True: inp = input("> ") if inp.strip() == "END": break else: notebook.write(inp + "\n")
def __init__(self, player): self.symbol = " " * int( (screen_width - len("@xxxx[{::::::::::::::::::::::::::::::>")) / 2 ) + " [" + " " * int( (len("::::::::::::::::::::::::::::::") - len("Mr. & Mrs. Smith")) / 2) + "Mr. & Mrs. Smith\n" + " " * int( (screen_width - len("@xxxx[{::::::::::::::::::::::::::::::>")) / 2) + "@xxxx[{::::::::::::::::::::::::::::::>\n" + " " * int( (screen_width - len("@xxxx[{::::::::::::::::::::::::::::::>")) / 2) + " [" self.greeting = [ "Welcome, traveller. How may I help you?", "Hey! You. Get over here. How about a nice new sword for you?", "Oi! You have some coin to spend?" ] self.inventory = [] self.set_inventory(player) # Auslage wird erstellt self.gold = random.randrange(150, 301) # Gold für Ankäufe clear() print("#" * screen_width) print(self.symbol, sep="\n") print("#" * screen_width + "\n") print(random.choice(self.greeting)) self.decision(player) # Interaktion mit blacksmith wird gestartet
def box_print(self, message, x): print("#" * 70) print(" ") print(" ") print(message) print(" ") print(" ") print("#" * 70) time.sleep(x) clear()
def game_over(): clear() speech_manipulation("Ouh there you are again.\n", 0.05) speech_manipulation( "Don't get me wrong. This is no surprise for me. Maybe you have more luck in your next reincarnation.\n", 0.05) speech_manipulation("Have a good day. :)", 0.07) myPlayer.game_over = True time.sleep(2) sys.exit()
def stay(direct): directions = { "up": "north", "down": "south", "left": "west", "right": "east" } print("You cannot move further " + directions[direct] + ".") time.sleep(3) clear()
def title_screen(): clear() print("#" * screen_width) print("#" + (" " * int((screen_width - len("Welcome to the Text RPG")) / 2)) + "Welcome to the Text RPG" + ( " " * int((screen_width - 2 - len("Welcome to the Text RPG")) / 2)) + "#") print("#" + "=" * (screen_width - 2) + "#") print("#" + (" " * int((screen_width - 6) / 2)) + "-play-" + (" " * int((screen_width - 9) / 2)) + "#") print("#" + (" " * int((screen_width - 6) / 2)) + "-help-" + (" " * int((screen_width - 9) / 2)) + "#") print("#" + (" " * int((screen_width - 6) / 2)) + "-quit-" + (" " * int((screen_width - 9) / 2)) + "#") print("#" * screen_width + "\n") title_screen_selections()
def __init__(self, player): self.greeting = [ "Welcome, traveller. How may I help you?", "Hey! You. Get over here. How about a nice new sword for you?", "Oi! You have some coin to spend?" ] self.inventory = [] self.set_inventory(player) # Auslage wird erstellt self.gold = random.randrange(150, 301) # Gold für Ankäufe clear() print_blacksmith() print(random.choice(self.greeting)) self.decision(player) # Interaktion mit blacksmith wird gestartet
def fight_setup(player, poss): clear() print("#" * screen_width) print(" " * int((screen_width - len("FIGHT")) / 2) + "FIGHT") print("#" * screen_width) x = random.random() if x < poss[0]: enemy = Bandit() elif poss[0] < x < poss[0] + poss[1]: enemy = Orc() else: enemy = Giant() # else, solange nur 3 mögliche Gegner fight(player, enemy, zonemap)
def intro(): clear() question3 = "Welcome, " + myPlayer.name + " the " + myPlayer.play_class + ".\n" speech_manipulation(question3, 0.05) speech_manipulation("Welcome to this fantasy world I created for you. ;)\n", 0.05) speech_manipulation("I hope you will have some fun\n ... \n ... \n ...\n", 0.15) speech_manipulation( "Well, you are not the first adventurer here. There have been many before you. And to be honest, there will " "be many after you ... when you have ... ", 0.05) speech_manipulation("passed away ... \n", 0.25) speech_manipulation("Now have some fun exploring the world. We will see each other when it's time to.\n", 0.05) time.sleep(2)
def show_notebook(self): """ Prints out the notebook of the player. """ clear() print("#" * screen_width) print("#" + " " * int((screen_width - len("NOTEBOOK")) / 2 - 1) + "NOTEBOOK" + " " * int((screen_width - len("NOTEBOOK")) / 2 - 1) + "#") print("#" * screen_width) with open("../notebook.txt", "r") as notebook: for line in notebook.readlines(): print("> " + line, end="")
def setup(self, player): print("Hello there. Do you want to make some money?") time.sleep(0.5) speech_manipulation("How about a round of rock, paper, scissors?\n", 0.05) a = str(input("> ")).lower() while a not in ["yes", "no"]: print("What did you say?") a = str(input("> ")).lower() if a == "yes": clear() speech_manipulation("Alright! Place your bet.\n", 0.05) time.sleep(0.3) speech_manipulation( "How much do you want to play for? If you win, I'll double it.\n", 0.05) amount = input("> ") while not all([c in "0123456789" for c in amount]): speech_manipulation( "You should give me an amount of gold you want to bet?\n", 0.05) amount = input("> ") amount = int(amount) if amount > 0: if amount > player.gold: print("Sorry mate, you don't have the bank for that.") else: speech_manipulation("Alright.", 0.05) win = self.play_rps() if win == 1: speech_manipulation("You won! Not bad.\n", 0.05) time.sleep(0.5) print("Here is your reward!") speech_manipulation( "You earn " + str(amount) + " Gold.", 0.05) player.gold += amount time.sleep(2) elif win == 2: speech_manipulation("Oh. A tie.\n", 0.05) print("Well, no luck for both of us.") time.sleep(2) else: speech_manipulation( "You lose... Better luck next time!\n", 0.05) time.sleep(0.5) print("Pay your bet!") player.gold -= amount time.sleep(2) else: print("Try again...")
def win_fight(player, enemy, zonemap): print(" ") print("**** You won!!! ****") print(" ") zonemap[player.location]["ENCOUNTERS"] -= 1 # Kampf ist vorbei -------------------------------------------------- if random.random() < enemy.loot_chance: # Chance ob Loot-Drop oder nicht (abhängig von Gegner) loot(enemy, player) # Spieler erhält Trank(30%) oder Gegenstand(70%) else: print("Looks like you found nothing interesting...") # Garantierte Belohnungen: Gold und Erfahrung player.get_ep(enemy.ep_drop) player.get_gold(random.randrange(10, 20) * enemy.loot_level) time.sleep(2) # Notwendig? clear()
def end_screen(): speech_manipulation( "Congratulations, you have solved the complete game. I never thought you would be able to do this.", 0.05) print("") speech_manipulation( "I will get in touch with you soon. Wait for a sign from me. I think I have a good job for some strong " "adventurer like you.", 0.04) time.sleep(5) clear() # print("Made by laeberkaes") # print("Hit me "UP" at: https://github.com/laeberkaes/ or @laeberkaes:uraltemorla.xyz") # # time.sleep(5) sys.exit()
def player_examine(): if zonemap[myPlayer.location]["ENCOUNTERS"] > 0: fight_setup(myPlayer, zonemap[myPlayer.location]["POSSIBILITIES"]) if zonemap[myPlayer.location]["SOLVED"] == True: print("You have already been here.") print(zonemap[myPlayer.location]["EXAMINATION"]) time.sleep(3) clear() else: print(zonemap[myPlayer.location]["EXAMINATION"]) zonemap[myPlayer.location]["SOLVED"] = True if all(solved_places.values()): myPlayer.game_over = True time.sleep(3) clear()
def help_menu(): clear() print("#" * screen_width) print(("=" * int((screen_width - len("HELP MENU")) / 2)) + "HELP MENU" + ( "=" * int((screen_width - len("HELP MENU")) / 2))) print("#" * screen_width) print("") print(" -- You can always decide to 'examine' a location or 'move' to another.") print(" -- You can always see your inventory with 'show inventory' and show your stats with 'show stats'") print("-- If you examine a location you may trigger a random encounter and you can 'fish', 'hunt'. 'rest', " "'learn' or 'get corn'") print(" -- If you move, you can decide to move 'up', 'down', 'left' or 'right'") print("") print("Press ENTER to continue.") input() title_screen() title_screen_selections()
def get_corn(self): """ The player can get corn from the corn field. Adds corn to the inventory. :return: """ if self.location == "d2": p = random.random() if p > 0.25: print("You get some nice corn.") if "bag of corn" not in self.inventory["misc"]: self.inventory["misc"]["bag of corn"] = 1 else: self.inventory["misc"]["bag of corn"] += 1 else: print("Baaah. You better not take this corn with you.") else: print("Well you cannot get corn out of this place.") time.sleep(2) clear()
def print_inventory(self, interactive=False): """ This function prints out the inventory of the player with weapons, armor, potions and miscellaneous. """ clear() print("#" * screen_width) print("=" * int((screen_width - len("WEAPONS")) / 2) + "WEAPONS" + "=" * int((screen_width - len("WEAPONS")) / 2)) for weapon in self.inventory["weapons"]: if weapon.equipped == True: print("EQUIPPED: " + str(weapon)[13:]) else: print(str(weapon)[13:]) print("") print("=" * int((screen_width - len("ARMOR")) / 2) + "ARMOR" + "=" * int((screen_width - len("ARMOR")) / 2)) for armor in self.inventory["armor"]: if armor.equipped == True: print("EQUIPPED: A" + str(armor)[6:]) else: print("A" + str(armor)[6:]) print("") print("=" * int((screen_width - len("POTIONS")) / 2) + "POTIONS" + "=" * int((screen_width - len("POTIONS")) / 2)) if self.potions == 1: print("You have " + str(self.potions) + " potion.") if self.potions > 1: print("You have " + str(self.potions) + " potions.") print("") print("=" * int((screen_width - len("MISC")) / 2) + "MISC" + "=" * int((screen_width - len("MISC")) / 2)) for misc in self.inventory["misc"]: print(misc + ": " + str(self.inventory["misc"][misc])) print("") if not interactive: print("Press ENTER to continue.") input() clear()
def use_potion(self): """ Adds health and mana, if the player has potions left. :return: """ if self.potions > 0: # Adding health and mana self.health_cur += 25 self.mp_cur_max[0] += 25 # Check if the result is more than the max value if self.health_cur > self.health_max: self.health_cur = self.health_max if self.mp_cur_max[0] > self.mp_cur_max[1]: self.mp_cur_max[0] = self.mp_cur_max[1] self.potions -= 1 print( "Ahhhh this feels good. You feel new power filling up your body. (HP +25)" ) else: print("You don't have any potions left.") time.sleep(2) clear()
def setup_game(): clear() question1 = "Hello what's your name?\n" speech_manipulation(question1, 0.05) print("") myPlayer.name = input("> ").lower() clear() classes = ["warrior", "mage", "rogue"] question2 = "What Class do you want to play? (Warrior, Mage, Rogue)\n" speech_manipulation(question2, 0.01) print("") player_class = input("> ").lower() print("") if player_class.lower() in classes: myPlayer.play_class = player_class print("You are now a " + player_class) time.sleep(1.5) else: while player_class.lower() not in classes: print("No valid class.\n") player_class = input("> ").lower() if player_class.lower() in classes: myPlayer.play_class = player_class print("You are now " + player_class) time.sleep(1.5) if myPlayer.play_class == "warrior": myPlayer.health_max = 120 myPlayer.health_cur = 120 myPlayer.mp_cur_max.append(20) myPlayer.mp_cur_max.append(20) elif myPlayer.play_class == "mage": myPlayer.health_max = 80 myPlayer.health_cur = 80 myPlayer.mp_cur_max.append(80) myPlayer.mp_cur_max.append(80) elif myPlayer.play_class == "rogue": myPlayer.health_max = 100 myPlayer.health_cur = 100 myPlayer.mp_cur_max.append(40) myPlayer.mp_cur_max.append(40) # intro() clear() print("#" * screen_width + "\n") print("#" + (" " * int((screen_width - 2 - len("Let's start now")) / 2)) + "Let's start now" + ( " " * int((screen_width - 2 - len("Let's start now")) / 2)) + "#\n") print("#" * screen_width + "\n") game_loop() end_screen()
def setup_game(): clear() question1 = "Hello what's your name?\n" speech_manipulation(question1, 0.05) print("") myPlayer.name = input("> ").lower() clear() classes = ["warrior", "mage", "rogue", "debug"] question2 = "What Class do you want to play? ('Warrior', 'Mage', 'Rogue')\n" speech_manipulation(question2, 0.01) print("") player_class = input("> ").lower() print("") if player_class.lower() in classes: myPlayer.play_class = player_class print("You are now a:") else: while player_class.lower() not in classes: print("No valid class.\n") player_class = input("> ").lower() if player_class.lower() in classes: myPlayer.play_class = player_class print("You are now " + player_class) if myPlayer.play_class == "warrior": print_warrior() time.sleep(2) myPlayer.health_max = 120 myPlayer.health_cur = 120 myPlayer.mp_cur_max.append(20) myPlayer.mp_cur_max.append(20) myPlayer.karma = 1.0 myPlayer.strength = 0.3 myPlayer.dexterity = -0.1 myPlayer.constitution = 0.2 myPlayer.intelligence = 0.0 myPlayer.wisdom = 0.1 myPlayer.charisma = 0.2 elif myPlayer.play_class == "mage": print_mage() time.sleep(2) myPlayer.health_max = 80 myPlayer.health_cur = 80 myPlayer.mp_cur_max.append(80) myPlayer.mp_cur_max.append(80) myPlayer.karma = 1.0 myPlayer.strength = 0.0 myPlayer.dexterity = 0.2 myPlayer.constitution = 0.2 myPlayer.intelligence = 0.3 myPlayer.wisdom = 0.1 myPlayer.charisma = -0.1 elif myPlayer.play_class == "rogue": print_rogue() time.sleep(2) myPlayer.health_max = 100 myPlayer.health_cur = 100 myPlayer.mp_cur_max.append(40) myPlayer.mp_cur_max.append(40) myPlayer.karma = 1.0 myPlayer.strength = -0.1 myPlayer.dexterity = 0.3 myPlayer.constitution = 0.1 myPlayer.intelligence = 0.1 myPlayer.wisdom = 0.0 myPlayer.charisma = 0.3 elif myPlayer.play_class == "debug": myPlayer.health_max = 1000 myPlayer.health_cur = 1000 myPlayer.mp_cur_max.append(400) myPlayer.mp_cur_max.append(400) myPlayer.level = 10 myPlayer.gold = 10000 myPlayer.karma = 1.0 myPlayer.strength = -0.1 myPlayer.dexterity = 0.3 myPlayer.constitution = 0.1 myPlayer.intelligence = 0.1 myPlayer.wisdom = 0.0 myPlayer.charisma = 0.3 for i in range(3): myPlayer.spells.append(Spell(myPlayer)) myPlayer.weapon = game_object.Weapon(10) print("Where to start? (a1, a2, etc.") myPlayer.location = input("> ") # intro() clear() print("#" * screen_width + "\n") print("#" + (" " * int((screen_width - 2 - len("Let's start now")) / 2)) + "Let's start now" + ( " " * int((screen_width - 2 - len("Let's start now")) / 2)) + "#\n") print("#" * screen_width + "\n") game_loop() end_screen()
def fight_options(): print("Choose: attack, magic, heal, flee, show stats, quit\n") ant = input("> ") clear() return ant
def repair(self, player): clear() player.print_inventory(interactive=True) print("What do you want to repair? ('weapon', 'armor'): ") sell = input("> ") while sell.lower() not in ["weapon", "armor"]: print("Please write 'weapon' or 'armor'") sell = input("> ") clear() if sell.lower() == "weapon": print("#" * screen_width, end="\n\n") for num, weapon in enumerate(player.inventory["weapons"]): if weapon.durability[0] < weapon.durability[1]: print(" " * 5 + str(num + 1) + " " + weapon.name + " with " + str(weapon.durability[0] / weapon.durability[1] * 100) + "% of durability.") print(" " * 9 + "~~ Cost: " + str(int(weapon.value * .25)) + " Gold ~~", end="\n\n") else: print( " " * 5 + str(num + 1) + " --> >>FULL DURABILITY<< " + weapon.name + " with " + str(weapon.durability[0] / weapon.durability[1] * 100) + "% of durability.", end="\n\n") print("#" * screen_width, end="\n\n") print("Which one do you want to repair? (number):") select = input("> ") if player.inventory["weapons"][int(select) - 1].durability[0] < \ player.inventory["weapons"][int(select) - 1].durability[1]: if player.gold - int(player.inventory["weapons"][int( int(select) - 1)].value * .25) >= 0: print("This costs you " + str( int(player.inventory["weapons"][int(int(select) - 1)].value * .25)) + " Gold.") player.gold -= int( player.inventory["weapons"][int(int(select) - 1)].value * .25) player.inventory["weapons"][int(select) - 1].durability[0] = \ player.inventory["weapons"][int(select) - 1].durability[1] time.sleep(2) else: print( "Oh this seems to be too expensive for a poor guy like you." ) time.sleep(2) self.decision(player) else: print("This weapon is in shape. No need to repair..") self.decision(player) elif sell.lower() == "armor": print("#" * screen_width, end="\n\n") for num, armor in enumerate(player.inventory["armor"]): if armor.durability[0] < armor.durability[1]: print(" " * 5 + str(num + 1) + " --> " + armor.name + " for your " + armor.slot + " with " + str(armor.durability[0] / armor.durability[1] * 100) + "% of durability.") print(" " * 9 + "~~ Cost: " + str(int(armor.value * .25)) + " Gold ~~", end="\n\n") else: print( " " * 5 + str(num + 1) + " --> >> FULL DURABILITY<< " + armor.name + " for your " + armor.slot + " with " + str(armor.durability[0] / armor.durability[1] * 100) + "% of durability.", end="\n\n") print("#" * screen_width, end="\n\n") print("Which one do you want to repair? (number):") select = input("> ") if player.inventory["armor"][int(select) - 1].durability[0] < \ player.inventory["armor"][int(select) - 1].durability[1]: if player.gold - int(player.inventory["weapons"][int( int(select) - 1)].value * .25) >= 0: print("This costs you " + str( int(player.inventory["armor"][int(int(select) - 1)].value * .25)) + " Gold.") player.gold -= int( player.inventory["armor"][int(int(select) - 1)].value * .25) player.inventory["armor"][int(select) - 1].durability[0] = \ player.inventory["armor"][int(select) - 1].durability[1] time.sleep(2) else: print( "Oh this seems to be too expensive for a poor guy like you." ) time.sleep(2) self.decision(player) else: print("This armor is in shape. No need to repair..") self.decision(player)
def movement(destination): myPlayer.location = destination print("You have moved to the " + zonemap[myPlayer.location]["ZONENAME"] + ".") time.sleep(3) clear()
def buy_inventory(self, player): clear() print("#" * screen_width) for i in range(3): o = self.inventory[i] if o.obj_type == "weapon": m = o.obj_type + ": " + o.name + ", damage: " + str( o.damage) + " " * ( screen_width - (11 + len(o.obj_type + ": " + o.name + ", damage: " + str(o.damage))) ) + "#\n" + "#" + " " * 10 + ">> Price: " + str( o.value) + " <<" + " " * (screen_width - (12 + len( ">> Price: " + str(o.value) + " <<"))) + "#" else: m = o.obj_type + ": " + o.name + " for your " + o.slot + ", protection: " + str( o.protection ) + " " * ( screen_width - (11 + len(o.obj_type + ": " + o.name + " for your " + o.slot + ", protection: " + str(o.protection))) ) + "#" + "\n" + "#" + " " * 10 + ">> Price: " + str( o.value) + " <<" + " " * ( screen_width - (12 + len(">> Price: " + str(o.value) + " <<"))) + "#" print("#" + " " * 6 + str(i + 1) + ". " + m) print("#" * screen_width) # TODO Hannes, mach das schön! :D print(" ") print("Which one do you want? ('1', '2', '3', 'nothing')") valid_input = ["1", "2", "3", "nothing"] a_capital = input("> ") a = a_capital.lower() # Workaround fürs debuggen auswahl = -1 # Hilfsmittel :D while a not in valid_input: print("Please give me a normal answer, stranger.") self.buy_inventory(player) if a == "1": auswahl = 0 elif a == "2": auswahl = 1 elif a == "3": auswahl = 2 elif a == "nothing": # oder direkt else, für die Lesbarkeit aber noch so print("Well, why do you waste my time then?") if auswahl >= 0: if self.inventory[auswahl] != " ": if player.gold > self.inventory[auswahl].value: print("So you want the " + self.inventory[auswahl].name + ". Are you sure? ('y'/'n')") ax = input() a2 = ax.lower() # debug workaround if a2 == "y": # der eigentliche Kauf if self.inventory[auswahl].obj_type == "weapon": player.get_weapon(self.inventory[auswahl], p=False) player.equip_weapon(self.inventory[auswahl]) else: player.get_armor(self.inventory[auswahl], p=False) player.equip_armor(self.inventory[auswahl]) player.gold -= self.inventory[ auswahl].value # Bezahlvorgang self.inventory[ auswahl] = " " # Inventarslot wird geleert. Man könnte auch direkt nen neuen Gegenstand rein, aber weiß nich ob das so cool ist :D else: # Quasi if a2 == "n" oder was anderes (print("Your loss.")) self.buy_inventory(player) else: print("You don't have the coin for that!") self.buy_inventory(player) else: print("I got nothing there for you.") self.buy_inventory(player) time.sleep(2) clear()
def play_rps(self): rock_left = """ _______ ---' ____) (_____) (_____) (____) ---.__(___) """ rock_right = """ _______ (____ '--- (_____) (_____) (____) (___)__.--- """ paper_left = """ _______ ---' ____)____ ______) _______) _______) ---.__________)""" paper_right = """ _______ ____(____ '--- (______ (_______ (_______ (__________.---""" scissors_left = """ _______ ---' ____)____ ______) __________) (____) ---.__(___)""" scissors_right = """ _______ ____(____ '--- (______ (__________ (____) (___)__.---""" clear() print("Choose your symbol: (rock, paper, scissors)") choice = str(input("> ")).lower() while choice not in ["rock", "paper", "scissors"]: print("Choose a valid answer.") choice = str(input("> ")).lower() print("ROCK") time.sleep(0.8) print("PAPER") time.sleep(0.8) print("SCISSORS") time.sleep(0.8) clear() own_choice = random.choice(["rock", "paper", "scissors"]) print("Your choice: Opponent's choice:") print(" " + choice + " " + own_choice) if choice == "rock": print(rock_left) elif choice == "paper": print(paper_left) else: print(scissors_left) if own_choice == "rock": print(rock_right) elif own_choice == "paper": print(paper_right) else: print(scissors_right) winning_combinations = [("rock", "scissors"), ("scissors", "paper"), ("paper", "rock")] losing_combinations = [("rock", "paper"), ("paper", "scissors"), ("scissors", "rock")] tie_combinations = [("scissors", "scissors"), ("rock", "rock"), ("paper", "paper")] for combination in winning_combinations: if combination[0] == choice and combination[1] == own_choice: return 1 for combination in losing_combinations: if combination[0] == choice and combination[1] == own_choice: return 0 for combination in tie_combinations: if combination[0] == choice and combination[1] == own_choice: return 2