Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Copyright 2013 SuperHitler Von McStalinPants Esquire
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- # MA 02110-1301, USA.
- # Or you could, you know, read it online.
- #Bar Fight v1.5
- ver = 1.5
- #This is awful but has potential. But I don't care because I'm done with it.
- #I did some weird stuff in this I'm not sure why. I don't care though.
- import time
- import sys
- import os
- import subprocess
- import platform
- import copy
- from random import randint
- #---VARIABLES---#
- hp1 = 300
- hp2 = 300
- mp1 = 100
- mp2 = 100
- inv1 = ["dig", "sword"]
- inv2 = ["dig", "sword", "steak"]
- status1 = []
- status2 = []
- hp = [hp1, hp2]
- mp = [mp1, mp2]
- inv = [inv1, inv2]
- status = [status1, status2]
- player1 = 0
- player2 = 1
- players = [] #Add the names of all the AI players here and pass their names to the checkuse function.
- ename = "Drugbot"
- AIEXPHP = copy.copy(hp[1])
- togglespeech = 1
- GREETING = "Welcome to Bar Fight %s. After 9 days in development, \n\
- hopefully it will have been worth the wait.\n\
- Use the command \"help\" for a list of commands." % ver
- HISTORY = []
- HELP = [
- "\"use itemname\": Use an item in your inventory.",
- "\"status\": Display the current state of the game.",
- "\"inventory\": Display your inventory.",
- "\"history\": Display the console history.",
- "\"info itemname\": Display information about any item in the game.",
- "\"ts\": Toggle the annoying speech synthesis.",
- "\"quit\": Quit the game."
- ]
- #---UTILITY FUNCTIONS---#
- def clear():
- subprocess.Popen("cls" if platform.system() == "Windows" else "clear", shell=True).wait()
- def hist(x='nil', y=HISTORY, z="TERMINAL HISTORY:"):
- if not x == 'nil':
- y.append(x)
- else:
- print z
- for a in y:
- time.sleep(0.08)
- print "--" + a
- niceprt("Press ENTER to continue. Screen will be cleared.", 0, 0, 1, 0.03)
- clear()
- def speak(x):
- subprocess.Popen("espeak \"%s\"" % x, stderr=subprocess.PIPE, shell=True)
- def niceprt(x, inp=1, clr=1, log=0, sleeptime=0.05, opt='CONTINUE->'):
- if togglespeech == 1:
- speak(x)
- for a in x:
- sys.stdout.write( '%s' % a )
- sys.stdout.flush()
- time.sleep(sleeptime)
- print " "
- if inp == 0:
- raw_input(opt)
- if log == 0:
- hist(x)
- if clr == 0:
- clear()
- def findi(f, seq):
- for item in seq:
- if f == item:
- return item
- def leave():
- niceprt("Do you really want to quit?", 1, 1, 1)
- if raw_input("y/N? ").lower() == "y":
- niceprt("It was fun having you!", 0, 1, 0, 0.04, 'Goodbye...')
- quit()
- else:
- niceprt("The fun never ends!", 1, 1, 1)
- term()
- def confuzzled_prompt(x):
- a = [
- "I'm not sure what \'%s\' means!",
- "I'm sorry, but \'%s\' confuzzles me.",
- "404: \'%s\' not found.",
- "There is no \'%s\' here, only Gankutsuou.",
- "I'm sorry, Dave, I'm afraid I can't do \'%s\'.",
- "I'm not sure why you would think there would be a \'%s\' command.",
- "AH! You think you're doing some damage!? 2 plus 2 equals \'%s\'.",
- "This is my original character \'%s\', do not steal.",
- "What is the DEAL with \'%s\'!?",
- "If it don't make \'%s\', it don't make cents.",
- "That wasn't very \'%s\' of you.",
- "I told you about the \'%s\' dog, I warned you.",
- "I can do no \'%s\', for I do not know what it is...",
- "You told me you would take me to our \'%s\' place, but you never did...",
- "It is pitch black. You are likely to be eaten by a \'%s\'.",
- "Does a set of all sets contain \'%s\'?",
- "Omg \'%s\' is so moe!"
- ]
- b = [
- "No input detected.",
- "Input missing.",
- "I cannot process your request without input.",
- "I need input, first.",
- "I can't do anything without input.",
- "Please provide input.",
- "Error: Input not detected.",
- "No input discovered.",
- "That is too little input for processing."
- ]
- if len(x) == x.count(" "):
- niceprt(b[randint(0, len(b) - 1)], 1, 1, 1, 0.03)
- else:
- niceprt(a[randint(0, len(a) - 1)] % x, 1, 1, 0, 0.03)
- term()
- def term():
- a = raw_input("PROMPT-> ").lower()
- if a == "history":
- clear()
- hist()
- term()
- elif a == "help":
- clear()
- hist('nil', HELP, "HELP SCREEN/COMMANDS")
- term()
- elif a == "status":
- clear()
- niceprt("GAME STATUS:")
- print("-- Drugbot has %s HP" % hp[1])
- print("-- You have %s HP" % hp[0])
- print("-- Drugbot has %s MP" % mp[1])
- print("-- You have %s MP" % mp[0])
- print("-- Your Items: %s" % inv[0])
- niceprt("Press ENTER to continue.", 0, 0)
- term()
- elif a == "quit":
- leave()
- elif a == "ts":
- global togglespeech
- if togglespeech == 0:
- togglespeech = 1
- else: togglespeech = 0
- niceprt("Speech synthesis toggled.", 1, 1, 0, 0.01)
- term()
- elif a == "inventory":
- niceprt("Your current inventory: ", 1, 1, 1)
- for name in inv[0]:
- print("-- {!s}".format(name.title()))
- term()
- elif a[:3] == "say":
- niceprt(a.upper()[4:])
- term()
- elif a[:3] == "use":
- checkuse(a[4:], player1)
- elif a[:4] == "info":
- if a[5:] in iteminfo:
- niceprt(iteminfo[a[5:]])
- else: niceprt("No such item in vocabulary.")
- term()
- elif a == "pass":
- pass
- elif a == "sodoku":
- hp[0] = 0
- else:
- confuzzled_prompt(a)
- def announceuse(x, player):
- niceprt("{!s} used {!s}.".format("You" if player is player1 else ename, x.title()))
- def otherplayer(player):
- if player is 1:
- return 0
- elif player is 0:
- return 1
- def statcheck(stat, targ, prt='nil'):
- if stat < targ:
- if prt is not 'nil':
- niceprt(prt)
- return 1
- else: return 0
- def miss(player, ext1, ext2):
- MISS = randint(0, ext1)
- if player == 0:
- if MISS < ext2:
- niceprt("But you missed.")
- return 1
- else:
- if MISS < ext2:
- niceprt("But he missed.")
- return 1
- #---ITEMS---#
- #Yes, I know this looks redundant. Yes, I know exactly what kind of functions I could write
- #to make this less redundant. No, I don't care. This is fine IMO. And hard-coding all this
- #gives me a little more freedom to make each item do specific things.
- def rawitem(player):
- name = "rawitem"
- announceuse(name, player)
- hp[otherplayer(player)] -= 50
- inv[player].remove(name)
- niceprt("{!s} lost 50 HP.".format(ename if player is player1 else "You"))
- def sword(player):
- name = "sword"
- rand = randint(20, 40)
- announceuse(name, player)
- if miss(player, 10, 4) == 1:
- pass
- else:
- hp[otherplayer(player)] -= rand
- niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
- def katana(player):
- name = "katana"
- rand = randint(30, 50)
- announceuse(name, player)
- if miss(player, 10, 2) == 1:
- pass
- else:
- hp[otherplayer(player)] -= rand
- niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
- def magicdart(player):
- if player == 1 and statcheck(mp[1], 20) == 1:
- drugbot()
- pass
- elif player == 0 and statcheck(mp[0], 20, "You don't have enough MP") == 1:
- pass
- else:
- name = "magic dart"
- rand = randint(40, 70)
- announceuse(name, player)
- if miss(player, 20, 10) == 1:
- pass
- else:
- hp[otherplayer(player)] -= rand
- niceprt("{!s} lost {!s} HP.".format(ename if player is player1 else "You", rand))
- mp[player] -= 20
- inv[player].remove(name)
- niceprt("{!s} lost {!s} MP.".format("You" if player is player1 else ename, 20))
- def steak(player):
- name = "steak"
- announceuse(name, player)
- hp[player] += 20
- inv[player].remove(name)
- niceprt("{!s} gained 20 HP.".format("You" if player is player1 else ename))
- def pocky(player):
- name = "pocky"
- announceuse(name, player)
- hp[player] += 10
- inv[player].remove(name)
- niceprt("{!s} gained 10 HP.".format("You" if player is player1 else ename))
- def manapot(player):
- name = "mana pot"
- announceuse(name, player)
- mp[player] += 50
- inv[player].remove(name)
- niceprt("{!s} gained 50 MP.".format("You" if player is player1 else ename))
- def dig(player):
- name = "dig"
- il = ["rawitem", "magic dart", "steak", "katana", "pocky", "mana pot"] #Add items to this list if you want the player to get them with "dig".
- infitems = ["katana"] #Put items with infinite uses here, so they don't clog the inventory by staying there forever.
- rand1 = randint(0, 20)
- rand2 = il[randint(0, len(il) - 1)]
- announceuse(name, player)
- if rand1 < 5:
- niceprt("{!s} didn't find anything, though.".format("You" if player is player1 else ename))
- else:
- niceprt("{!s} found a {!s}".format("You" if player is player1 else ename, rand2.title()))
- if rand2 == findi(rand2, infitems) and findi(rand2, inv[player]):
- niceprt("But it's not nessisary for {!s} to have more than one.".format("You" if player is player1 else ename))
- else:
- inv[player].append(rand2)
- #Not items but item-specific stuff.
- def checkuse(x, player):
- if findi(x, inv[player]):
- use(x, player)
- else:
- if player == player1:
- niceprt("You don't have that item.")
- term()
- else: niceprt("ERROR: AI tried to use item it doesn't have.")
- def use(x, player):
- itemlist[x](player)
- itemlist = { #shit, it's better than elif elif elif. This is what I call "variety".
- "dig":dig,
- "sword":sword,
- "rawitem":rawitem,
- "magic dart":magicdart,
- "steak":steak,
- "pocky":pocky,
- "katana":katana,
- "mana pot":manapot
- }
- iteminfo = {
- "dig":"If you're low on items, dig around for some more. Infinite uses.",
- "sword":"Deal 20 to 40 HP to that land lubber. Infinite uses.",
- "rawitem":"Genuine item, raw. Deals 50 HP.",
- "magic dart":"If you're willing to give up 20 MP, deals 40 to 70 HP.",
- "steak":"Steak made of real artificial chicken. Heals 20 HP.",
- "pocky":"Raw sewage commonly consumed by beached whales. Heals 10 HP.",
- "katana":"Deals 30 to 50 HP. Contradicting real life, it never breaks.",
- "mana pot":"Gives 50 MP. That's it."
- }
- #---DRUGBOT HIMSELF---#
- def filteritems(lst, x=0):
- tempinv = []
- for it1 in inv[1]:
- if it1 == findi(it1, lst):
- tempinv.append(it1)
- return tempinv
- def robotattack(): #I appear today to announce my retirement.
- atkitems = ["magic dart", "rawitem", "sword", "katana", "mana pot"]
- tempinv = filteritems(atkitems)
- randinv = tempinv[randint(0, len(tempinv) - 1)]
- if tempinv == []:
- checkuse("dig", player2)
- elif randint(0, 20) >= 16:
- checkuse("dig", player2)
- else:
- checkuse(randinv, player2)
- def drugbot():
- weed = ["steak", "pocky"]
- tempinv = filteritems(weed)
- if tempinv == []:
- if randint(0, 50) <= 20:
- checkuse("dig", player2)
- else:
- robotattack()
- else:
- randinv = tempinv[randint(0, len(tempinv) - 1)]
- if hp[1] <= AIEXPHP/2:
- if randint(0, 30) <= 10:
- robotattack()
- else:
- checkuse(randinv, player2)
- elif hp[1] <= AIEXPHP/3:
- checkuse(randinv, player2)
- else:
- robotattack()
- mainloop()
- #---GAME LOGIC---#
- def this_will_be_the_sixth_time_we_have_destroyed_it_and_we_have_become_exceedingly_efficient_at_it():
- global HISTORY
- hp[0] = 500
- hp[1] = 500
- mp[0] = 100
- mp[1] = 100
- inv[0] = ["dig", "sword"]
- inv[1] = ["dig", "sword", "steak"]
- status[0] = []
- status[1] = []
- HISTORY=[]
- clear()
- niceprt("New game initiated.")
- mainloop()
- def playagain():
- niceprt("Would you like to play again?", 1, 1, 1)
- a = raw_input("y/n? ->").lower()
- if a == "y":
- this_will_be_the_sixth_time_we_have_destroyed_it_and_we_have_become_exceedingly_efficient_at_it()
- elif a == "n":
- niceprt("That was a great game. Goodbye.", 0)
- quit()
- else:
- niceprt("I'm sorry, I didn't quite get that.", 1, 1, 1)
- playagain()
- def deathcheck():
- if hp[0] <= 0:
- niceprt("You have lost.")
- playagain()
- elif hp[1] <= 0:
- niceprt("You have won!")
- playagain()
- def mainloop():
- deathcheck()
- term()
- deathcheck()
- drugbot()
- niceprt(GREETING)
- mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement