Advertisement
VinColo

Python Healthy Shopping Game - working code

Aug 30th, 2013
1,540
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.10 KB | None | 0 0
  1. from sys import exit
  2. from ext_links import *
  3. from game_messages import *
  4.  
  5. init_score = [100]
  6.  
  7. def initial_score():
  8.     return init_score[0]
  9.    
  10. def cur_score():
  11.     return init_score[-1]
  12.  
  13. def affect_score(delta):
  14.     init_score.append(cur_score() + delta)
  15.     return cur_score()
  16.    
  17.  
  18. # Beginning. Proceed or quit game.
  19. def start():
  20.     print "Your shopping habits will either help you live longer or they will help you die sooner. No kidding! Wanna find out which one of the two in your case?", yn
  21.    
  22.     find_out = raw_input(select).upper()
  23.    
  24.     if find_out == "YES":
  25.         print "\nGreat! Let's go shopping... but first..."
  26.         print "Think of this as a personal health deposit account at the Health Bank..."
  27.         print "Your starting Health Score is:", initial_score()
  28.         print "So, here is the situation..."
  29.         inner_outer()
  30.     else:
  31.         out("No prob. May be next time.")
  32.  
  33.  
  34. # Choose shopping from inner or outer isles
  35. def inner_outer():
  36.     print "You enter the grocery store. You have to choose between the 'inner' or 'outer' isles. Which isles do you choose?"
  37.    
  38.     init_isle = raw_input(select).lower()
  39.    
  40.     if init_isle == "inner":
  41.         inner()
  42.     elif init_isle == "outer":
  43.         outer()
  44.     else:
  45.         print not_sure
  46.         inner_outer()
  47.        
  48.  
  49. # Define inner isles and the four subcategories.       
  50. def inner():
  51.     print "Okay. You are about to do some shopping from the inner isles of the store!"
  52.     print "There are four main sections. Choose which section you want to go to first."
  53.     print "Your choices are: \n\n\t cereal \n\t snacks and chips \n\t peanut butter \n\t sports drinks\n"
  54.    
  55.     inner_choice = raw_input(select).lower()
  56.    
  57.     if inner_choice == "cereal":
  58.         affect_score(-5)
  59.         print "NOTE: Shopping from the 'cereal' isle is not a good idea. You just lost 5 points from your Health Score. Your new Health Score is:", cur_score()
  60.         print cereal_url
  61.         again()
  62.     elif inner_choice == "snacks and chips":
  63.         affect_score(-5)
  64.         print "NOTE: Shopping from the 'snacks and chips' isle is not a good idea. You just lost 5 points from your Health Score. Your new Health Score is:", cur_score()
  65.         print snack_url
  66.         again()
  67.     elif inner_choice == "peanut butter":
  68.         affect_score(-5)
  69.         print "NOTE: Shopping from the 'peanut butter' isle is not a good idea. You just lost 5 points from your Health Score. Your new Health Score is:", cur_score()
  70.         print peanut_url
  71.         again()
  72.     elif inner_choice == "sports drinks":
  73.         affect_score(-5)
  74.         print "NOTE: Shopping from the 'sports drinks' isle is not a good idea. You just lost 5 points from your Health Score. Your new Health Score is:", cur_score()
  75.         print gatorade_url
  76.         again()
  77.     else:
  78.         print not_sure
  79.         inner()
  80.        
  81.  
  82. # Define outer isles and the three subcategories.          
  83. def outer():
  84.     print "You are about to shop from the outer isles of the store!"
  85.     print "There are three main sections. Choose which section you want \nto go to first."
  86.     print "Your choices are: \n\n\t produce \n\t dairy \n\t meat \n"
  87.    
  88.     outer_choice = raw_input(select).lower()
  89.    
  90.     if outer_choice == "produce":
  91.         affect_score(+5)
  92.         print "Awesome! Shopping from the 'produce' isle is a great idea. You just added 5 points to your Health Score. Your new Health Score is:", cur_score()
  93.         print poduce_url
  94.         again()
  95.     elif outer_choice == "dairy":
  96.         affect_score(+2)
  97.         print "Alright. Shopping from the 'dairy' isle is a good idea. You just added 2 points to your Health Score. Your new Health Score is:", cur_score()
  98.         print dairy_url
  99.         again()
  100.     elif outer_choice == "meat":
  101.         affect_score(+2)
  102.         print "Not bad! Shopping from the 'meat' isle could be a good idea. You just added 2 points to your Health Score. Your new Health Score is:", cur_score()
  103.         print meat_url
  104.         again()
  105.     else:
  106.         print not_sure
  107.         outer()
  108.  
  109.  
  110.  
  111. # Define a function for quitting the game      
  112. def out(why):
  113.     print why, "Your final Health Score is:", cur_score()
  114.     print "Good bye!"
  115.     exit(0)
  116.    
  117.  
  118. # Define a function for going back to choosing from inner or outer isles 'inner_outer()'   
  119. def again():
  120.     print "Want to continue shopping?", yn
  121.     go_again = raw_input(select).upper()
  122.    
  123.     if go_again == "YES":
  124.         inner_outer()
  125.     else:
  126.         out("No prob.")
  127.    
  128.  
  129. # Initiate the game
  130. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement