log
This commit is contained in:
parent
d5d80345fc
commit
e567f2d75b
45
rougelike.py
45
rougelike.py
@ -32,7 +32,7 @@ class World(Grid):
|
||||
self.bodies = []
|
||||
self.behavior = []
|
||||
|
||||
class Spirit():
|
||||
class Behaviour():
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
self.body = None
|
||||
@ -52,15 +52,16 @@ class Spirit():
|
||||
def message(self, msg):
|
||||
pass
|
||||
|
||||
class Player(Spirit):
|
||||
class Player(Behaviour):
|
||||
def __init__(self, name):
|
||||
super().__init__(name)
|
||||
self.msgbuffer = cl.deque([], 200)
|
||||
self.messaged = False
|
||||
self.messaged_last = False
|
||||
|
||||
def message(self, msg):
|
||||
if len(self.msgbuffer) > 0 and msg == self.msgbuffer[0][1]:
|
||||
self.msgbuffer.appendleft((self.msgbuffer.pop()[0] + 1, msg))
|
||||
if len(self.msgbuffer) > 0 and msg == self.msgbuffer[0][1] and self.messaged_last:
|
||||
self.msgbuffer.appendleft((self.msgbuffer.popleft()[0] + 1, msg))
|
||||
else:
|
||||
self.msgbuffer.appendleft((1, msg))
|
||||
self.messaged = True
|
||||
@ -73,7 +74,7 @@ class Player(Spirit):
|
||||
|
||||
self.world.window.erase()
|
||||
|
||||
# draw interface
|
||||
# draw interface you
|
||||
for x in range(0, self.world.width):
|
||||
for y in range(0, self.world.height):
|
||||
if visibility.get(x, y):
|
||||
@ -81,12 +82,15 @@ class Player(Spirit):
|
||||
for body in self.world.bodies:
|
||||
if visibility.get(body.x, body.y):
|
||||
body.draw()
|
||||
if not len(self.msgbuffer) == 0 and self.messaged:
|
||||
if self.messaged:
|
||||
if self.msgbuffer[0][0] == 1:
|
||||
self.world.window.addstr(self.world.height + 1, 0, self.msgbuffer[0][1])
|
||||
else:
|
||||
self.world.window.addstr(self.world.height + 1, 0, self.msgbuffer[0][1] + " (x" + str(self.msgbuffer[0][0]) + ")")
|
||||
self.messaged = False
|
||||
self.messaged_last = True
|
||||
else:
|
||||
self.messaged_last = False
|
||||
|
||||
self.world.window.refresh()
|
||||
|
||||
@ -119,7 +123,7 @@ class Player(Spirit):
|
||||
self.world.run = False
|
||||
# case _: self.world.message(key)
|
||||
|
||||
class Drunkard(Spirit):
|
||||
class Drunkard(Behaviour):
|
||||
|
||||
def behave(self):
|
||||
while True:
|
||||
@ -190,6 +194,33 @@ class Body():
|
||||
def draw(self):
|
||||
self.world.window.addch(self.y, self.x, self.appearence)
|
||||
|
||||
class Conversation(list):
|
||||
def __init__(self, title, description):
|
||||
self.title = title
|
||||
self.description = description
|
||||
|
||||
def run(self):
|
||||
# rendering code goes here
|
||||
pass
|
||||
|
||||
class Response():
|
||||
def __init__(self, name, text, target=None, prerequisite=None, function=None):
|
||||
self.name = name
|
||||
self.text = text
|
||||
self.target = target
|
||||
self.function = function
|
||||
|
||||
def respond(self, title, description):
|
||||
# rendering code goes here
|
||||
if function:
|
||||
function()
|
||||
if target:
|
||||
target.run()
|
||||
|
||||
bum_conversation = Conversation("Conversing With a Drunkard", "A foul-smelling drunkard waves to and fro, trying to form words. His tattered clothes are brown with filth.")
|
||||
bum_conversation.append(Response("Hello? Is everything all right?", "Hargl... hurgl...", target=bum_conversation))
|
||||
bum_conversation.append(Response("I will take my leave, good sir.", "..."))
|
||||
|
||||
p = Player("you")
|
||||
|
||||
pb = Body("yourself", '@', "an unremarkable person", c.COLOR_WHITE)
|
||||
|
Loading…
Reference in New Issue
Block a user