The Challenge: -Develop a turn based combat system that implements the following choices that occur during the player's turns:
--Fight (Straight Damage)
--Item (Use an object from a choice of your design)
--Ability (Use an ability from a choice of your design)
--Run (Flee the battle)
Well, I don't like that that is the only Python entry.
Have this one.
from random import randint
from time import sleep
SPELLBOOK = [{"DICH SNAKE RETRACTION":18, "MASTER BLASTER":16},
{"DIGITAL IMAGE POST ATTEMPT":20, "POWERFUL BBCODE":19},
{"BEAUTIFUL COOING":14, "GENTLE RUBBING INTO THAT GOODNIGHT":21, "RECITATION OF HIGHSCHOOL SPIRIT SONG":12}]
ITEMLIST = [{"Handful of Dust":6, "Pawful of Dirt":9},
{"Mudden Idol":6, "Quigsor Pindleweign":9},
{"Open Courseware PDF notes":10, "Topical caffeine mixture, 10%":8, "A bloody mary cocktail sticker":7}]
YOUR_NAME = raw_input("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nWhat is your name?\n>> ")
PLAY = 1
class Person:
def __init__(self, NAME, HP, MP, SPELLBOOK, ITEMLIST):
self.name = NAME
self.hp = HP
self.mp = MP
self.spells = SPELLBOOK
self.items = ITEMLIST
def Fight(self):
#How uncivilized.
hit = randint(5,14)
print "\n"*2+ "%s whacks a bit, blooming into a petit mort d'%d droplets" % (self.name, hit)
return hit
def Magic(self, choice):
damage = self.spells[choice]
self.mp -= 10
print "\n"*2+ "%s uses %s for %d damage!" % (self.name, choice, damage)
return damage
def Item(self):
Item = self.items.keys()[randint(0,len(self.items)-1)]
cure = self.items[Item]
self.hp = self.hp + cure
print "\n"*2+ "%s takes in the curious %s, yet looks %d radians brighter!" % (self.name, Item, cure)
return 0
def Run(self):
print "\n"*2+ "The cowardice of %s emboldens his opponent!" % (self.name)
return -17
def Upkeep(self, dmg):
self.hp = self.hp - dmg
if self.hp <= 0:
print "OH DEAR! %s HAS FAILED!" % (self.name)
def Menu():
print "[F][I][R][M]. DECIDE."
choice = raw_input(">>")
if choice.lower() == "r":
return PLAYER.Run()
elif choice.lower() == "f":
return PLAYER.Fight()
elif choice.lower() == "m":
i = 1
for spell in PLAYER.spells:
print " %d) %s" % (i, spell)
i = i + 1
choice = int(raw_input("Which number spell do you choose? \n>>"))
if (choice == 1) or (choice == 2):
choice -= 1
return PLAYER.Magic(PLAYER.spells.keys()[choice])
elif choice.lower() == "i":
return PLAYER.Item()
else:
print "I believe you've gone a bit hax'd!\nYour dalliance only strengthens your opponent!"
return 0
def Computer():
choices = ["r", "f", "m", "i"]
choice = choices[randint(0,3)]
if choice.lower() == "r":
return OPPONENT.Run()
elif choice.lower() == "f":
return OPPONENT.Fight()
elif choice.lower() == "m":
return OPPONENT.Magic(OPPONENT.spells.keys()[randint(0,len(OPPONENT.spells)-1)])
elif choice.lower() == "i":
return OPPONENT.Item()
print "\n"*5
print " ", "-"*35
print " PROGRPG"
print " ", "-"*35
OPPONENT = Person(NAMES[randint(0,6)],randint(75,95),randint(75,95),SPELLBOOK[randint(0,len(SPELLBOOK)-1)],ITEMLIST[randint(0,len(SPELLBOOK)-1)])
PLAYER = Person(YOUR_NAME, 75, 75, SPELLBOOK[randint(0,len(SPELLBOOK)-1)], ITEMLIST[randint(0, len(SPELLBOOK)-1)])
print "\n"*5
print """%s has come upon you, as you lie in repose! Arise, my Rubenesque champion!
Let this not be that hour during which you falter, nor fall, nor find your soul weak!
Justice flows through you, and many meditations complete you- now find the strength inside yourself to complete this!""" % (OPPONENT.name)
print "Your spell book has many pages- FEAST!"
print "\n" + "---------------------------------------"
for spell in PLAYER.spells.keys():
print " | " + spell
print "---------------------------------------"
print "\n"*2 + "---------------------------------------"
print "Your bag bursts with things- OBSERVE!"
print "---------------------------------------"
for item in PLAYER.items.keys():
print " || " + item
print "---------------------------------------"
sleep(2)
while PLAY == 1:
print "You're health is %d, and you've got %d anii. You're opponent looks to have %d health." % (PLAYER.hp, PLAYER.mp, OPPONENT.hp-8)
OPPONENT.Upkeep(Menu())
if OPPONENT.hp <= 0:
break
PLAYER.Upkeep(Computer())
if PLAYER.hp <= 0:
break
print "\n"*4