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