def fighting(): fight = True while int(changestats.get("hitpoints")) >= 0 and fight == True: changestats.modify("hitpoints", basehp) #reset hp if battle() == "home": fight = False home(inv, bank) money = int(changestats.get("money")) #check if you can spent money if money >= 500: #level up! print("would you like to advance a level for 500g? Press enter!") changestats.modify("money", str(money - 500)) changestats.modify("basehp", str(int(changestats.get("basehp")) + 1)) print("Congratulations! Your HP is now", changestats.get("basehp"), "!!!") #reset hp changestats.modify("hitpoints", basehp)
def levelUp(xpGain): xpGain = int(xpGain) changestats.get("level") level = int(changestats.get("level")) xp = int(changestats.get("experience")) print("XP gained:", xpGain) time.sleep(2) print('\n' * 40) sound.play("exp.wav") time.sleep(.25) for i in range(xpGain): xp += 1.000 / (1 + level * .1) xpGain -= 1 randomEvents.progress(xp, xpGain) time.sleep(.004 - (level * .00005) + (i / 2000000)) if xp >= 100: sound.stop() print('\n' * 30) print("------------------------------------------") print("\n Level up! Your level is now", level) print("------------------------------------------") randomEvents.progress(xp, xpGain) xp = 0 level += 1 playsound("ding.wav") sound.play("exp.wav") print('\n' * 40) sound.stop() time.sleep(2) xp = int(xp) changestats.modify("experience", str(xp)) changestats.modify("level", str(level)) travel(False)
def inventory(func, inv, bank): bank = changestats.get("bank").strip('][').split(', ') print("This is your inventory!") inv = simplify() cont = 0 print("Bank:", bank) while cont == 0: say = input(''' Type r to return! ''') #Return to previous page. if say == "r": cont = 1 return func(inv, bank, True)
def fishing(min, max, neg, t, inv, map='ocean'): cardNum = random.randint(min, max) xpReward = (cardNum - neg) * t spacer = "" if map == 'ocean': ocean() spacer = " " if map == 'ocean2': ocean2() spacer = " " print(spacer, " |") for i in range(cardNum): #time is faster at higher levels. time.sleep(t * (1 - (int(changestats.get("level")) / 150))) print(spacer, " |") print( spacer, " | -------------------------------------------------------" ) print(spacer, " | You caught something!") print( spacer, " | -------------------------------------------------------" ) playsound('money.wav', block=False) #use proper a/an articles if cardNum - neg == 8: print(spacer, " | It's an", cardNum - neg, "card!") elif cardNum - neg == 11: print(spacer, " | It's a Jack!") elif cardNum - neg == 12: print(spacer, " | It's a Queen!!") elif cardNum - neg == 13: print(spacer, " | It's a King!!!") else: print(spacer, " | It's a", cardNum - neg, "card!") print("") # Save the cards to the .ini file. inv.append(cardNum - neg) inv = [int(s) for s in inv] inv.sort() changestats.save(inv, "inv") return xpReward
def map(): print('\n' * 12) bank = changestats.get("bank").strip('][').split(', ') inv = simplify() randomEvents.map() print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Where would you like to go? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n" ) cont = 0 while cont == 0: say = input(''' Type 'city' to go downtown. Type 'd' to go to the digsite. Type 'north' to go to the North Pole. Type 'home' to go back home. Type 'close' to close the map ''') if say == "home": sound.stop() cont = 1 home(inv, bank) if say == "north": sound.stop() cont = 1 northern(inv, bank) if say == "d": sound.stop() cont = 1 digsite(inv, bank) if say == "city": sound.stop() cont = 1 city(inv, bank) if say == "close": travel(True)
def digGame(duration): meters = int(changestats.get("meters")) chance = 2 level = int(changestats.get("level")) print("Welcome to the digsite! You have currently dug", meters, "meters.") def dig(meters, chance): prize = False if chance >= random.randrange(100): #time.sleep(1) chance = .1 + (meters / 300) prize = True playsound("money.wav", block=False) chance *= (1.1 + (level / 1000)) if chance > 100: chance = 100 return chance, prize amount = 0 t_end = time.time() + duration #60 seconds xpGain = duration / 4 for i in range(100): while time.time() < t_end: digSound = random.choice( ['dig.wav', 'dig2.wav', 'dig3.wav', 'dig4.wav']) if meters > 350: digSound = random.choice([ 'pickaxe.wav', 'pickaxe2.wav', 'pickaxe3.wav', 'pickaxe4.wav' ]) playsound(digSound, block=False) chance = int(math.ceil(chance)) underground(meters) print("Time left: less than", math.ceil(int(t_end - time.time()) / 60), "minute(s).") print("You keep digging... You have found", amount, "card pack(s) on this trip.") print("you have a", chance, "% chance of finding treasure.") time.sleep(2.8 * meters / 10 / level) chance, prize = dig(meters, chance) if prize == True: amount += 1 meters += 1 xpGain += int(5 + (meters / 100)) print("You have found:", amount, "Card pack(s)!") print("You receive", int(xpGain), "experience!") input("Press ENTER to continue.") #save stats packs = int(changestats.get("packs")) changestats.save(packs + amount, "packs") changestats.save(meters, "meters") return xpGain
def openPack(card1, card2, card3, card4, card5): tempSound = [] tempSound = ['ducky.wav'] * 5 card1 = str(card1) card2 = str(card2) card3 = str(card3) card4 = str(card4) card5 = str(card5) if card1 == '11': card1 = 'J' tempSound[0] = 'goodCard.wav' elif card1 == '12': card1 = 'Q' tempSound[0] = 'goodCard.wav' elif card1 == '13': card1 = 'K' tempSound[0] = 'goodCard.wav' if card2 == '11': card2 = 'J' tempSound[1] = 'goodCard.wav' elif card2 == '12': card2 = 'Q' tempSound[1] = 'goodCard.wav' elif card2 == '13': card2 = 'K' tempSound[1] = 'goodCard.wav' if card3 == '11': card3 = 'J' tempSound[2] = 'goodCard.wav' elif card3 == '12': card3 = 'Q' tempSound[2] = 'goodCard.wav' elif card3 == '13': card3 = 'K' tempSound[2] = 'goodCard.wav' if card4 == '11': card4 = 'J' tempSound[3] = 'goodCard.wav' elif card4 == '12': card4 = 'Q' tempSound[3] = 'goodCard.wav' elif card4 == '13': card4 = 'K' tempSound[3] = 'goodCard.wav' if card5 == '11': card5 = 'J' tempSound[4] = 'goodCard.wav' elif card5 == '12': card5 = 'Q' tempSound[4] = 'goodCard.wav' elif card5 == '13': card5 = 'K' tempSound[4] = 'goodCard.wav' if card1 != '10': card1 = '░' + card1 if card2 != '10': card2 = '░' + card2 if card3 != '10': card3 = '░' + card3 if card4 != '10': card4 = '░' + card4 if card5 != '10': card5 = '░' + card5 blank1 = '░░' blank2 = '░░' blank3 = '░░' blank4 = '░░' blank5 = '░░' for i in range(6): if i == 1: blank1 = card1 if i == 2: blank2 = card2 if i == 3: blank3 = card3 if i == 4: blank4 = card4 if i == 5: blank5 = card5 print('\n \n \n \n \n \n \n ' * 2) lines = [ ' ┌─────────┐ ┌─────────┐' ] lines += [ ' │░{}░░░░░░│ │░{}░░░░░░│'. format(blank1, blank2) ] lines += [ ' │░░░░░░░░░│ │░░░░░░░░░│' ] * 5 lines += [ ' │░░░░░░{}░│ │░░░░░░{}░│'. format(blank1, blank2) ] lines += [ ' └─────────┘ └─────────┘' ] lines += [' ┌─────────┐'] lines += [ ' │░{}░░░░░░│'.format( blank3) ] lines += [' │░░░░░░░░░│'] * 5 lines += [ ' │░░░░░░{}░│'.format( blank3) ] lines += [' └─────────┘'] lines += [ ' ┌─────────┐ ┌─────────┐' ] lines += [ ' │░{}░░░░░░│ │░{}░░░░░░│'. format(blank4, blank5) ] lines += [ ' │░░░░░░░░░│ │░░░░░░░░░│' ] * 5 lines += [ ' │░░░░░░{}░│ │░░░░░░{}░│'. format(blank4, blank5) ] lines += [ ' └─────────┘ └─────────┘' ] # make each line into a single list for index, x in enumerate(lines): lines[index] = ''.join(x) # convert the list into a single string lines = '\n'.join(lines) #print("(1) (2) (3)") print(lines, '\n') print(" You have ", changestats.get("packs"), "more pack(s)!") myVar = input( " Press any key to open the packs!") if i < 5: mySound = tempSound[i] playsound(mySound, block=False)
def gamble(): inv = changestats.get("inv").strip('][').split(', ') inv = [int(s) for s in inv] inv.sort() print("Here are your cards:") counter = 1 myString = "" sevenCards = "" for i in range(len(inv)): if i + 1 < len(inv) and inv[i] == inv[i + 1]: counter += 1 elif inv[i] == 7: myString += ' [' if inv[i] == 11: myString += "Jack" #If there are more than 1 of a face card, add an 's' if counter > 1: myString += "s" elif inv[i] == 12: myString += "Queen" if counter > 1: myString += "s" elif inv[i] == 13: myString += "King" if counter > 1: myString += "s" else: myString += str(inv[i]) myString += "]" myString += "x" sevenCards += str(counter) myString += str(counter) counter = 1 print( "-------------------------------------------------------------------------------------------------------------" ) print(myString) print( "-------------------------------------------------------------------------------------------------------------" ) print("You have", changestats.get("money"), "gold!") print( "-------------------------------------------------------------------------------------------------------------" ) print( "Want to gamble? bet a 7 card and 1 coin. If you win, you get a Queen card." ) print("If you lose, I get your 7 card!") sevenCards = int(sevenCards) xpGain = 0 cont = 0 choice = 'g' while cont == 0: choice = input("Press 'g' to gamble or 'r' to return. \n") if choice == 'r': cont = 1 elif choice == 'g' and int(changestats.get("money")) > 0: print("You bet one 7 card.\n") #pay one gold money = int(changestats.get("money")) changestats.modify("money", str(money - 1)) time.sleep(1) print('\n' * 30) if random.randrange(2) == 1: playsound('money.wav', block=False) print("YOU WIN! You get a 10 card. You have", changestats.get("money"), "gold and", str(sevenCards) + 'x', "'7 cards' left.\n") xpGain += 20 inv.append(10) changestats.save(inv, "inv") else: sevenCards -= 1 playsound('ducky.wav', block=False) print("You lose! You have", changestats.get("money"), "gold and", str(sevenCards) + 'x', "'7 cards' left.\n") xpGain += 10 inv.remove(7) changestats.save(inv, "inv") elif int(changestats.get("money")) < 1: print("\nYou don't have any money!\n") else: cont = 0 return xpGain
def cards(inv, bank, difficulty, speed): #Load the inventory bank = changestats.get("bank").strip('][').split(', ') print('\n' * 6) print("________________________________") print("Let's DUEL!!!") print("________________________________") monList = monsters.getMonList() randMonster = random.randint(0, len(monList) - 1) print("You will fight:", monList[randMonster].get('name')) monsterCard = int(monList[randMonster].get('hp')) + difficulty print("He has", monsterCard, "HP!") card1 = int(random.choice(inv)) card2 = int(random.choice(inv)) card3 = int(random.choice(inv)) print("Drawing three cards...") print('\n') time.sleep(speed) #print your hand randomEvents.showHand(card1, card2, card3) choice = input("Choose a card: \n") yourCard = 0 if choice == '1': yourCard = card1 elif choice == '2': yourCard = card2 else: yourCard = card3 #print the name of the card print("-------------------------------------------------------") determineFace(yourCard) print("-------------------------------------------------------") time.sleep(1.5 * speed) if yourCard > monsterCard: print("you win! You get their card!") inv.append(monsterCard) elif yourCard < monsterCard: print("you lost! You lose your card...") inv.remove(yourCard) #second chance! print("Adding another card! It's a...") newCard = int(random.choice(inv)) time.sleep(speed) #print the name of the card print("-------------------------------------------------------") determineFace(newCard) print("-------------------------------------------------------") time.sleep(speed) cardTotal = yourCard + newCard print("Your total is...", cardTotal, "!") time.sleep(.5 * speed) if cardTotal > monsterCard: print("you win! You get their card!") if monsterCard > 13: #earn excess gold money = int(changestats.get("money")) bonus = money + monsterCard - 13 changestats.modify("money", str(money + monsterCard - 13)) print("You also earned a bonus", monsterCard - 13, "gold!") monsterCard = 13 inv.append(monsterCard) else: print("Not enough! You lost your other card... =(") inv.remove(newCard) else: print("It's a draw!") # Save the cards to the .ini file. changestats.save(inv, "inv") changestats.save(bank, "bank")
def home(inv, bank, music=False): print('\n' * 12) #Play music if it is not already playing. This prevents a restart. if music == False: sound.play(path + "home.wav") changestats.modify("location", 'home') bank = changestats.get("bank").strip('][').split(', ') inv = simplify() randomEvents.house() print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Welcome home! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n" ) #print("Bank:",bank) print("Would you like to enter the town?") cont = 0 while cont == 0: say = input(''' Type 'todo' to see to-do list. Type 'b' to bank! Type 'north' to go to the North Pole. Type 'c' to play cards against a monster! Type 'sleep' to take a rest! Type 'm' to create a monster! Type 'inv' to open your bag! Type 'fish' to go fishing! Type 'map' to open the map! Type 'pack' to open a card pack. ''') if say == "f": sound.stop() cont = 1 fighting() if say == "north": sound.stop() cont = 1 northern(inv, bank) if say == "sleep": print("zzZZzZZz...") time.sleep(3) print("You feel refreshed!") time.sleep(1) cont = 1 home(inv, bank, True) if say == "todo": randomEvents.todo() cont = 1 home(inv, bank, True) if say == "inv": print("Opening the bag!") time.sleep(1) cont = 1 inventory(home, inv, bank) if say == "pack": pack(inv, bank) cont = 1 home(inv, bank, True) if say == "m": monsters.createMonster() cont = 1 time.sleep(2) home(inv, bank, True) if say == "map": cont = 1 map() if say == "c": monsters.viewMonster() print("Choose a difficulty from 0-9: ") x = input( "Or type 'tournament' for a challenge... 'xt' to lose all your cards!\n" ) sound.stop() if x == "tournament": for i in range(3): cards(inv, bank, 1, 1) elif x == "xt": for i in range(20): cards(inv, bank, 6, .1) else: cards(inv, bank, int(x), 1.5) cont = 1 time.sleep(2) home(inv, bank) #Bank your items. if say == "b": sound.stop() cont = 1 bank += inv #inv=['Beer'] # Save the stats in the .ini file. changestats.save(inv, "inv") changestats.save(bank, "bank") #refresh the inventory home(inv, bank, True) if say == "fish": #play music print("Gone fishing!") randomEvents.fishing(1, 7, 0, 1, inv) #stop music cont = 1 time.sleep(1.5) home(inv, bank, True)
def digsite(inv, bank, music=False): print('\n' * 12) #Play music if it is not already playing. This prevents a restart. if music == False: sound.play(path + "jazzrock.mp3") changestats.modify("location", 'digsite') bank = changestats.get("bank").strip('][').split(', ') inv = simplify() #randomEvents.house() print( "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Back to work. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \n" ) cont = 0 print( " |-------------------------------------------------------------|" ) print(" |Type 'dig' to start digging! You are currently at", changestats.get("meters"), "meters!|") while cont == 0: say = input( ''' |-------------------------------------------------------------| Type 'inv' to open your bag! Type 'map' to open the map! Type 'pack' to open a card pack! Type 'gamble' to gamble! ''') if say == "inv": print("Opening the bag!") time.sleep(1) cont = 1 inventory(digsite, inv, bank) if say == "pack": pack(inv, bank) cont = 1 digsite(inv, bank, True) if say == "map": cont = 1 map() if say == "dig": answer = False while answer == False: duration = input( "How many minutes would you like to dig? (1-20)") if int(duration) >= 0 and int(duration) < 21: answer = True levelUp(randomEvents.digGame(int(duration) * 60)) digsite(inv, bank, True) cont = 1 if say == "gamble": levelUp(randomEvents.gamble()) cont = 1 digsite(inv, bank, True)
#change the strength to a random int def newChar(): changestats.modify("strength", str(random.randint(6, 12))) basehp = changestats.modify("hitpoints", str(random.randint(20, 30))) changestats.modify("basehp", basehp) changestats.modify("luck", str(random.randint(6, 12))) changestats.modify("magic", str(random.randint(6, 12))) changestats.modify("level", str(random.randint(1))) changestats.modify("experience", str(random.randint(0))) enemyNum = random.randint(2, 4) inv = changestats.get("inv").strip('][').split(', ') bank = changestats.get("bank").strip('][').split(', ') location = changestats.get("location") ''' 1) A function that displays the inventory in a simple way, telling the player how many of each card they have. 2) if there's more than 1 King, Queen, or Jack, I add an 's' ''' def determineFace(card): if card == 11: print("Jack!") elif card == 12: print("Queen!!") elif card == 13: