simple module that holds the needed classes to make an adventure game plus a ascii anamation class for ascii art
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | ## bctg.py
## by andrew wayne teesdale jr.
class LL:
def __init__(self, ll, name):
import random
self.randnum=random.choice(['True', 'False'])
self.msg=random.choice(['I dont know.', 'Oh, Yes '+ll, 'I think '+name+' knows.'])
def say_to(self, msg):
## msging system
print msg
def fight_thing(self, moolaugh, things):
import random
bg=random.choice(things)
print 'You see a '+bg+' It attacks you'
if self.randnum == 'True':
fmsg='Died!'
else:
fmsg='Killed it'
moolaugh=moolaugh+random.randint(1, 40)
print 'You '+fmsg
def reply_to(self, msg):
print 'The person says:'
print msg
## player class
## is related
## to monster
## class.
class Player(LL):
def __init__(self, name1):
LL.__init__(self, "None", "None")
self.name=name1
self.money=0
self.weapons=['sword']
self.keys=[]
def say(self, s):
print 'You say:'
self.say_to(s)
def fight(self):
self.fight_thing(self.money)
def pickup(self, thing):
things=[['coin', 'ruby'], ['key'], ['shield', 'bow', 'arrows']]
if thing in things[2]:
self.weapons.append(thing)
print 'You got a '+thing
elif thing in things[0]:
if thing == 'coin':
self.money=self.money+1
print 'you got a '+thing
elif thing == 'ruby':
self.money=self.money*2
else:
print "weird not a kind of currency I've seen before."
elif thing in things[1]:
print 'cool a key.'
self.keys.append(thing)
else:
print 'what is it!'
print 'ill keep it'
self.weapons.append(thing)
def sell(self, price, thing):
self.weapons.remove(thing)
self.money=self.money+price
def show_stat(self):
self.say(self.money)
self.say(self.weapons)
## Npc class is a subclass of LL
## It is the non player class
class Npc(LL):
def __init__(self, info, keyto, kinfo, list):
LL.__init__(self, "None", "None")
self.info=info
self.keyto=keyto
self.kinfo=kinfo
self.list=list
def talk(self):
import random
print 'my names '+random.choice(['Neec', 'Nal', 'Zeenosx', 'Teelal', 'Meron', 'Peelal'])
if self.keyto in self.list:
self.say_to('ooh could i have that')
if raw_input('y-n?]') == 'y':
self.list.remove(self.keyto)
self.say_to('Thankyou!')
self.say_to('Hey by the way')
self.say_to(self.kinfo)
else:
self.say_to('Ok-Ok! Fine keep it')
else:
self.say_to(self.info)
class Door:
def __init__(self, key, lst):
self.key = key
self.list = lst
self.exst = '0'
def check(self):
if self.key in self.list:
self.list.remove(self.key)
self.exst="1"
else:
print "you don't have the right key for this door"
## check if key is in inventory
if self.exst == '1':
return True
else:
return False
## Shell parser syntax
import time
class ascii:
def __init__(self):
self.version=1.0
def clear(self):
print "\n"*1000
def pause(self, i):
time.sleep(i)
def roll_film(self, film, repi=1):
for k in range(1, repi):
for j in film:
print j
self.pause(1)
self.clear()
self.clear()
def example(self):
listf=['. ', ' . ', ' .']
self.roll_film(listf, 100)
def create_film(self, film):
return film
def prompt():
return raw_input('?]')
def test_game_funcs():
print 'Name:'
player=Player(prompt())
player.fight()
player.pickup('key')
player.say('hello my name is bobby the busybody')
npc=Npc('I know you', 'sword', 'I know evrybody', player.weapons)
npc.talk()
door=Door('key', player.keys)
print door.check()
def small_text_game():
print "name please:"
if __name__ == "__main__":
test_game_funcs()
|
you would want to use this to make a text game
Tags: base_class, text_game