Advertisement
Guest User

Bar Fight 1.5

a guest
Jun 19th, 2013
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.12 KB | None | 0 0
  1. #  Copyright 2013 SuperHitler Von McStalinPants Esquire
  2.  
  3. #  This program is free software; you can redistribute it and/or modify
  4. #  it under the terms of the GNU General Public License as published by
  5. #  the Free Software Foundation; either version 3 of the License, or
  6. #  (at your option) any later version.
  7. #  
  8. #  This program is distributed in the hope that it will be useful,
  9. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. #  GNU General Public License for more details.
  12. #  
  13. #  You should have received a copy of the GNU General Public License
  14. #  along with this program; if not, write to the Free Software
  15. #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  16. #  MA 02110-1301, USA.
  17. #  Or you could, you know, read it online.
  18.  
  19. #Bar Fight v1.5
  20.  
  21. ver = 1.5
  22.  
  23. #TODO:
  24. #Make multiple drugbots.
  25. #Make new variants of drugbot.
  26. #Add target system so player can target different enemies, or enemies can target each other (such as a cleric healing a team mate)
  27.  
  28. import time
  29. import sys
  30. import os
  31. import subprocess
  32. import platform
  33. import copy
  34. from random import randint
  35.  
  36. #---VARIABLES---#
  37.  
  38. hp1 = 300
  39. hp2 = 300
  40. mp1 = 100
  41. mp2 = 100
  42. inv1 = ["dig", "sword"]
  43. inv2 = ["dig", "sword", "steak"]
  44. status1 = []
  45. status2 = []
  46. hp = [hp1, hp2]
  47. mp = [mp1, mp2]
  48. inv = [inv1, inv2]
  49. status = [status1, status2]
  50. player1 = 0
  51. player2 = 1
  52.  
  53. players = [] #Add the names of all the AI players here and pass their names to the checkuse function. Protip by Scarlet.
  54. ename = "Drugbot"
  55. AIEXPHP = copy.copy(hp[1])
  56. togglespeech = 1
  57.  
  58. GREETING = "Welcome to Bar Fight %s. After 9 days in development, \n\
  59. hopefully it will have been worth the wait.\n\
  60. Use the command \"help\" for a list of commands." % ver
  61. HISTORY = []
  62. HELP = [
  63. "\"use itemname\": Use an item in your inventory.",
  64. "\"status\": Display the current state of the game.",
  65. "\"inventory\": Display your inventory.",
  66. "\"history\": Display the console history.",
  67. "\"info itemname\": Display information about any item in the game.",
  68. "\"ts\": Toggle the annoying speech synthesis.",
  69. "\"quit\": Quit the game."
  70. ]
  71.  
  72. #---UTILITY FUNCTIONS---#
  73.  
  74. def clear():
  75.     subprocess.Popen("cls" if platform.system() == "Windows" else "clear", shell=True).wait()
  76.  
  77. def hist(x='nil', y=HISTORY, z="TERMINAL HISTORY:"):
  78.     if not x == 'nil':
  79.         y.append(x)
  80.     else:
  81.         print z
  82.         for a in y:
  83.             time.sleep(0.08)
  84.             print "--" + a
  85.         niceprt("Press ENTER to continue. Screen will be cleared.", 0, 0, 1, 0.03)
  86.         clear()
  87.  
  88. def speak(x):
  89.     subprocess.Popen("espeak \"%s\"" % x, stderr=subprocess.PIPE, shell=True)
  90.  
  91. def niceprt(x, inp=1, clr=1, log=0, sleeptime=0.05, opt='CONTINUE->'):
  92.     if togglespeech == 1:
  93.         speak(x)
  94.     for a in x:
  95.         sys.stdout.write( '%s' % a )
  96.         sys.stdout.flush()
  97.         time.sleep(sleeptime)
  98.     print " "
  99.     if inp == 0:
  100.         raw_input(opt)
  101.     if log == 0:
  102.         hist(x)
  103.     if clr == 0:
  104.         clear()
  105.  
  106. def findi(f, seq):
  107.     for item in seq:
  108.         if f == item:
  109.             return item
  110.  
  111. def leave():
  112.     niceprt("Do you really want to quit?", 1, 1, 1)
  113.     if raw_input("y/N? ").lower() == "y":
  114.         niceprt("It was fun having you!", 0, 1, 0, 0.04, 'Goodbye...')
  115.         quit()
  116.     else:
  117.         niceprt("The fun never ends!", 1, 1, 1)
  118.         term()
  119.  
  120. def confuzzled_prompt(x):
  121.     a = [
  122.     "I'm not sure what \'%s\' means!",
  123.     "I'm sorry, but \'%s\' confuzzles me.",
  124.     "404: \'%s\' not found.",
  125.     "There is no \'%s\' here, only Gankutsuou.",
  126.     "I'm sorry, Dave, I'm afraid I can't do \'%s\'.",
  127.     "I'm not sure why you would think there would be a \'%s\' command.",
  128.     "AH! You think you're doing some damage!? 2 plus 2 equals \'%s\'.",
  129.     "This is my original character \'%s\', do not steal.",
  130.     "What is the DEAL with \'%s\'!?",
  131.     "If it don't make \'%s\', it don't make cents.",
  132.     "That wasn't very \'%s\' of you.",
  133.     "I told you about the \'%s\' dog, I warned you.",
  134.     "I can do no \'%s\', for I do not know what it is...",
  135.     "You told me you would take me to our \'%s\' place, but you never did...",
  136.     "It is pitch black. You are likely to be eaten by a \'%s\'.",
  137.     "Does a set of all sets contain \'%s\'?",
  138.     "Omg \'%s\' is so moe!"
  139.     ]
  140.     b = [
  141.     "No input detected.",
  142.     "Input missing.",
  143.     "I cannot process your request without input.",
  144.     "I need input, first.",
  145.     "I can't do anything without input.",
  146.     "Please provide input.",
  147.     "Error: Input not detected.",
  148.     "No input discovered.",
  149.     "That is too little input for processing."
  150.     ]
  151.     if len(x) == x.count(" "):
  152.         niceprt(b[randint(0, len(b) - 1)], 1, 1, 1, 0.03)
  153.     else:
  154.         niceprt(a[randint(0, len(a) - 1)] % x, 1, 1, 0, 0.03)
  155.     term()
  156.  
  157. def term():
  158.     a = raw_input("PROMPT-> ").lower()
  159.     if a == "history":
  160.         clear()
  161.         hist()
  162.         term()
  163.     elif a == "help":
  164.         clear()
  165.         hist('nil', HELP, "HELP SCREEN/COMMANDS")
  166.         term()
  167.     elif a == "status":
  168.         clear()
  169.         niceprt("GAME STATUS:")
  170.         print("-- Drugbot has %s HP" % hp[1])
  171.         print("-- You have %s HP" % hp[0])
  172.         print("-- Drugbot has %s MP" % mp[1])
  173.         print("-- You have %s MP" % mp[0])
  174.         print("-- Your Items: %s" % inv[0])
  175.         niceprt("Press ENTER to continue.", 0, 0)
  176.         term()
  177.     elif a == "quit":
  178.         leave()
  179.     elif a == "ts":
  180.         global togglespeech
  181.         if togglespeech == 0:
  182.             togglespeech = 1
  183.         else: togglespeech = 0
  184.         niceprt("Speech synthesis toggled.", 1, 1, 0, 0.01)
  185.         term()
  186.     elif a == "inventory":
  187.         niceprt("Your current inventory: ", 1, 1, 1)
  188.         for name in inv[0]:
  189.             print("-- {!s}".format(name.title()))
  190.         term()
  191.     elif a[:3] == "say":
  192.         niceprt(a.upper()[4:])
  193.         term()
  194.     elif a[:3] == "use":
  195.         checkuse(a[4:], player1)
  196.     elif a[:4] == "info":
  197.         if a[5:] in iteminfo:
  198.             niceprt(iteminfo[a[5:]])
  199.         else: niceprt("No such item in vocabulary.")
  200.         term()
  201.     elif a == "pass":
  202.         pass
  203.     elif a == "sodoku":
  204.         hp[0] = 0
  205.     else:
  206.         confuzzled_prompt(a)
  207.  
  208. def announceuse(x, player):
  209.     niceprt("{!s} used {!s}.".format("You" if player is player1 else ename, x.title()))
  210.  
  211. def otherplayer(player):
  212.     if player is 1:
  213.         return 0
  214.     elif player is 0:
  215.         return 1
  216.  
  217. def statcheck(stat, targ, prt='nil'):
  218.     if stat < targ:
  219.         if prt is not 'nil':
  220.             niceprt(prt)
  221.         return 1
  222.     else: return 0
  223.  
  224. def miss(player, ext1, ext2):
  225.     MISS = randint(0, ext1)
  226.     if player == 0:
  227.         if MISS < ext2:
  228.             niceprt("But you missed.")
  229.             return 1
  230.     else:
  231.         if MISS < ext2:
  232.             niceprt("But he missed.")
  233.             return 1
  234.  
  235. #---ITEMS---#
  236.  
  237. #Yes, I know this looks redundant. Yes, I know exactly what kind of functions I could write
  238. #to make this less redundant. No, I don't care. This is fine IMO. And hard-coding all this
  239. #gives me a little more freedom to make each item do specific things.
  240.  
  241. def rawitem(player):
  242.     name = "rawitem"
  243.     announceuse(name, player)
  244.     hp[otherplayer(player)] -= 50
  245.     inv[player].remove(name)
  246.     niceprt("{!s} lost 50 HP.".format(ename if player is player1 else "You"))
  247.  
  248. def sword(player):
  249.     name = "sword"
  250.     rand = randint(20, 40)
  251.     announceuse(name, player)
  252.     if miss(player, 10, 4) == 1:
  253.         pass
  254.     else:
  255.         hp[otherplayer(player)] -= rand
  256.         niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
  257.  
  258. def katana(player):
  259.     name = "katana"
  260.     rand = randint(30, 50)
  261.     announceuse(name, player)
  262.     if miss(player, 10, 2) == 1:
  263.         pass
  264.     else:
  265.         hp[otherplayer(player)] -= rand
  266.         niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
  267.  
  268. def magicdart(player):
  269.     if player == 1 and statcheck(mp[1], 20) == 1:
  270.         drugbot()
  271.         pass
  272.     elif player == 0 and statcheck(mp[0], 20, "You don't have enough MP") == 1:
  273.         pass
  274.     else:
  275.         name = "magic dart"
  276.         rand = randint(40, 70)
  277.         announceuse(name, player)
  278.         if miss(player, 20, 10) == 1:
  279.             pass
  280.         else:
  281.             hp[otherplayer(player)] -= rand
  282.             niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
  283.         mp[player] -= 20
  284.         inv[player].remove(name)
  285.         niceprt("{!s} lost {!s} MP.".format("You" if player is player1 else ename, 20))
  286.  
  287. def steak(player):
  288.     name = "steak"
  289.     announceuse(name, player)
  290.     hp[player] += 20
  291.     inv[player].remove(name)
  292.     niceprt("{!s} gained 20 HP.".format("You" if player is player1 else ename))
  293.  
  294. def pocky(player):
  295.     name = "pocky"
  296.     announceuse(name, player)
  297.     hp[player] += 10
  298.     inv[player].remove(name)
  299.     niceprt("{!s} gained 10 HP.".format("You" if player is player1 else ename))
  300.  
  301. def manapot(player):
  302.     name = "mana pot"
  303.     announceuse(name, player)
  304.     mp[player] += 50
  305.     inv[player].remove(name)
  306.     niceprt("{!s} gained 50 MP.".format("You" if player is player1 else ename))
  307.  
  308. def dig(player):
  309.     name = "dig"
  310.     il = ["rawitem", "magic dart", "steak", "katana", "pocky", "mana pot"] #Add items to this list if you want the player to get them with "dig".
  311.     infitems = ["katana"] #Put items with infinite uses here, so they don't clog the inventory by staying there forever.
  312.     rand1 = randint(0, 20)
  313.     rand2 = il[randint(0, len(il) - 1)]
  314.     announceuse(name, player)
  315.     if rand1 < 5:
  316.         niceprt("{!s} didn't find anything, though.".format("You" if player is player1 else ename))
  317.     else:
  318.         niceprt("{!s} found a {!s}".format("You" if player is player1 else ename, rand2.title()))
  319.         if rand2 == findi(rand2, infitems) and findi(rand2, inv[player]):
  320.             niceprt("But it's not nessisary for {!s} to have more than one.".format("You" if player is player1 else ename))
  321.         else:
  322.             inv[player].append(rand2)
  323.  
  324. #Not items but item-specific stuff.
  325.  
  326. def checkuse(x, player):
  327.     if findi(x, inv[player]):
  328.         use(x, player)
  329.     else:
  330.         if player == player1:
  331.             niceprt("You don't have that item.")
  332.             term()
  333.         else: niceprt("ERROR: AI tried to use item it doesn't have.")
  334.  
  335. def use(x, player):
  336.     itemlist[x](player)
  337.  
  338. itemlist = { #shit, it's better than elif elif elif. This is what I call "variety".
  339. "dig":dig,
  340. "sword":sword,
  341. "rawitem":rawitem,
  342. "magic dart":magicdart,
  343. "steak":steak,
  344. "pocky":pocky,
  345. "katana":katana,
  346. "mana pot":manapot
  347. }
  348.  
  349. iteminfo = {
  350. "dig":"If you're low on items, dig around for some more. Infinite uses.",
  351. "sword":"Deal 20 to 40 HP to that land lubber. Infinite uses.",
  352. "rawitem":"Genuine item, raw. Deals 50 HP.",
  353. "magic dart":"If you're willing to give up 20 MP, deals 40 to 70 HP.",
  354. "steak":"Steak made of real artificial chicken. Heals 20 HP.",
  355. "pocky":"Raw sewage commonly consumed by beached whales. Heals 10 HP.",
  356. "katana":"Deals 30 to 50 HP. Contradicting real life, it never breaks.",
  357. "mana pot":"Gives 50 MP. That's it."
  358. }
  359.  
  360. #---DRUGBOT HIMSELF---#
  361.  
  362. def filteritems(lst, x=0):
  363.     tempinv = []
  364.     for it1 in inv[1]:
  365.         if it1 == findi(it1, lst):
  366.             tempinv.append(it1)
  367.     return tempinv
  368.  
  369. def robotattack(): #I appear today to announce my retirement.
  370.     atkitems = ["magic dart", "rawitem", "sword", "katana", "mana pot"]
  371.     tempinv = filteritems(atkitems)
  372.     randinv = tempinv[randint(0, len(tempinv) - 1)]
  373.     if tempinv == []:
  374.         checkuse("dig", player2)
  375.     elif randint(0, 20) >= 16:
  376.         checkuse("dig", player2)
  377.     else:
  378.         checkuse(randinv, player2)
  379.  
  380. def drugbot():
  381.     weed = ["steak", "pocky"]
  382.     tempinv = filteritems(weed)
  383.     if tempinv == []:
  384.         if randint(0, 50) <= 20:
  385.             checkuse("dig", player2)
  386.         else:
  387.             robotattack()
  388.     else:
  389.         randinv = tempinv[randint(0, len(tempinv) - 1)]
  390.         if hp[1] <= AIEXPHP/2:
  391.             if randint(0, 30) <= 10:
  392.                 robotattack()
  393.             else:
  394.                 checkuse(randinv, player2)
  395.         elif hp[1] <= AIEXPHP/3:
  396.             checkuse(randinv, player2)
  397.         else:
  398.             robotattack()
  399.     mainloop()
  400.  
  401. #---GAME LOGIC---#
  402.  
  403. def this_will_be_the_sixth_time_we_have_destroyed_it_and_we_have_become_exceedingly_efficient_at_it():
  404.     global HISTORY
  405.     hp[0] = 500
  406.     hp[1] = 500
  407.     mp[0] = 100
  408.     mp[1] = 100
  409.     inv[0] = ["dig", "sword"]
  410.     inv[1] = ["dig", "sword", "steak"]
  411.     status[0] = []
  412.     status[1] = []
  413.     HISTORY=[]
  414.     clear()
  415.     niceprt("New game initiated.")
  416.     mainloop()
  417.  
  418. def playagain():
  419.     niceprt("Would you like to play again?", 1, 1, 1)
  420.     a = raw_input("y/n? ->").lower()
  421.     if a == "y":
  422.         this_will_be_the_sixth_time_we_have_destroyed_it_and_we_have_become_exceedingly_efficient_at_it()
  423.     elif a == "n":
  424.         niceprt("That was a great game. Goodbye.", 0)
  425.         quit()
  426.     else:
  427.         niceprt("I'm sorry, I didn't quite get that.", 1, 1, 1)
  428.         playagain()
  429.  
  430. def deathcheck():
  431.     if hp[0] <= 0:
  432.         niceprt("You have lost.")
  433.         playagain()
  434.     elif hp[1] <= 0:
  435.         niceprt("You have won!")
  436.         playagain()
  437.  
  438. def mainloop():
  439.     deathcheck()
  440.     term()
  441.     deathcheck()
  442.     drugbot()
  443.  
  444. niceprt(GREETING)
  445. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement