import random class game: snailMoney = 0.0 mushroom = "none" age = 0 life = 20 name = "Snail" shellColor = "grey" dead = False def spendMoney(self, amount): if(self.snailMoney < amount): print("You don't have enough money!") return -1 else: self.snailMoney -= amount return amount def ageOneDay(self): self.age += 1 if(self.age > self.life): self.dead = True print(self.name + " has died. They will be missed") def initialize(self): print("Welcome to A Snail's World, the world's most sophisticated snail life experience simulation program. What is your name, new snail?") self.name = input() print("Hello " + self.name + ", when you are ready to begin your snail's journey through life, press enter.") input() def printStats(self): print("\nCurrent snail stats for " + self.name + " the snail:\nSnail Age: " + str(self.age) + " day(s)\nSnail Money: " + str(self.snailMoney) + " snail dollars\nMushrooms: " + self.mushroom + "\nShell color: " + self.shellColor) def displayChoices(self): inputValue = -1 print("\n\n1. Search for mushrooms") print("2. Socialize") print("3. Repaint shell") if(self.mushroom != "none"): print("4. Eat a mushroom") inputValue = input() while(int(inputValue) < 1 or int(inputValue) > 4): print("Please enter a valid choice!:") inputValue = input() else: inputValue = input() while(int(inputValue) < 1 or int(inputValue) > 3): print("Please enter a valid choice!:") inputValue = input() if(int(inputValue) == 1): if(self.mushroom == "none"): searchForMushrooms() else: print("You already have a mushroom!") displayChoices() elif(int(inputValue) == 2): socialize() elif(int(inputValue) == 3): repaintShell() elif(int(inputValue) == 4): eatMushroom() def searchForMushrooms(self): print("\n\nYou come to the field and see a few mushrooms to choose from:") print("1. A green mushroom") print("2. A purple mushroom") print("3. A blue mushroom") print("4. A yellow mushroom") print("\nWhich mushroom do you pick?") inputValue = input() while(int(inputValue) < 1 or int(inputValue) > 4): print("Please enter a valid choice!:") inputValue = input() if(int(inputValue) == 1): self.mushroom = "green" elif(int(inputValue) == 2): self.mushroom = "purple" elif(int(inputValue) == 3): self.mushroom = "blue" elif(int(inputValue) == 4): self.mushroom = "yellow" print("You got a " + self.mushroom + " mushroom!") def socialize(self): print("\n\nYou enter the snail cafe and note a few friendly snails hanging out. Who do you talk to?") print("1. Boris the snail") print("2. Franny the snail") print("3. Josef the snail") print("4. Penelope the snail") inputValue = input() while(int(inputValue) < 1 or int(inputValue) > 4): print("Please enter a valid choice!:") inputValue = input() if(int(inputValue) == 1): print("You slither on over to Boris and start up a conversation. He says, 'Hey there " + self.name + "! Wanna hear something funny? I was talking to my snail friend Paris, and she said that blue mushrooms are just absolutely delicious! What she failed to mention is that they're bad for you! They shorten your lifespan considerably! That poor soul.'") if(self.shellColor != "grey"): print("He also comments, 'Wow! Your " + self.shellColor + " shell is looking good! I should get mine done sometime, too.") elif(int(inputValue) == 2): print("You decide to see what Franny has been up to. 'Hello " + self.name + "!' she says, 'I have been meaning to talk to you about something. Look, I don't want to get into the dirty details, but let's say that a certain snail friend of mine didn't keep his mouth shut about the you-know-what, so it looks like we're gonna have to off him. Word on the street is those purple mushrooms are crazy poisonous. One bite and you're a goner. If I had one, I could make sure that this friend of mine doesn't squeal no more. So " + self.name + ", got any purple mushrooms?'") print("[Enter y or n]") choice = input() while(choice != "y" and choice != "n"): print("Please enter a valid choice!:") choice = input() if(choice == "y"): if(self.mushroom == "purple"): print("You hand over the purple mushroom and Franny comments, 'Thanks " + self.name + ". I knew I could count on you. Here's something for your trouble.'") print("You gained 80.00 snail dollars!") self.snailMoney += 80 self.mushroom = "none" else: print("Franny looks at you, confused, and says, 'Huh? It doesn't look like you have a poisonous purple mushroom. Come see me when you do.'") else: print("Franny looks a bit disappointed and says, 'Alright, well suit yourself. Come see me if you can help me out.'") elif(int(inputValue) == 3): print("You head on over to see Josef the snail. He greets you and asks, 'Say " + self.name + ", I've been dying to have one of those delicious green mushrooms. They taste great and they're supposedly really good for you! Do you have any?'") print("[Enter y or n]") choice = input() while(choice != "y" and choice != "n"): print("Please enter a valid choice!:") choice = input() if(choice == "y"): if(self.mushroom == "green"): print("You hand over the green mushroom and Josef comments, 'Thanks " + self.name + ", This looks delicious! Here's something for your trouble.'") print("You gained 130.00 snail dollars!") self.snailMoney += 130 else: print("Josef looks at you, confused, and says, 'Huh? It doesn't look like you have a delicious green mushroom. Come see me when you do.'") else: print("Josef looks a bit disappointed and says, 'Alright, that's alright. Come see me if you can help me out.'") elif(int(inputValue) == 4): print("You walk over to go talk to Penelope the snail. She looks happy to see you and says, 'HELLO!! I am so happy! You know why? I ate a yellow mushroom and now I'm going to live longer! Did you know that when you eat a yellow mushroom, there's a chance it will extend your life by several days? Amazing!'") if(self.shellColor != "grey"): print("She also comments, 'Hey! I like your " + self.shellColor + " shell, by the way! You always were s stylish one.") print("After a long day at the Snail Cafe, you decide to head home.") def eatMushroom(self): if(self.mushroom == "green"): print("You eat a delicious green mushroom! Tha flavor dances upon your palette gracefully") elif(self.mushroom == "blue"): print("You eat the blue mushroom and it is the most delicious thing you've ever eaten. You fall asleep in a mushroomy daze. When you wake up, you don't feel so well. One day has been removed from your lifespan.") self.life -= 1 elif(self.mushroom == "purple"): print("The purple mushroom tastes a little funny...suddenly your heart feels a sharp pain, and you die immediately.") self.life = 0 elif(self.mushroom == "yellow"): randChoice = random.randint(0, 2) if(randChoice == 0): print("The yellow mushroom tastes so great that your life has been extended by 3 days!") else: print("The yellow mushroom tastes great, but you feel no different after eating it.") self.mushroom = "none" def repaintShell(self): print("\n\nYou slither on over to the shell painting shop. What color do you ask for?") print("1. Red (50.00 Snail dollars)") print("2. Green (50.00 Snail dollars)") print("3. Blue (50.00 Snail dollars)") print("4. Gold (400.00 Snail dollars)") print("5. Cancel") inputValue = input() while(int(inputValue) < 1 or int(inputValue) > 5): print("Please enter a valid choice!:") inputValue = input() if(int(inputValue) == 1): if(self.snailMoney >= 50.00): self.snailMoney -= 50.00 self.shellColor = "red" print("Enjoy your flashy new red shell!") else: print("You don't have enough snail money!") repaintShell() elif(int(inputValue) == 2): if(self.snailMoney >= 50.00): self.snailMoney -= 50.00 self.shellColor = "green" print("Enjoy your trendy new green shell!") else: print("You don't have enough snail money!") repaintShell() elif(int(inputValue) == 3): if(self.snailMoney >= 50.00): self.snailMoney -= 50.00 self.shellColor = "blue" print("Enjoy your cool new blue shell!") else: print("You don't have enough snail money!") repaintShell() elif(int(inputValue) == 4): if(self.snailMoney >= 400.00): self.snailMoney -= 40.00 self.shellColor = "gold" print("Wow! Well, aren't you a well-off snail! You will be the talk of the town with your fancy new golden shell.") else: print("You don't have enough snail money!") repaintShell() if(int(inputValue) == 5): print("Thank you for visitng the snail depot!") def startDay(self): self.printStats() if(self.age == 0): print(self.name + " the snail has woken up for their first day in the snail world. They are ready to grab the world by the eye stalks and make a name for themselves. However, they only live for 20 days, so they should live in the moment! What do they do today?") displayChoices() else: print("\n\nAnd so begins another day in the life of " + self.name + " the snail. What wonders await him today?") displayChoices() ageOneDay() if(dead): print("\n\nAnd thus ends the legacy of " + self.name + " the snail. Farewell!") input() else: print("\n\nAnd so another day has ended in the life of " + self.name + " the snail. Tomorrow is a new day!") gameInstance = game() gameInstance.initialize() gameInstance.startDay()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question