Created
March 10, 2023 10:19
-
-
Save R3DHULK/b7fde36c6954d9e68390c0aac8cfec24 to your computer and use it in GitHub Desktop.
Text Based Saloon Game Written In Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
try: | |
class SaloonGame: | |
def __init__(self): | |
self.money = 100 | |
self.drinks = ["Beer", "Whiskey", "Wine"] | |
self.prices = {"Beer": 5, "Whiskey": 10, "Wine": 15} | |
self.welcome_message = "Welcome to the Saloon! You have $100 to spend. " \ | |
"Each drink costs: Beer: $5, Whiskey: $10, Wine: $15. " \ | |
"You can type 'exit' to leave the Saloon." | |
def start_game(self): | |
print(self.welcome_message) | |
while True: | |
print("You have $" + str(self.money)) | |
drink = input("What would you like to drink? ") | |
if drink.lower() == "exit": | |
break | |
while drink.capitalize() not in self.drinks: | |
drink = input( | |
"Sorry, we don't have that drink. What would you like to drink? ") | |
if self.money < self.prices[drink.capitalize()]: | |
print("Sorry, you don't have enough money.") | |
else: | |
self.money -= self.prices[drink.capitalize()] | |
print("You have bought a " + drink.capitalize() + | |
". You have $" + str(self.money) + " left.") | |
print("Thanks for coming to the Saloon! You have $" + | |
str(self.money) + " left.") | |
game = SaloonGame() | |
game.start_game() | |
except KeyboardInterrupt: | |
print("Ctrl+C Deteced...Exiting...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment