Advertisement
McBroColi

Python Scripts - StackOverflow

Dec 1st, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.28 KB | None | 0 0
  1. #Import Modules
  2.  
  3. import random
  4. import time
  5.  
  6.  
  7. #Begin User Commands
  8.  
  9. easy='easy'
  10. medium='medium'
  11. hard='hard'
  12. expert='expert'
  13. rank_guest = "Guest"
  14. rank_user = "User"
  15. rank_admin = "Admin"
  16. cmd_help = "help"
  17. cmd_games = "games"
  18. cmd_yes = "yes"
  19. cmd_y = "y"
  20. cmd_no = "no"
  21. cmd_n = "n"
  22. cmd_admin = "admin"
  23. cmd_privilages = "privilages"
  24. cmd_target = 'target'
  25. acshun_give = "give"
  26. acshun_remove = "remove"
  27. acshun_do = "do"
  28. currentuser_rank=''
  29. helplist="""\nCommands:
  30. games - Lists the games you can play. Type the name of a game to play.
  31. admin - Administrators only: Access the control panel.
  32. privilages - Shows your current user privilages.
  33. help - Displays this message.
  34. """
  35. gamelist="""
  36. Text Adventure - Moreoverly a text fighter.
  37. Guessing Game - Guess 3 numbers and see if one of them equals the randomly generated one.
  38. """
  39. play_guessinggame = "guessing game"
  40. play_textadventure = "text adventure"
  41.  
  42. #All the TF preface commands
  43.  
  44. cmd_attack = "attack"
  45. cmd_protect = "protect"
  46.  
  47. tf_class_mage='mage'
  48. tf_class_mage_desc='A wizard of sorts. Weak in melee, strong in mid-range combat.'
  49. tf_class_elf='elf'
  50. tf_class_elf_desc='Uses his speed to evade attacks, higher chances of critical hits.'
  51. tf_class_warrior='warrior'
  52. tf_class_warrior_desc='Extremely fluent in melee, a hard hitter.'
  53.  
  54. tf_player_stats_hp=0
  55. tf_player_stats_mana=0
  56. tf_player_stats_mana_limit=200
  57. tf_player_stats_hp_limit=200
  58. tf_player_attackstrength=random.randint(40, 60)
  59. tf_player_attackstrength_str=str(tf_player_attackstrength)
  60.  
  61. tf_item_woodsword='Wooden Sword'
  62. tf_item_woodsword_desc='A starter sword. Low damage, and no critical hits.'
  63. tf_item_woodsword_dmg=random.randint(10, 15)
  64.  
  65. tf_player_inventory=[tf_item_woodsword]
  66.  
  67. tf_enemy_outlaw = "Outlaw"
  68. tf_enemy_outlaw_hp = 50
  69. tf_enemy_outlaw_hp_str = str(tf_enemy_outlaw_hp)
  70. tf_enemy_outlaw_attackstrength=random.randint(10, 15)
  71. tf_enemy_outlaw_attackstrength_str = str(tf_enemy_outlaw_attackstrength)
  72. tf_enemy_merc_stats = ['HP: '+tf_enemy_outlaw_hp_str, 'Attack Strength: Anywhere between 10 and 15']
  73.  
  74. tf_enemy_brute = "Brute"
  75. tf_enemy_brute_hp = 100
  76. tf_enemy_brute_hp_str = str(tf_enemy_brute_hp)
  77. tf_enemy_brute_attackstrength=random.randint(20, 35)
  78. tf_enemy_brute_attackstrength_str = str(tf_enemy_brute_attackstrength)
  79. tf_enemy_merc_stats = ['HP: '+tf_enemy_brute_hp_str, 'Attack Strength: Anywhere between 20 and 35']
  80.  
  81. tf_enemy_merc = "Mercenary"
  82. tf_enemy_merc_hp = 300
  83. tf_enemy_merc_hp_str = str(tf_enemy_merc_hp)
  84. tf_enemy_merc_attackstrength=random.randint(50, 60)
  85. tf_enemy_merc_attackstrength_str = str(tf_enemy_merc_attackstrength)
  86. tf_enemy_merc_stats = ['HP: '+tf_enemy_merc_hp_str, 'Attack Strength: Anywhere between 50 and 60']
  87.  
  88. tf_enemy=''
  89. tf_input=''
  90. battleinput=''
  91. tfinput=''
  92. #End the TF stuff
  93. adminpriv="""
  94. Administrators have access to everything, including the code, the admin panel, and the normal commands.\n"""
  95. userpriv="""
  96. Users have access to all the games and default commands. Editing the code, creating shortcuts, and accessing the Administrator panel are restricted.\n"""
  97. guestpriv="""
  98. Guests have access to basic functions such as some games and simple commands. They are restricted to various commands.\n"""
  99. #End User Commands
  100. def target(): #THIS FUNCTION IS A WORK IN PROGRESS AND WILL REMAIN HIDDEN FROM THE USERS TEMPORARILY
  101.     player_target = raw_input('Target: ')
  102.     action_target = raw_input('Give, Do, or Remove: ')
  103.     global username
  104.     player_from = username
  105.     if action_target.lower()==acshun_give.lower():
  106.         action_give = raw_input('Give: ')
  107.         print(player_from + ' gave ' + action_give + ' to ' + player_target + '!')
  108.         usermenu()
  109.     elif action_target.lower()==acshun_do.lower():
  110.         action_do = raw_input('Do: ')
  111.         print(player_from + ' ' + action_do + ' ' + player_target + '!')
  112.         usermenu()
  113.     elif action_target.lower()==acshun_remove.lower():
  114.         action_remove = raw_input('Remove: ')
  115.         print(player_from + ' removed ' + action_remove + ' from ' + player_target + '!')
  116.         usermenu()
  117.  
  118. def rankpriv():
  119.         global username
  120.         if username in rank_adminlist:
  121.                 print(adminpriv)
  122.                 usermenu()
  123.         elif username in rank_userlist:
  124.                 print(userpriv)
  125.                 usermenu()
  126.         else:
  127.                 print(guestpriv)
  128.                 usermenu()
  129.                
  130. tf_elf_help = """
  131. help - Displays this message
  132. attack - Attack the enemy
  133. protect - Shield yourself against up to 50 attack damage next turn
  134. inventory - Shows your current inventory
  135. equip - Equip one of the items in your inventory
  136. stats - Check your health, current equipped weapons, etc
  137. """
  138. def tf_elf_intro():
  139.     print('\nThe streets are empty. You walk the barren road. Only 4 and a half feet tall, you are looking for trouble.')
  140.     print('It is rainy. The mood is dark and dim, as it is dark out; the houses are missing their usual jazz of lights.')
  141.     print('Nobody is out. It seems like they are hiding from you. You think you are alone. But suddenly...')
  142.     tf_elf_battle()
  143. def tf_elf_battle():
  144.     pickenemy=random.randint(3, 3)
  145.     if pickenemy==3:
  146.         global tf_enemy
  147.         enemy="Mercenary"
  148.         print('A Mercenary steps in front of you. His stats are...')
  149.         print('HP: ' + tf_enemy_merc_hp_str)
  150.         print('Attack Strength: Anywhere between 50 and 60\n')
  151.         tf_elf_battle_merc()
  152. def attack_merc():
  153.     global tf_enemy
  154.     global tf_enemy_merc_hp
  155.     global tf_player_attack_strength
  156.     global tf_player_attackstrength_str
  157.     tf_player_attackstrength = random.randint(15, 20)
  158.     tf_enemy_merc_hp = tf_enemy_merc_hp - tf_player_attackstrength
  159.     print('You attacked him for ' + str(tf_player_attackstrength) + ' damage. He is now at ' + str(tf_enemy_merc_hp) + 'HP.')
  160.     tf_elf_battle_merc()
  161. def tf_elf_battle_merc():
  162.     battleinput==raw_input('Elf :: ')
  163.     global cmd_help
  164.     global cmd_attack
  165.     global cmd_protect
  166.     if battleinput.lower()==cmd_attack.lower():
  167.         attack_merc()
  168.     elif battleinput.lower()==cmd_help.lower():
  169.         print(tf_elf_help)
  170.        
  171. def textfighterclasspick():
  172.         tf_input=raw_input('TF :: ')
  173.         if tf_input.lower()==tf_class_elf.lower():
  174.                 tf_player_stats_hp=100
  175.                 tf_player_stats_hp_limit=150
  176.                 print('You have chosen the Elf class.\nStarting HP: 100 (out of a 150 maximum)')
  177.                 print('Starting Stamina: 100 (out of a 250 maximum)')
  178.                 print('No Mana: Elves do not use magic')
  179.                 start=raw_input('Ready to start? ')
  180.                 if start.lower()==cmd_yes:
  181.                     tf_elf_intro()
  182.                 else:
  183.                     print('Directing you back to the user menu...')
  184.                     time.sleep(2)
  185.                     usermenu()
  186.                
  187. def textfighterintro():
  188.         print('Alright, suit up General '+username+'! Pick your class.\n')
  189.         print('** Warrior:\n'+tf_class_warrior_desc)
  190.         print('** Elf:\n'+tf_class_elf_desc)
  191.         print('** Mage:\n'+tf_class_mage_desc)
  192.         textfighterclasspick()
  193.  
  194.        
  195. def checkrank():
  196.     global username
  197.     if username in rank_adminlist:
  198.         print("You are in the rank of Administrators.")
  199.     elif username in rank_userlist:
  200.         print("You are in the rank of Users.")
  201.     else:
  202.         print('You are in the rank of a Guest.')
  203. def usermenu():
  204.     um_in=raw_input('Menu :: ')
  205.     #Help Command
  206.     if um_in.lower()==cmd_help.lower():
  207.         print(helplist)
  208.         usermenu()
  209.     #Games Command
  210.     elif um_in.lower()==cmd_games.lower():
  211.         print(gamelist)
  212.         usermenu()
  213.     #Play 'Text Adventure' Command
  214.     elif um_in.lower()==play_textadventure.lower():
  215.           print('Booting up Text Adventure/Fighter...')
  216.           print('You have inserted an SSD for instant load times!') ################ PUT IN THE TIME.SLEEP HERE AGAIN FOR A FEW SECONDS
  217.           textfighterintro()
  218.     #Play 'Guessing Game' Command
  219.     elif um_in.lower()==play_guessinggame.lower():
  220.         print("Booting up Guessing Game...\n")
  221.         time.sleep(2)
  222.         promptguess()
  223.         usermenu()
  224.     #Admin Command
  225.     elif um_in.lower()==cmd_admin.lower():
  226.         print('This command exists - although it is not implemented yet.')
  227.         usermenu()
  228.     #Privilages
  229.     elif um_in.lower()==cmd_privilages.lower():
  230.         global currentuser_rank
  231.         print('\nYour privilages are...')
  232.         rankpriv()
  233.     #Target Fun
  234.     elif um_in.lower()==cmd_target.lower():
  235.         target()
  236.     #Otherwise...
  237.     else:
  238.         print("Invalid. Type 'help' for help.")
  239.         usermenu()
  240. def playagain():
  241.         gg_again=raw_input('Would you like to play again? ')
  242.         if gg_again.lower()==cmd_yes.lower():
  243.             print('Alright! Restarting...\n')
  244.             time.sleep(0.5)
  245.             promptguess()
  246.         elif gg_again.lower()==cmd_y.lower():
  247.             print('Alright! Restarting...\n')
  248.             time.sleep(0.5)
  249.             promptguess()
  250.         elif gg_again.lower()==cmd_no.lower():
  251.             print('Returning to the Menu...\n')
  252.             time.sleep(0.5)
  253.             usermenu()
  254.         elif gg_again.lower()==cmd_n.lower():
  255.             print('Returning to the Menu...\n')
  256.             time.sleep(0.5)
  257.             usermenu()
  258.         else:
  259.             print("Invalid - returning to the menu...")
  260.             time.sleep(0.5)
  261.             usermenu()
  262. def guess(g1, g2, g3, difficulty):
  263.     if difficulty.lower()==easy.lower():
  264.         randomint=random.randint(1, 10)
  265.     elif difficulty.lower()==medium.lower():
  266.         randomint=random.randint(1, 30)
  267.     elif difficulty.lower()==hard.lower():
  268.         randomint=random.randint(1, 100)
  269.     elif difficulty.lower()==expert.lower():
  270.         randomint=random.randint(1, 666)
  271.     #Break Line
  272.     randomintstr=str(randomint)
  273.     if g1==randomintstr:
  274.         print('Great job, correct on the first number! ('+g1+')')
  275.         playagain()
  276.     elif g2==randomintstr:
  277.         print('Nice one! The second number was correct. ('+g2+')')
  278.         playagain()
  279.     elif g3==randomintstr:
  280.         print('Excellent! The third number was correct. ('+g3+')')
  281.         playagain()
  282.     else:
  283.         print('Sorry, none were correct. It was '+randomintstr+'.')
  284.         playagain()
  285. def promptguess():
  286.     print('Easy: Guess 1-10.\nMedium: Guess 1-30.\nHard: Guess 1-100.\nExpert: Guess 1-666.')
  287.     difficulty=raw_input('Easy, Medium, Hard, or Expert? ')
  288.     g1=raw_input('First number: ')
  289.     if g1=="":
  290.         print('You must input a valid number! Restarting...')
  291.         time.sleep(1)
  292.         promptguess()
  293.     g2=raw_input('Second number: ')
  294.     if g2=="":
  295.         print('You must input a valid number! Restarting...')
  296.         time.sleep(1)
  297.         promptguess()
  298.     g3=raw_input('Third number: ')
  299.     if g3=="":
  300.         print('You must input a valid number! Restarting...')
  301.         time.sleep(1)
  302.         promptguess()
  303.     print('Generating results...')
  304.     time.sleep(2)
  305.     guess(g1, g2, g3, difficulty)
  306.    
  307. #Some lists...
  308.  
  309. users=['JynX', 'McBroColi', 'Deydria', 'Ray.henry', 'Zeke', '9/11Faggot', 'SplodyBitz', 'fartman']
  310. passes=['drpepper123', 'KY8G3HD', 'K3IEJLD', 'KWU4B9Z', 'K2CO2UI', 'logitechspeaker', 'AKDJASKDJKALU3EIASDMN389UDH9Q8WDH3U2HD38DH2389DH8923DH8923DH3', 'ifartinmymomsmouth']
  311. rank_adminlist=['McBroColi', 'Deydria', 'Ray.henry', 'Zeke', 'JynX']
  312. rank_userlist=['9/11Faggot', 'SplodyBitz', 'fartman']
  313. userlist=set(users)
  314. passlist=set(passes)
  315. username=""
  316.  
  317. #End lists
  318.  
  319. def promptlogin():
  320.     global username
  321.     username=raw_input('Username: ')
  322.     if username in userlist:
  323.         password=raw_input('Passcode: ')
  324.         if password in passlist:
  325.             usergen=random.randint(1, 3)
  326.             if usergen==3:
  327.                 print('Howdy, '+username+"!")
  328.                 checkrank()
  329.                 usermenu()
  330.             elif usergen==2:
  331.                 print('Greetings, '+username+"!")
  332.                 checkrank()
  333.                 usermenu()
  334.             elif usergen==1:
  335.                 print('Welcome, '+username+"!")
  336.                 checkrank()
  337.                 usermenu()
  338.         else:
  339.             print('Invalid Login: Bad Password')
  340.             promptlogin()
  341.     elif username=="Guest":
  342.         print('You have signed in as a Guest.')
  343.         usermenu()
  344.     else:
  345.         print('Invalid Login: Bad Username')
  346.         promptlogin()
  347. promptlogin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement