robertvari

tmp

Apr 28th, 2019
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.89 KB | None | 0 0
  1. import time, random, os
  2.  
  3. playerName = None
  4. levels = {
  5.     "1":{"name":"Easy", "points":1, "range":5},
  6.     "2":{"name":"Medium", "points":3, "range":10},
  7.     "3":{"name":"Hard", "points":5, "range":20},
  8. }
  9. gifts = {
  10.     "1":{"name": "Candy", "price":1},
  11.     "2":{"name": "Chocolate Bar", "price":5},
  12.     "3":{"name": "Tour To The Moon", "price":10},
  13.    }
  14. points = 1
  15. DEBBUG = True
  16.  
  17. def main():
  18.     clear_screen()
  19.     print("Hello! This is a simple guess game.")
  20.     time.sleep(2)
  21.  
  22.     global playerName
  23.     playerName = input("Would you please tell me your name?")
  24.  
  25.     clear_screen()
  26.     print(f"Well hello {playerName}")
  27.     time.sleep(2)
  28.  
  29.     main_menu()
  30.  
  31. def main_menu():
  32.     clear_screen()
  33.     print(f"Here are your options {playerName}")
  34.     menu = """
  35.    1. Easy (0-5)
  36.    2. Medium (0-10)
  37.    3. Hard (0-10)
  38.    4. Gift Shop
  39.    5. Exit game.
  40.    """
  41.  
  42.     print(menu)
  43.     userInput = input()
  44.  
  45.     if not userInput in ["1","2","3","4","5"]:
  46.         clear_screen()
  47.         print("Use only the options I gave you  silly")
  48.         time.sleep(3)
  49.         main_menu()
  50.  
  51.     if userInput in ["1", "2","3"]:
  52.         play(userInput)
  53.     elif userInput == "4":
  54.         gift_shop()
  55.     else:
  56.         print(f"See you soon {playerName}!!!!!!")
  57.         time.sleep(3)
  58.         exit()
  59.  
  60.  
  61. def play(level):
  62.     global points
  63.     guess = random.randint(0, levels[level]['range'])
  64.     lives = 3
  65.     clear_screen()
  66.  
  67.     print(f"You are playing on {levels[level]['name']} level.")
  68.     time.sleep(2)
  69.     if level == "1":
  70.         print("This will be easy for you. It is good for warming up!")
  71.     elif level == "2":
  72.         print("This will be a bit harder.")
  73.     else:
  74.         print(f"You must be a brave one {playerName}, You can earn a lot if you survive!")
  75.     time.sleep(3)
  76.  
  77.     print(f" On this level you can win {levels[level]['points']} point but you have only {lives} tries!")
  78.     print(f"Be careful!")
  79.  
  80.     time.sleep(5)
  81.     clear_screen()
  82.  
  83.     print(f"I guessed a number between 0-{levels [level]['range']}.")
  84.     if DEBBUG:
  85.         print(f"DEBBUG: guess {guess}")
  86.  
  87.     userGuess = int(input("What is your guess???"))
  88.  
  89.     while not userGuess == guess:
  90.         clear_screen()
  91.         lives -= 1
  92.  
  93.         if lives == 0: # ha nem maradt életünk
  94.             print(f"You lost all your points... Maybe baby next time!")
  95.             time.sleep(5)
  96.             main_menu()
  97.  
  98.         if lives == 1:
  99.             print(f"You have {lives} lives left. This is your last chance!!!")
  100.         else:
  101.             print(f"You have {lives} lives left.")
  102.  
  103.         userGuess = int(input("What is your next guess?????"))
  104.  
  105.     clear_screen()
  106.     print(f"Yessss! {userGuess} was my number!")
  107.     print(f"I give you {levels[level]['points']}  point(s)")
  108.     points += levels[level]['points']
  109.  
  110.     print(f" Now You have {points} points.")
  111.     print(f"Please go to the gift shop or play more!")
  112.     time.sleep(5)
  113.     main_menu()
  114.  
  115.  
  116. def gift_shop():
  117.     global points
  118.     clear_screen()
  119.  
  120.     if points < 1:
  121.         print("You do not have enough points yet!")
  122.         print("Go back and please play a bit more!")
  123.         time.sleep(4)
  124.         main_menu()
  125.  
  126.     print(f"Dear {playerName}, These are the following items you can buy:")
  127.  
  128.     available_items = {}
  129.     for key, value in gifts.items():
  130.         if value["price"] <= points:
  131.             available_items[key] = value
  132.             print(f"{key}. {value['name']} price: {value['price']}")
  133.  
  134.     userInput = input()
  135.     while not userInput in available_items:
  136.         clear_screen()
  137.         print("This item is not in the menu")
  138.         userInput = input()
  139.  
  140.     clear_screen()
  141.  
  142.     points -= available_items[userInput]["price"]
  143.     print(f"You bought a {available_items[userInput]['name']}.")
  144.     print(f"You have a {points} points.")
  145.     time.sleep(3)
  146.     main_menu()
  147.  
  148. def clear_screen():
  149.       os.system("cls")
  150.  
  151. main_menu()
Advertisement
Add Comment
Please, Sign In to add comment