From 3d2adcf17b1860b4ac2d70a6365afdcdfaec9393 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 10 Jan 2021 16:02:51 -0500 Subject: [PATCH 01/80] Create readme.md --- Adventure Game/readme.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Adventure Game/readme.md diff --git a/Adventure Game/readme.md b/Adventure Game/readme.md new file mode 100644 index 0000000..e69de29 -- 2.43.0 From 04d7388eb473356f41145fcfe87793c90a139d64 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Jan 2021 00:39:47 -0500 Subject: [PATCH 02/80] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index fd20fdd..11e2a47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *.pyc +.idea \ No newline at end of file -- 2.43.0 From 5e30cf1fb7041f5858009c413f8cbcd7a9d6dcce Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Jan 2021 00:40:08 -0500 Subject: [PATCH 03/80] Create a VERY BASIC main.py from example code in npyscreen (placeholder) --- Adventure Game/adventure_game/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 Adventure Game/adventure_game/main.py diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py new file mode 100644 index 0000000..96bc838 --- /dev/null +++ b/Adventure Game/adventure_game/main.py @@ -0,0 +1,24 @@ +import npyscreen + + +# This application class serves as a wrapper for the initialization of curses +# and also manages the actual forms of the application + +class MyTestApp(npyscreen.NPSAppManaged): + def onStart(self): + self.registerForm("MAIN", MainForm()) + + +# This form class defines the display that will be presented to the user. + +class MainForm(npyscreen.Form): + def create(self): + self.add(npyscreen.TitleText, name="Text:", value="Hellow World!") + + def afterEditing(self): + self.parentApp.setNextForm(None) + + +if __name__ == '__main__': + TA = MyTestApp() + TA.run() -- 2.43.0 From 375fabee71a7e3782ac648c2d1b6f9158c87a084 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 20 Jan 2021 00:40:11 -0500 Subject: [PATCH 04/80] Create requirements.txt --- Adventure Game/requirements.txt | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Adventure Game/requirements.txt diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt new file mode 100644 index 0000000..f4357d5 --- /dev/null +++ b/Adventure Game/requirements.txt @@ -0,0 +1,2 @@ +npyscreen==4.10.5 +windows-curses==2.2.0 # Only for those using windows, curses is standard on python for BSD and GNU/Linux -- 2.43.0 From bdba68ecb0856969db199e61c5a469d34c3159ba Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Thu, 21 Jan 2021 19:00:27 -0500 Subject: [PATCH 05/80] Test some more curses --- Adventure Game/adventure_game/main.py | 7 +--- Adventure Game/adventure_game/test_curses.py | 40 ++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 Adventure Game/adventure_game/test_curses.py diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 96bc838..265113f 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,6 +1,5 @@ import npyscreen - # This application class serves as a wrapper for the initialization of curses # and also manages the actual forms of the application @@ -8,17 +7,15 @@ class MyTestApp(npyscreen.NPSAppManaged): def onStart(self): self.registerForm("MAIN", MainForm()) - # This form class defines the display that will be presented to the user. class MainForm(npyscreen.Form): def create(self): - self.add(npyscreen.TitleText, name="Text:", value="Hellow World!") + self.add(npyscreen.TitleText, name = "Text:", value= "Hellow World!" ) def afterEditing(self): self.parentApp.setNextForm(None) - if __name__ == '__main__': TA = MyTestApp() - TA.run() + TA.run() \ No newline at end of file diff --git a/Adventure Game/adventure_game/test_curses.py b/Adventure Game/adventure_game/test_curses.py new file mode 100644 index 0000000..a02daaf --- /dev/null +++ b/Adventure Game/adventure_game/test_curses.py @@ -0,0 +1,40 @@ +import curses + +# The `screen` is a window that acts as the master window +# that takes up the whole screen. Other windows created +# later will get painted on to the `screen` window. +screen = curses.initscr() + +# lines, columns, start line, start column +my_window = curses.newwin(15, 20, 0, 0) + +# Long strings will wrap to the next line automatically +# to stay within the window +my_window.addstr(4, 4, "Hello from 4,4") +my_window.addstr(5, 15, "Hello from 5,15 with a long string") + +# Print the window to the screen +my_window.refresh() +curses.napms(2000) + +# Clear the screen, clearing my_window contents that were printed to screen +# my_window will retain its contents until my_window.clear() is called. +screen.clear() +screen.refresh() + +# Move the window and put it back on screen +# If we didn't clear the screen before doing this, +# the original window contents would remain on the screen +# and we would see the window text twice. +my_window.mvwin(10, 10) +my_window.refresh() +curses.napms(1000) + +# Clear the window and redraw over the current window space +# This does not require clearing the whole screen, because the window +# has not moved position. +my_window.clear() +my_window.refresh() +curses.napms(1000) + +curses.endwin() \ No newline at end of file -- 2.43.0 From 37524876e58452a85024b08e84bed6f0bdeafd2d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 3 Feb 2021 17:27:22 -0500 Subject: [PATCH 06/80] Clean up adventure-game --- 4/4.10/4.10.1/main.py | 0 Adventure Game/Makefile | 7 +++++++ Adventure Game/requirements.txt | 4 ++-- 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 4/4.10/4.10.1/main.py create mode 100644 Adventure Game/Makefile diff --git a/4/4.10/4.10.1/main.py b/4/4.10/4.10.1/main.py new file mode 100644 index 0000000..e69de29 diff --git a/Adventure Game/Makefile b/Adventure Game/Makefile new file mode 100644 index 0000000..a15a119 --- /dev/null +++ b/Adventure Game/Makefile @@ -0,0 +1,7 @@ +init: + pip install -r requirements.txt + +test: + py.test tests + +.PHONY: init test \ No newline at end of file diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index f4357d5..6493b8a 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1,2 +1,2 @@ -npyscreen==4.10.5 -windows-curses==2.2.0 # Only for those using windows, curses is standard on python for BSD and GNU/Linux +# Blessed handles our terminal "graphics" +blessed==1.17.12 \ No newline at end of file -- 2.43.0 From 298e5abdbe0c6f749dad438e89c967f2613c2392 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 5 Feb 2021 11:45:49 -0500 Subject: [PATCH 07/80] idk --- Adventure Game/adventure_game/main.py | 44 +++++++++++++------- Adventure Game/adventure_game/test_curses.py | 40 ------------------ 2 files changed, 29 insertions(+), 55 deletions(-) delete mode 100644 Adventure Game/adventure_game/test_curses.py diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 265113f..48bbc4e 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,21 +1,35 @@ -import npyscreen +# std imports +from math import floor -# This application class serves as a wrapper for the initialization of curses -# and also manages the actual forms of the application +# local +from blessed import Terminal -class MyTestApp(npyscreen.NPSAppManaged): - def onStart(self): - self.registerForm("MAIN", MainForm()) -# This form class defines the display that will be presented to the user. +def roundxy(x, y): + return int(floor(x)), int(floor(y)) -class MainForm(npyscreen.Form): - def create(self): - self.add(npyscreen.TitleText, name = "Text:", value= "Hellow World!" ) - def afterEditing(self): - self.parentApp.setNextForm(None) +term = Terminal() -if __name__ == '__main__': - TA = MyTestApp() - TA.run() \ No newline at end of file +x, y, xs, ys = 2, 2, 0.4, 0.3 +with term.cbreak(), term.hidden_cursor(): + # clear the screen + print(term.home + term.black_on_olivedrab4 + term.clear) + + # loop every 20ms + while term.inkey(timeout=0.02) != 'q': + # erase, + txt_erase = term.move_xy(*roundxy(x, y)) + ' ' + + # bounce, + if x >= (term.width - 1) or x <= 0: + xs *= -1 + if y >= term.height or y <= 0: + ys *= -1 + + # move, + x, y = x + xs, y + ys + + # draw ! + txt_ball = term.move_xy(*roundxy(x, y)) + '█' + print(txt_erase + txt_ball, end='', flush=True) diff --git a/Adventure Game/adventure_game/test_curses.py b/Adventure Game/adventure_game/test_curses.py deleted file mode 100644 index a02daaf..0000000 --- a/Adventure Game/adventure_game/test_curses.py +++ /dev/null @@ -1,40 +0,0 @@ -import curses - -# The `screen` is a window that acts as the master window -# that takes up the whole screen. Other windows created -# later will get painted on to the `screen` window. -screen = curses.initscr() - -# lines, columns, start line, start column -my_window = curses.newwin(15, 20, 0, 0) - -# Long strings will wrap to the next line automatically -# to stay within the window -my_window.addstr(4, 4, "Hello from 4,4") -my_window.addstr(5, 15, "Hello from 5,15 with a long string") - -# Print the window to the screen -my_window.refresh() -curses.napms(2000) - -# Clear the screen, clearing my_window contents that were printed to screen -# my_window will retain its contents until my_window.clear() is called. -screen.clear() -screen.refresh() - -# Move the window and put it back on screen -# If we didn't clear the screen before doing this, -# the original window contents would remain on the screen -# and we would see the window text twice. -my_window.mvwin(10, 10) -my_window.refresh() -curses.napms(1000) - -# Clear the window and redraw over the current window space -# This does not require clearing the whole screen, because the window -# has not moved position. -my_window.clear() -my_window.refresh() -curses.napms(1000) - -curses.endwin() \ No newline at end of file -- 2.43.0 From ed4b5abd247da87189fd27ac01dc19e92422793e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 6 Feb 2021 00:19:16 -0500 Subject: [PATCH 08/80] This is awful but it shows some prototpe stuff --- Adventure Game/.gitignore | 1 + Adventure Game/adventure_game/main.py | 61 +++++++++++++++------------ Adventure Game/adventure_game/test.py | 9 ++++ 3 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 Adventure Game/.gitignore create mode 100644 Adventure Game/adventure_game/test.py diff --git a/Adventure Game/.gitignore b/Adventure Game/.gitignore new file mode 100644 index 0000000..5ceb386 --- /dev/null +++ b/Adventure Game/.gitignore @@ -0,0 +1 @@ +venv diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 48bbc4e..f9c34fb 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,35 +1,40 @@ -# std imports -from math import floor - -# local from blessed import Terminal +class Graphics: + def __init__(self): + self.bottom_left_corner = u"└" + self.bottom_right_corner = u"┘" + self.top_left_corner = u"┌" + self.top_right_corner = u"┐" + self.border_horizontal = u"─" + self.border_vertical = u"│" -def roundxy(x, y): - return int(floor(x)), int(floor(y)) +class Window: + def __init__(self, term, height, width, xpos, ypos, title=None): + self.term = term + self.title = title -term = Terminal() + self.height = height + self.width = width + self.xpos = xpos + self.ypos = ypos + + def draw_borders(self): + # Print the top + print( + self.term.move_xy(self.xpos, self.ypos) + + u"┌" + + u"─" * (self.width - 2) + + u"┐" + ) -x, y, xs, ys = 2, 2, 0.4, 0.3 -with term.cbreak(), term.hidden_cursor(): - # clear the screen - print(term.home + term.black_on_olivedrab4 + term.clear) + # Print the middle + # We exclude the top and bottom rows since we'll draw them with other chars + for dx in range (1, self.height - 1): + print(self.term.move_xy(self.xpos + dx, self.ypos) + u'│') + print(self.term.move_xy(self.xpos + dx, self.ypos + self.width - 1) + u'│') - # loop every 20ms - while term.inkey(timeout=0.02) != 'q': - # erase, - txt_erase = term.move_xy(*roundxy(x, y)) + ' ' - - # bounce, - if x >= (term.width - 1) or x <= 0: - xs *= -1 - if y >= term.height or y <= 0: - ys *= -1 - - # move, - x, y = x + xs, y + ys - - # draw ! - txt_ball = term.move_xy(*roundxy(x, y)) + '█' - print(txt_erase + txt_ball, end='', flush=True) +terminal = Terminal() +my_window = Window(terminal, 4, 20, 10, 10) +my_window.draw_borders() \ No newline at end of file diff --git a/Adventure Game/adventure_game/test.py b/Adventure Game/adventure_game/test.py new file mode 100644 index 0000000..11bdcef --- /dev/null +++ b/Adventure Game/adventure_game/test.py @@ -0,0 +1,9 @@ +from blessed import Terminal +import time + +term = Terminal() + +for x in range(10): + for y in range(10): + print(term.move_xy(x, y) + '*') + time.sleep(0.1) \ No newline at end of file -- 2.43.0 From a03bfaf3dcc9c67cdee307f7988e7f35b467ab28 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 14 Feb 2021 15:47:09 -0500 Subject: [PATCH 09/80] Fix up curses stuff --- Adventure Game/adventure_game/curses_test.py | 92 ++++++++++++++++ Adventure Game/adventure_game/dashing_test.py | 17 +++ Adventure Game/adventure_game/main.py | 101 ++++++++++++------ 3 files changed, 176 insertions(+), 34 deletions(-) create mode 100644 Adventure Game/adventure_game/curses_test.py create mode 100644 Adventure Game/adventure_game/dashing_test.py diff --git a/Adventure Game/adventure_game/curses_test.py b/Adventure Game/adventure_game/curses_test.py new file mode 100644 index 0000000..d316fcd --- /dev/null +++ b/Adventure Game/adventure_game/curses_test.py @@ -0,0 +1,92 @@ +import sys,os +import curses + +def draw_menu(stdscr): + k = 0 + cursor_x = 0 + cursor_y = 0 + + # Clear and refresh the screen for a blank canvas + stdscr.clear() + stdscr.refresh() + + # Start colors in curses + curses.start_color() + curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + + # Loop where k is the last character pressed + while (k != ord('q')): + + # Initialization + stdscr.clear() + height, width = stdscr.getmaxyx() + + if k == curses.KEY_DOWN: + cursor_y = cursor_y + 1 + elif k == curses.KEY_UP: + cursor_y = cursor_y - 1 + elif k == curses.KEY_RIGHT: + cursor_x = cursor_x + 1 + elif k == curses.KEY_LEFT: + cursor_x = cursor_x - 1 + + cursor_x = max(0, cursor_x) + cursor_x = min(width-1, cursor_x) + + cursor_y = max(0, cursor_y) + cursor_y = min(height-1, cursor_y) + + # Declaration of strings + title = "Curses example"[:width-1] + subtitle = "Written by Clay McLeod"[:width-1] + keystr = "Last key pressed: {}".format(k)[:width-1] + statusbarstr = "Press 'q' to exit | STATUS BAR | Pos: {}, {}".format(cursor_x, cursor_y) + if k == 0: + keystr = "No key press detected..."[:width-1] + + # Centering calculations + start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) + start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) + start_x_keystr = int((width // 2) - (len(keystr) // 2) - len(keystr) % 2) + start_y = int((height // 2) - 2) + + # Rendering some text + whstr = "Width: {}, Height: {}".format(width, height) + stdscr.addstr(0, 0, whstr, curses.color_pair(1)) + + # Render status bar + stdscr.attron(curses.color_pair(3)) + stdscr.addstr(height-1, 0, statusbarstr) + stdscr.addstr(height-1, len(statusbarstr), " " * (width - len(statusbarstr) - 1)) + stdscr.attroff(curses.color_pair(3)) + + # Turning on attributes for title + stdscr.attron(curses.color_pair(2)) + stdscr.attron(curses.A_BOLD) + + # Rendering title + stdscr.addstr(start_y, start_x_title, title) + + # Turning off attributes for title + stdscr.attroff(curses.color_pair(2)) + stdscr.attroff(curses.A_BOLD) + + # Print rest of text + stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) + stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) + stdscr.addstr(start_y + 5, start_x_keystr, keystr) + stdscr.move(cursor_y, cursor_x) + + # Refresh the screen + stdscr.refresh() + + # Wait for next input + k = stdscr.getch() + +def main(): + curses.wrapper(draw_menu) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/Adventure Game/adventure_game/dashing_test.py b/Adventure Game/adventure_game/dashing_test.py new file mode 100644 index 0000000..a400a52 --- /dev/null +++ b/Adventure Game/adventure_game/dashing_test.py @@ -0,0 +1,17 @@ +from dashing import * + +if __name__ == '__main__': + + ui = HSplit( + VSplit( + Log(title='logs', border_color=5), + ) + ) + # access a tile by index + log = ui.items[0].items[0] + log.append("0 -----") + log.append("1 Hello") + log.append("2 -----") + + # display/refresh the ui + ui.display() diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index f9c34fb..b887df3 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,40 +1,73 @@ -from blessed import Terminal +from time import sleep, time +import math -class Graphics: - def __init__(self): - self.bottom_left_corner = u"└" - self.bottom_right_corner = u"┘" - self.top_left_corner = u"┌" - self.top_right_corner = u"┐" - self.border_horizontal = u"─" - self.border_vertical = u"│" +from dashing import * -class Window: - def __init__(self, term, height, width, xpos, ypos, title=None): - self.term = term +if __name__ == '__main__': - self.title = title - - self.height = height - self.width = width - self.xpos = xpos - self.ypos = ypos - - def draw_borders(self): - # Print the top - print( - self.term.move_xy(self.xpos, self.ypos) + - u"┌" + - u"─" * (self.width - 2) + - u"┐" + ui = HSplit( + VSplit( + HGauge(val=50, title="only title", border_color=5), + HGauge(label="only label", val=20, border_color=5), + HGauge(label="only label", val=30, border_color=5), + HGauge(label="only label", val=50, border_color=5), + HGauge(label="only label", val=80, border_color=5), + HGauge(val=20), + HGauge(label="label, no border", val=55), + HSplit( + VGauge(val=0, border_color=2), + VGauge(val=5, border_color=2), + VGauge(val=30, border_color=2), + VGauge(val=50, border_color=2), + VGauge(val=80, border_color=2, color=4), + VGauge(val=95, border_color=2, color=3), + ColorRangeVGauge( + val=100, + border_color=2, + colormap=( + (33, 2), + (66, 3), + (100, 1), + ) + ), + ) + ), + VSplit( + Text('Hello World,\nthis is dashing.', border_color=2), + Log(title='logs', border_color=5), + VChart(border_color=2, color=2), + HChart(border_color=2, color=2), + HBrailleChart(border_color=2, color=2), + # HBrailleFilledChart(border_color=2, color=2), + ), + title='Dashing', ) + log = ui.items[1].items[1] + vchart = ui.items[1].items[2] + hchart = ui.items[1].items[3] + bchart = ui.items[1].items[4] + # bfchart = ui.items[1].items[5] + log.append("0 -----") + log.append("1 Hello") + log.append("2 -----") + prev_time = time() + for cycle in range(0, 200): + ui.items[0].items[0].value = int(50 + 49.9 * math.sin(cycle / 80.0)) + ui.items[0].items[1].value = int(50 + 45 * math.sin(cycle / 20.0)) + ui.items[0].items[2].value = int(50 + 45 * math.sin(cycle / 30.0 + 3)) - # Print the middle - # We exclude the top and bottom rows since we'll draw them with other chars - for dx in range (1, self.height - 1): - print(self.term.move_xy(self.xpos + dx, self.ypos) + u'│') - print(self.term.move_xy(self.xpos + dx, self.ypos + self.width - 1) + u'│') + vgauges = ui.items[0].items[-1].items + for gaugenum, vg in enumerate(vgauges): + vg.value = 50 + 49.9 * math.sin(cycle / 12.0 + gaugenum) -terminal = Terminal() -my_window = Window(terminal, 4, 20, 10, 10) -my_window.draw_borders() \ No newline at end of file + t = int(time()) + if t != prev_time: + log.append("%s" % t) + prev_time = t + vchart.append(50 + 50 * math.sin(cycle / 16.0)) + hchart.append(99.9 * abs(math.sin(cycle / 26.0))) + bchart.append(50 + 50 * math.sin(cycle / 6.0)) + # bfchart.append(50 + 50 * math.sin(cycle / 16.0)) + ui.display() + + sleep(1.0/25) \ No newline at end of file -- 2.43.0 From 1b73dc208b5b2fae6cf7ba579feb76f4cc55d747 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:02:49 -0500 Subject: [PATCH 10/80] This is still a huge mess --- Adventure Game/adventure_game/dashing_test.py | 17 -- Adventure Game/adventure_game/example.py | 18 ++ Adventure Game/adventure_game/main.py | 156 ++++++++++-------- Adventure Game/adventure_game/test.py | 9 - .../adventure_game/windowed_adventure.py | 86 ++++++++++ 5 files changed, 190 insertions(+), 96 deletions(-) delete mode 100644 Adventure Game/adventure_game/dashing_test.py create mode 100644 Adventure Game/adventure_game/example.py delete mode 100644 Adventure Game/adventure_game/test.py create mode 100644 Adventure Game/adventure_game/windowed_adventure.py diff --git a/Adventure Game/adventure_game/dashing_test.py b/Adventure Game/adventure_game/dashing_test.py deleted file mode 100644 index a400a52..0000000 --- a/Adventure Game/adventure_game/dashing_test.py +++ /dev/null @@ -1,17 +0,0 @@ -from dashing import * - -if __name__ == '__main__': - - ui = HSplit( - VSplit( - Log(title='logs', border_color=5), - ) - ) - # access a tile by index - log = ui.items[0].items[0] - log.append("0 -----") - log.append("1 Hello") - log.append("2 -----") - - # display/refresh the ui - ui.display() diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py new file mode 100644 index 0000000..4913d5d --- /dev/null +++ b/Adventure Game/adventure_game/example.py @@ -0,0 +1,18 @@ +import curses, curses.textpad +def setup_input(): + inp = curses.newwin(8,55, 0,0) + inp.addstr(1,1, "Please enter your username:") + sub = inp.subwin(2,1) + sub.border() + sub2 = sub.subwin(3,2) + global tb + tb = curses.textpad.Textbox(sub2) + inp.refresh() + tb.edit(enter_is_terminate) + +def enter_is_terminate(x): + if x == 10: + tb.do_command(7) + tb.do_command(x) + +setup_input() \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index b887df3..caea9cc 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,73 +1,89 @@ -from time import sleep, time -import math +import curses +from curses.textpad import Textbox, rectangle + + + +def draw_main_menu(stdscr): + # Command is the last char the user entered. + command = 0 + + # Clear, and refresh the screen + stdscr.clear() + stdscr.refresh() + + # Start some curses colors + curses.start_color() + curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + + while command != ord('q'): + # Clear the screen + stdscr.clear() + # Get the height, and width + height, width = stdscr.getmaxyx() + + + # Temporary strings, replace these with libdocs! + title = 'Untitled Adventure Game PRE ALPHA'[:width - 1] + subtitle = 'Joe Sedutto'[:width - 1] + statusbarstr = "Press 'q' to exit " + + # Centering calculations + start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) + start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) + start_y = int((height // 2) - 2) + + # Rendering some text + whstr = 'Width: {}, Height: {}'.format(width, height) + stdscr.addstr(0, 0, whstr, curses.color_pair(1)) + + # Render status bar + stdscr.attron(curses.color_pair(3)) + stdscr.addstr(height - 1, 0, statusbarstr) + stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1)) + stdscr.attroff(curses.color_pair(3)) + + # Turning on attributes for title + stdscr.attron(curses.color_pair(2)) + stdscr.attron(curses.A_BOLD) + + # Rendering title + stdscr.addstr(start_y, start_x_title, title) + + # Turning off attributes for title + stdscr.attroff(curses.color_pair(2)) + stdscr.attroff(curses.A_BOLD) + + # Print rest of text + stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) + stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) + + # Refresh the screen + stdscr.refresh() + + # Wait for next input + command = stdscr.getch() + + +def main_textbox(stdscr): + stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)") + + editwin = curses.newwin(5,30, 2,1) + rectangle(stdscr, 1,0, 1+5+1, 1+30+1) + stdscr.refresh() + + box = Textbox(editwin) + + # Let the user edit until Ctrl-G is struck. + box.edit() + + # Get resulting contents + message = box.gather() + +def main(): + curses.wrapper(main_textbox) -from dashing import * if __name__ == '__main__': - - ui = HSplit( - VSplit( - HGauge(val=50, title="only title", border_color=5), - HGauge(label="only label", val=20, border_color=5), - HGauge(label="only label", val=30, border_color=5), - HGauge(label="only label", val=50, border_color=5), - HGauge(label="only label", val=80, border_color=5), - HGauge(val=20), - HGauge(label="label, no border", val=55), - HSplit( - VGauge(val=0, border_color=2), - VGauge(val=5, border_color=2), - VGauge(val=30, border_color=2), - VGauge(val=50, border_color=2), - VGauge(val=80, border_color=2, color=4), - VGauge(val=95, border_color=2, color=3), - ColorRangeVGauge( - val=100, - border_color=2, - colormap=( - (33, 2), - (66, 3), - (100, 1), - ) - ), - ) - ), - VSplit( - Text('Hello World,\nthis is dashing.', border_color=2), - Log(title='logs', border_color=5), - VChart(border_color=2, color=2), - HChart(border_color=2, color=2), - HBrailleChart(border_color=2, color=2), - # HBrailleFilledChart(border_color=2, color=2), - ), - title='Dashing', - ) - log = ui.items[1].items[1] - vchart = ui.items[1].items[2] - hchart = ui.items[1].items[3] - bchart = ui.items[1].items[4] - # bfchart = ui.items[1].items[5] - log.append("0 -----") - log.append("1 Hello") - log.append("2 -----") - prev_time = time() - for cycle in range(0, 200): - ui.items[0].items[0].value = int(50 + 49.9 * math.sin(cycle / 80.0)) - ui.items[0].items[1].value = int(50 + 45 * math.sin(cycle / 20.0)) - ui.items[0].items[2].value = int(50 + 45 * math.sin(cycle / 30.0 + 3)) - - vgauges = ui.items[0].items[-1].items - for gaugenum, vg in enumerate(vgauges): - vg.value = 50 + 49.9 * math.sin(cycle / 12.0 + gaugenum) - - t = int(time()) - if t != prev_time: - log.append("%s" % t) - prev_time = t - vchart.append(50 + 50 * math.sin(cycle / 16.0)) - hchart.append(99.9 * abs(math.sin(cycle / 26.0))) - bchart.append(50 + 50 * math.sin(cycle / 6.0)) - # bfchart.append(50 + 50 * math.sin(cycle / 16.0)) - ui.display() - - sleep(1.0/25) \ No newline at end of file + main() diff --git a/Adventure Game/adventure_game/test.py b/Adventure Game/adventure_game/test.py deleted file mode 100644 index 11bdcef..0000000 --- a/Adventure Game/adventure_game/test.py +++ /dev/null @@ -1,9 +0,0 @@ -from blessed import Terminal -import time - -term = Terminal() - -for x in range(10): - for y in range(10): - print(term.move_xy(x, y) + '*') - time.sleep(0.1) \ No newline at end of file diff --git a/Adventure Game/adventure_game/windowed_adventure.py b/Adventure Game/adventure_game/windowed_adventure.py new file mode 100644 index 0000000..d457741 --- /dev/null +++ b/Adventure Game/adventure_game/windowed_adventure.py @@ -0,0 +1,86 @@ +import curses +from curses.textpad import Textbox, rectangle + + +class AdventureGame: + def __init__(self, stdscr): + # Self.stdrscr is our parent standard screen + self.stdscr = stdscr + + # This is just done once at startup to get inital windows sizes + # TODO: handle live window resize! + self.height, self.width = self.stdscr.getmaxyx() + + self.command = 0 + + # Clear and refresh the screen + self.stdscr.clear() + self.stdscr.refresh() + + # Setup some colors! + # Start some curses colors + curses.start_color() + curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + + # Setup art_win + art_win_width = int((self.width / 3) * 2) + art_win_begin_x = int(self.width - art_win_width) + art_win_begin_y = 1 # Must be at least 1 (to allow header) + art_win_height = int(self.height / 2) + + art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x) + + # Setup dialogue_win + dialogue_win_width = self.width + dialogue_win_begin_x = 0 + dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above. + dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box, + + dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y, + dialogue_win_begin_x) + + while self.command != 'q': + # Get the height of everything + self.height, self.width = self.stdscr.getmaxyx() + + self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1] + self.statusbarstr = "Press 'q' to exit " + + # Render status bar + self.stdscr.attron(curses.color_pair(3)) + self.stdscr.addstr(self.height - 1, 0, self.statusbarstr) + self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1)) + self.stdscr.attroff(curses.color_pair(3)) + + # Render major game windows + self.draw_art_window(art_win) + self.command = self.draw_dialogue_box(dialogue_win) + + # Refresh the screen + self.stdscr.refresh() + + # Wait for next input + # self.command = self.stdscr.getch() + curses.echo() + #self.command = self.stdscr.getstr(0, 0) + + def draw_main_menu(self): + pass + + def draw_art_window(self, window): + window.addstr(0, 0, "Wip") + window.box() + window.refresh() + + def draw_dialogue_box(self, window): + window.box() + window.refresh() + + textbox = Textbox(window) + return textbox.gather() + + +if __name__ == '__main__': + curses.wrapper(AdventureGame) -- 2.43.0 From e87c70e04f621441aff05c75e70def590cec9c5e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:07:32 -0500 Subject: [PATCH 11/80] Stll broke --- Adventure Game/adventure_game/main.py | 125 +++++++++--------- .../adventure_game/windowed_adventure.py | 86 ------------ 2 files changed, 61 insertions(+), 150 deletions(-) delete mode 100644 Adventure Game/adventure_game/windowed_adventure.py diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index caea9cc..0c69125 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -2,88 +2,85 @@ import curses from curses.textpad import Textbox, rectangle +class AdventureGame: + def __init__(self, stdscr): + # Self.stdrscr is our parent standard screen + self.stdscr = stdscr -def draw_main_menu(stdscr): - # Command is the last char the user entered. - command = 0 + # This is just done once at startup to get inital windows sizes + # TODO: handle live window resize! + self.height, self.width = self.stdscr.getmaxyx() - # Clear, and refresh the screen - stdscr.clear() - stdscr.refresh() + self.command = 0 - # Start some curses colors - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + # Clear and refresh the screen + self.stdscr.clear() + self.stdscr.refresh() - while command != ord('q'): - # Clear the screen - stdscr.clear() - # Get the height, and width - height, width = stdscr.getmaxyx() + # Setup some colors! + # Start some curses colors + curses.start_color() + curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + # Setup art_win + art_win_width = int((self.width / 3) * 2) + art_win_begin_x = int(self.width - art_win_width) + art_win_begin_y = 1 # Must be at least 1 (to allow header) + art_win_height = int(self.height / 2) - # Temporary strings, replace these with libdocs! - title = 'Untitled Adventure Game PRE ALPHA'[:width - 1] - subtitle = 'Joe Sedutto'[:width - 1] - statusbarstr = "Press 'q' to exit " + art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x) - # Centering calculations - start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) - start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) - start_y = int((height // 2) - 2) + # Setup dialogue_win + dialogue_win_width = self.width + dialogue_win_begin_x = 0 + dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above. + dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box, - # Rendering some text - whstr = 'Width: {}, Height: {}'.format(width, height) - stdscr.addstr(0, 0, whstr, curses.color_pair(1)) + dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y, + dialogue_win_begin_x) - # Render status bar - stdscr.attron(curses.color_pair(3)) - stdscr.addstr(height - 1, 0, statusbarstr) - stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1)) - stdscr.attroff(curses.color_pair(3)) + while self.command != ord('q'): + # Get the height of everything + self.height, self.width = self.stdscr.getmaxyx() - # Turning on attributes for title - stdscr.attron(curses.color_pair(2)) - stdscr.attron(curses.A_BOLD) + self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1] + self.statusbarstr = "Press 'q' to exit " - # Rendering title - stdscr.addstr(start_y, start_x_title, title) + # Render status bar + self.stdscr.attron(curses.color_pair(3)) + self.stdscr.addstr(self.height - 1, 0, self.statusbarstr) + self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1)) + self.stdscr.attroff(curses.color_pair(3)) - # Turning off attributes for title - stdscr.attroff(curses.color_pair(2)) - stdscr.attroff(curses.A_BOLD) + # Render major game windows + self.draw_art_window(art_win) + self.command = self.draw_dialogue_box(dialogue_win) - # Print rest of text - stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) - stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) + # Refresh the screen + self.stdscr.refresh() - # Refresh the screen - stdscr.refresh() + # Wait for next input + # self.command = self.stdscr.getch() + curses.echo() + #self.command = self.stdscr.getstr(0, 0) - # Wait for next input - command = stdscr.getch() + def draw_main_menu(self): + pass + def draw_art_window(self, window): + window.addstr(0, 0, "Wip") + window.box() + window.refresh() -def main_textbox(stdscr): - stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)") + def draw_dialogue_box(self, window): + window.box() + window.refresh() - editwin = curses.newwin(5,30, 2,1) - rectangle(stdscr, 1,0, 1+5+1, 1+30+1) - stdscr.refresh() - - box = Textbox(editwin) - - # Let the user edit until Ctrl-G is struck. - box.edit() - - # Get resulting contents - message = box.gather() - -def main(): - curses.wrapper(main_textbox) + textbox = Textbox(window) + return textbox.gather() if __name__ == '__main__': - main() + curses.wrapper(AdventureGame) diff --git a/Adventure Game/adventure_game/windowed_adventure.py b/Adventure Game/adventure_game/windowed_adventure.py deleted file mode 100644 index d457741..0000000 --- a/Adventure Game/adventure_game/windowed_adventure.py +++ /dev/null @@ -1,86 +0,0 @@ -import curses -from curses.textpad import Textbox, rectangle - - -class AdventureGame: - def __init__(self, stdscr): - # Self.stdrscr is our parent standard screen - self.stdscr = stdscr - - # This is just done once at startup to get inital windows sizes - # TODO: handle live window resize! - self.height, self.width = self.stdscr.getmaxyx() - - self.command = 0 - - # Clear and refresh the screen - self.stdscr.clear() - self.stdscr.refresh() - - # Setup some colors! - # Start some curses colors - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) - - # Setup art_win - art_win_width = int((self.width / 3) * 2) - art_win_begin_x = int(self.width - art_win_width) - art_win_begin_y = 1 # Must be at least 1 (to allow header) - art_win_height = int(self.height / 2) - - art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x) - - # Setup dialogue_win - dialogue_win_width = self.width - dialogue_win_begin_x = 0 - dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above. - dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box, - - dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y, - dialogue_win_begin_x) - - while self.command != 'q': - # Get the height of everything - self.height, self.width = self.stdscr.getmaxyx() - - self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1] - self.statusbarstr = "Press 'q' to exit " - - # Render status bar - self.stdscr.attron(curses.color_pair(3)) - self.stdscr.addstr(self.height - 1, 0, self.statusbarstr) - self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1)) - self.stdscr.attroff(curses.color_pair(3)) - - # Render major game windows - self.draw_art_window(art_win) - self.command = self.draw_dialogue_box(dialogue_win) - - # Refresh the screen - self.stdscr.refresh() - - # Wait for next input - # self.command = self.stdscr.getch() - curses.echo() - #self.command = self.stdscr.getstr(0, 0) - - def draw_main_menu(self): - pass - - def draw_art_window(self, window): - window.addstr(0, 0, "Wip") - window.box() - window.refresh() - - def draw_dialogue_box(self, window): - window.box() - window.refresh() - - textbox = Textbox(window) - return textbox.gather() - - -if __name__ == '__main__': - curses.wrapper(AdventureGame) -- 2.43.0 From a6d2352cfaa7aa2c6302ee3b59c092d0093d0b0a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 15 Feb 2021 22:16:20 -0500 Subject: [PATCH 12/80] Somewhat less broken? still littered with bugs. --- Adventure Game/adventure_game/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0c69125..d30f79d 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,5 +1,5 @@ import curses -from curses.textpad import Textbox, rectangle +from curses.textpad import Textbox class AdventureGame: @@ -70,7 +70,8 @@ class AdventureGame: pass def draw_art_window(self, window): - window.addstr(0, 0, "Wip") + window.addstr("Wip") + window.addstr("Morewip lol") window.box() window.refresh() @@ -79,7 +80,7 @@ class AdventureGame: window.refresh() textbox = Textbox(window) - return textbox.gather() + return textbox.edit() if __name__ == '__main__': -- 2.43.0 From 52d4f5bbfe4c8370257583806d9702c7305c6a4f Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 18:18:34 -0500 Subject: [PATCH 13/80] Nearing a sort-of-functional alpha --- Adventure Game/.gitignore | 1 + Adventure Game/adventure_game/curses_test.py | 92 ---------------- Adventure Game/adventure_game/example.py | 46 +++++--- Adventure Game/adventure_game/main.py | 109 +++++++------------ Adventure Game/requirements.txt | 3 +- 5 files changed, 71 insertions(+), 180 deletions(-) delete mode 100644 Adventure Game/adventure_game/curses_test.py diff --git a/Adventure Game/.gitignore b/Adventure Game/.gitignore index 5ceb386..29e5705 100644 --- a/Adventure Game/.gitignore +++ b/Adventure Game/.gitignore @@ -1 +1,2 @@ venv +inspectionProfiles diff --git a/Adventure Game/adventure_game/curses_test.py b/Adventure Game/adventure_game/curses_test.py deleted file mode 100644 index d316fcd..0000000 --- a/Adventure Game/adventure_game/curses_test.py +++ /dev/null @@ -1,92 +0,0 @@ -import sys,os -import curses - -def draw_menu(stdscr): - k = 0 - cursor_x = 0 - cursor_y = 0 - - # Clear and refresh the screen for a blank canvas - stdscr.clear() - stdscr.refresh() - - # Start colors in curses - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) - - # Loop where k is the last character pressed - while (k != ord('q')): - - # Initialization - stdscr.clear() - height, width = stdscr.getmaxyx() - - if k == curses.KEY_DOWN: - cursor_y = cursor_y + 1 - elif k == curses.KEY_UP: - cursor_y = cursor_y - 1 - elif k == curses.KEY_RIGHT: - cursor_x = cursor_x + 1 - elif k == curses.KEY_LEFT: - cursor_x = cursor_x - 1 - - cursor_x = max(0, cursor_x) - cursor_x = min(width-1, cursor_x) - - cursor_y = max(0, cursor_y) - cursor_y = min(height-1, cursor_y) - - # Declaration of strings - title = "Curses example"[:width-1] - subtitle = "Written by Clay McLeod"[:width-1] - keystr = "Last key pressed: {}".format(k)[:width-1] - statusbarstr = "Press 'q' to exit | STATUS BAR | Pos: {}, {}".format(cursor_x, cursor_y) - if k == 0: - keystr = "No key press detected..."[:width-1] - - # Centering calculations - start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) - start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2) - start_x_keystr = int((width // 2) - (len(keystr) // 2) - len(keystr) % 2) - start_y = int((height // 2) - 2) - - # Rendering some text - whstr = "Width: {}, Height: {}".format(width, height) - stdscr.addstr(0, 0, whstr, curses.color_pair(1)) - - # Render status bar - stdscr.attron(curses.color_pair(3)) - stdscr.addstr(height-1, 0, statusbarstr) - stdscr.addstr(height-1, len(statusbarstr), " " * (width - len(statusbarstr) - 1)) - stdscr.attroff(curses.color_pair(3)) - - # Turning on attributes for title - stdscr.attron(curses.color_pair(2)) - stdscr.attron(curses.A_BOLD) - - # Rendering title - stdscr.addstr(start_y, start_x_title, title) - - # Turning off attributes for title - stdscr.attroff(curses.color_pair(2)) - stdscr.attroff(curses.A_BOLD) - - # Print rest of text - stdscr.addstr(start_y + 1, start_x_subtitle, subtitle) - stdscr.addstr(start_y + 3, (width // 2) - 2, '-' * 4) - stdscr.addstr(start_y + 5, start_x_keystr, keystr) - stdscr.move(cursor_y, cursor_x) - - # Refresh the screen - stdscr.refresh() - - # Wait for next input - k = stdscr.getch() - -def main(): - curses.wrapper(draw_menu) - -if __name__ == "__main__": - main() \ No newline at end of file diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py index 4913d5d..6cf4ea8 100644 --- a/Adventure Game/adventure_game/example.py +++ b/Adventure Game/adventure_game/example.py @@ -1,18 +1,32 @@ -import curses, curses.textpad -def setup_input(): - inp = curses.newwin(8,55, 0,0) - inp.addstr(1,1, "Please enter your username:") - sub = inp.subwin(2,1) - sub.border() - sub2 = sub.subwin(3,2) - global tb - tb = curses.textpad.Textbox(sub2) - inp.refresh() - tb.edit(enter_is_terminate) +# encoding: utf-8 -def enter_is_terminate(x): - if x == 10: - tb.do_command(7) - tb.do_command(x) +import npyscreen -setup_input() \ No newline at end of file + +class TestApp(npyscreen.NPSApp): + def main(self): + # These lines create the form and populate it with widgets. + # A fairly complex screen in only 8 or so lines of code - a line for each control. + F = npyscreen.Form(name="Welcome to Npyscreen", ) + t = F.add(npyscreen.TitleText, name="Text:", ) + fn = F.add(npyscreen.TitleFilename, name="Filename:") + fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:") + dt = F.add(npyscreen.TitleDateCombo, name="Date:") + s = F.add(npyscreen.TitleSlider, out_of=12, name="Slider") + ml = F.add(npyscreen.MultiLineEdit, + value="""try typing here!\nMutiline text, press ^R to reformat.\n""", + max_height=5, rely=9) + ms = F.add(npyscreen.TitleSelectOne, max_height=4, value=[1, ], name="Pick One", + values=["Option1", "Option2", "Option3"], scroll_exit=True) + ms2 = F.add(npyscreen.TitleMultiSelect, max_height=-2, value=[1, ], name="Pick Several", + values=["Option1", "Option2", "Option3"], scroll_exit=True) + + # This lets the user interact with the Form. + F.edit() + + print(ms.get_selected_objects()) + + +if __name__ == "__main__": + App = TestApp() + App.run() diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index d30f79d..940dd35 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,87 +1,56 @@ -import curses -from curses.textpad import Textbox +import npyscreen -class AdventureGame: - def __init__(self, stdscr): - # Self.stdrscr is our parent standard screen - self.stdscr = stdscr +class GameNavigator(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm(None) - # This is just done once at startup to get inital windows sizes - # TODO: handle live window resize! - self.height, self.width = self.stdscr.getmaxyx() + def create(self): + self.myName = self.add(npyscreen.TitleText, name='Name') + self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', + values=['Department 1', 'Department 2', 'Department 3']) + self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') - self.command = 0 - # Clear and refresh the screen - self.stdscr.clear() - self.stdscr.refresh() +class MainMenu(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm('GAME') - # Setup some colors! - # Start some curses colors - curses.start_color() - curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) - curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) + def create(self): + self.add(npyscreen.MultiLineEdit, value='Test', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") - # Setup art_win - art_win_width = int((self.width / 3) * 2) - art_win_begin_x = int(self.width - art_win_width) - art_win_begin_y = 1 # Must be at least 1 (to allow header) - art_win_height = int(self.height / 2) - art_win = curses.newwin(art_win_height, art_win_width, art_win_begin_y, art_win_begin_x) +class AlphaWarning(npyscreen.Popup): + def afterEditing(self): + self.parentApp.setNextForm('MENU') - # Setup dialogue_win - dialogue_win_width = self.width - dialogue_win_begin_x = 0 - dialogue_win_begin_y = art_win_height + 1 # Fits 1 underneath the art box above. - dialogue_win_height = self.height - art_win_height - 2 # Fits 2 underneath the bottom box, + def create(self): + self.add(npyscreen.Pager, values=['Welcome to Unnamed Adventure game!', + 'Please enjoy your stay and report any bugs at', + 'kitsunehosting.net'], editable=False) - dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y, - dialogue_win_begin_x) - while self.command != ord('q'): - # Get the height of everything - self.height, self.width = self.stdscr.getmaxyx() - self.title = 'Untitled Adventure Game PRE ALPHA'[:self.width - 1] - self.statusbarstr = "Press 'q' to exit " +class AdventureGame(npyscreen.NPSAppManaged): + # Do on creation + def onStart(self): + # Intalize a game renderer for most game windows + self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') - # Render status bar - self.stdscr.attron(curses.color_pair(3)) - self.stdscr.addstr(self.height - 1, 0, self.statusbarstr) - self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1)) - self.stdscr.attroff(curses.color_pair(3)) + # Initalize a savegameSelector that allows a user to choose a savegame + self.addForm('MENU', MainMenu, name='Welcome to the main menu') - # Render major game windows - self.draw_art_window(art_win) - self.command = self.draw_dialogue_box(dialogue_win) - - # Refresh the screen - self.stdscr.refresh() - - # Wait for next input - # self.command = self.stdscr.getch() - curses.echo() - #self.command = self.stdscr.getstr(0, 0) - - def draw_main_menu(self): - pass - - def draw_art_window(self, window): - window.addstr("Wip") - window.addstr("Morewip lol") - window.box() - window.refresh() - - def draw_dialogue_box(self, window): - window.box() - window.refresh() - - textbox = Textbox(window) - return textbox.edit() + # Initalize a savegameSelector that allows a user to choose a savegame + self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') + #TODO: Create a 'splash screen' or, traditional "main menu" if __name__ == '__main__': - curses.wrapper(AdventureGame) + # Make a new adventure game if not imported + adventure_game = AdventureGame() + + # Run the game! + adventure_game.run() diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index 6493b8a..52c0eb3 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1,2 +1 @@ -# Blessed handles our terminal "graphics" -blessed==1.17.12 \ No newline at end of file +npyscreen~=4.10.5 \ No newline at end of file -- 2.43.0 From db78cca216e85a571ab0d0898a78ddc90956257a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:17:37 -0500 Subject: [PATCH 14/80] If we add the multiline edit above playersavelocation then it crashes, fix? --- Adventure Game/adventure_game/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 940dd35..0005530 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -19,8 +19,8 @@ class MainMenu(npyscreen.Form): self.parentApp.setNextForm('GAME') def create(self): - self.add(npyscreen.MultiLineEdit, value='Test', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") + self.add(npyscreen.MultiLineEdit, value='Test', editable=False) class AlphaWarning(npyscreen.Popup): -- 2.43.0 From 1999e8b8ecc69e5e61ff5718aaacf54ce2ea6cef Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:23:26 -0500 Subject: [PATCH 15/80] Added in yaml This works, but has a few minor bugs. it lays the foundation though for more stuff to be added --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 13 +++++++++++++ Adventure Game/adventure_game/main.py | 5 ++++- Adventure Game/adventure_game/yaml_parser.py | 12 ++++++++++++ Adventure Game/requirements.txt | 3 ++- 4 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/gamelib.yaml create mode 100644 Adventure Game/adventure_game/yaml_parser.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml new file mode 100644 index 0000000..223c904 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -0,0 +1,13 @@ +menu: + graphics: + logo: | + __ __ __ ___ __ __ + / / / /___ ____ ____ _____ ___ ___ ____/ / / | ____/ / _____ ____ / /___ __________ + / / / / __ \/ __ \/ __ `/ __ `__ \/ _ \/ __ / / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ + / /_/ / / / / / / / /_/ / / / / / / __/ /_/ / / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ + \____/_/ /_/_/ /_/\__,_/_/ /_/ /_/\___/\__,_/ /_/ |_\__,_/ |___/\___/_/ /_/\__/\__,_/_/ \___/ + _________ __ _________ + / ____/ | / |/ / ____/ + / / __/ /| | / /|_/ / __/ + / /_/ / ___ |/ / / / /___ + \____/_/ |_/_/ /_/_____/ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0005530..91a55c7 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,4 +1,5 @@ import npyscreen +from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): @@ -20,7 +21,7 @@ class MainMenu(npyscreen.Form): def create(self): self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") - self.add(npyscreen.MultiLineEdit, value='Test', editable=False) + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) class AlphaWarning(npyscreen.Popup): @@ -37,6 +38,8 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): + self.gamelib = parse('gamedata/gamelib.yaml') + # Intalize a game renderer for most game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') diff --git a/Adventure Game/adventure_game/yaml_parser.py b/Adventure Game/adventure_game/yaml_parser.py new file mode 100644 index 0000000..0d41be6 --- /dev/null +++ b/Adventure Game/adventure_game/yaml_parser.py @@ -0,0 +1,12 @@ +import yaml + + +def parse_datafile(file): + # With the file open + with open(file, 'r') as stream: + # Try to read it and return it + try: + content = yaml.safe_load(stream) + return content + except yaml.YAMLError as exc: + return exc diff --git a/Adventure Game/requirements.txt b/Adventure Game/requirements.txt index 52c0eb3..ba33800 100644 --- a/Adventure Game/requirements.txt +++ b/Adventure Game/requirements.txt @@ -1 +1,2 @@ -npyscreen~=4.10.5 \ No newline at end of file +npyscreen~=4.10.5 +PyYAML~=5.1.2 \ No newline at end of file -- 2.43.0 From 45801c53b05bc06980fda43291f772b17fdb002a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 20:25:36 -0500 Subject: [PATCH 16/80] TODO Weird bug where this crashes the game if the first char is not something other than space --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 223c904..c1b0624 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -1,7 +1,7 @@ menu: graphics: logo: | - __ __ __ ___ __ __ + . __ __ __ ___ __ __ / / / /___ ____ ____ _____ ___ ___ ____/ / / | ____/ / _____ ____ / /___ __________ / / / / __ \/ __ \/ __ `/ __ `__ \/ _ \/ __ / / /| |/ __ / | / / _ \/ __ \/ __/ / / / ___/ _ \ / /_/ / / / / / / / /_/ / / / / / / __/ /_/ / / ___ / /_/ /| |/ / __/ / / / /_/ /_/ / / / __/ -- 2.43.0 From e79fda1bb9ae9d5b03984949b05bd4f071b3fc04 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:53:12 -0500 Subject: [PATCH 17/80] Add a lot of quality of life stuff including exception to handle small screens --- .../adventure_game/gamedata/gamelib.yaml | 7 ++- Adventure Game/adventure_game/main.py | 44 ++++++++++++------- Adventure Game/adventure_game/text.py | 35 +++++++++++++++ 3 files changed, 68 insertions(+), 18 deletions(-) create mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index c1b0624..3ed6da6 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -10,4 +10,9 @@ menu: / ____/ | / |/ / ____/ / / __/ /| | / /|_/ / __/ / /_/ / ___ |/ / / / /___ - \____/_/ |_/_/ /_/_____/ \ No newline at end of file + \____/_/ |_/_/ /_/_____/ + + not_found: | + . / \ + / ! \ + / \ \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 91a55c7..cb4e615 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,17 +1,24 @@ import npyscreen +from npyscreen import NotEnoughSpaceForWidget + from yaml_parser import parse_datafile as parse class GameNavigator(npyscreen.Form): def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm(None) + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.myName = self.add(npyscreen.TitleText, name='Name') - self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', - values=['Department 1', 'Department 2', 'Department 3']) - self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=2,) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=32, rely=2) + self.artBox.footer = 'Unknown Location' + + #self.myName = self.add(npyscreen.TitleText, name='Name') + #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', + # values=['Department 1', 'Department 2', 'Department 3']) + #self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') class MainMenu(npyscreen.Form): @@ -34,26 +41,29 @@ class AlphaWarning(npyscreen.Popup): 'kitsunehosting.net'], editable=False) - class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): - self.gamelib = parse('gamedata/gamelib.yaml') + # Setup some important 'globa' values we'll need later + self.gamelib = parse( + 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen - # Intalize a game renderer for most game windows - self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') + # Draw game windows + self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game + self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu + self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') # This window is only needed for the ALPHA - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MENU', MainMenu, name='Welcome to the main menu') + # TODO: Create a 'splash screen' or, traditional "main menu" - # Initalize a savegameSelector that allows a user to choose a savegame - self.addForm('MAIN', AlphaWarning, name='Welcome to the alpha!') - - #TODO: Create a 'splash screen' or, traditional "main menu" if __name__ == '__main__': # Make a new adventure game if not imported adventure_game = AdventureGame() # Run the game! - adventure_game.run() + try: + adventure_game.run() + except NotEnoughSpaceForWidget: + # This exception should catch if a player tries to play in a screen that is too small. + print('Your screen is too small!\nOr, Joe has not fixed https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues/7') diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py new file mode 100644 index 0000000..53df858 --- /dev/null +++ b/Adventure Game/adventure_game/text.py @@ -0,0 +1,35 @@ +import npyscreen + + +# npyscreen.disableColor() +class TestApp(npyscreen.NPSApp): + def main(self): + F = npyscreen.Form(name="Welcome to Npyscreen", ) + t = F.add(npyscreen.BoxBasic, name="Basic Box:", max_width=30, relx=2, max_height=3) + t.footer = "This is a footer" + + t1 = F.add(npyscreen.BoxBasic, name="Basic Box:", rely=2, relx=32, max_width=30, max_height=3) + + t2 = F.add(npyscreen.BoxTitle, name="Box Title:", max_height=6) + t3 = F.add(npyscreen.BoxTitle, name="Box Title2:", max_height=6, + scroll_exit=True, + contained_widget_arguments={ + 'color': "WARNING", + 'widgets_inherit_color': True, } + ) + + t2.entry_widget.scroll_exit = True + t2.values = ["Hello", + "This is a Test", + "This is another test", + "And here is another line", + "And here is another line, which is really very long. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", + "And one more."] + t3.values = t2.values + + F.edit() + + +if __name__ == "__main__": + App = TestApp() + App.run() \ No newline at end of file -- 2.43.0 From cc620fda20e0479fd527be8f6fae71f58b7fd807 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:35:19 -0500 Subject: [PATCH 18/80] Fix yaml arangement --- Adventure Game/adventure_game/gamedata/gamelib.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 3ed6da6..5ecc905 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -15,4 +15,4 @@ menu: not_found: | . / \ / ! \ - / \ \ No newline at end of file + / \ -- 2.43.0 From 0867fe6d5fbafa2d82a4b2bd3b67f795101cdc10 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 14:35:36 -0500 Subject: [PATCH 19/80] Order artbox and inventory list together --- Adventure Game/adventure_game/main.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index cb4e615..0a9c462 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -9,11 +9,10 @@ class GameNavigator(npyscreen.Form): self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=2,) + self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=21) self.artBox.footer = 'Unknown Location' - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=32, rely=2) - self.artBox.footer = 'Unknown Location' + self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) #self.myName = self.add(npyscreen.TitleText, name='Name') #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', @@ -44,7 +43,7 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): - # Setup some important 'globa' values we'll need later + # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen -- 2.43.0 From adf7383c9fae365a124044caa64ff6c7e0b33da3 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 16:23:43 -0500 Subject: [PATCH 20/80] Update main.py --- Adventure Game/adventure_game/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 0a9c462..57e3c0e 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -14,6 +14,8 @@ class GameNavigator(npyscreen.Form): self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) + self.DialogueBox = self.add(npyscreen.BoxBasic, name='Type Here', max_width=20, max_height=20, relx=1, rely=2) + #self.myName = self.add(npyscreen.TitleText, name='Name') #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', # values=['Department 1', 'Department 2', 'Department 3']) @@ -26,7 +28,8 @@ class MainMenu(npyscreen.Form): self.parentApp.setNextForm('GAME') def create(self): - self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Filename:") + self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) -- 2.43.0 From 6743be8a6c4cdecae42ec84f5face1eedbe2a43d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:07:19 -0500 Subject: [PATCH 21/80] Update art rendering and prepare for input handling --- .../adventure_game/gamedata/gamelib.yaml | 21 +++++++-- .../adventure_game/gamedata/world/office.yaml | 12 ++++++ Adventure Game/adventure_game/main.py | 43 ++++++++++++++++--- 3 files changed, 66 insertions(+), 10 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/world/office.yaml diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index 5ecc905..dc5deff 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -13,6 +13,21 @@ menu: \____/_/ |_/_/ /_/_____/ not_found: | - . / \ - / ! \ - / \ + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -----------------------------------------------/ \----------------------------------------------- + ----------------------------------------------/ !! \---------------------------------------------- + ---------------------------------------------/ \--------------------------------------------- + --------------------------------------No Art for this location------------------------------------ + ----------------------------------Consider making a pull request?--------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- + -------------------------------------------------------------------------------------------------- diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml new file mode 100644 index 0000000..3d88078 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -0,0 +1,12 @@ +office: + grid: [0, 0] + upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" + look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|" + pick_up_logviewer: "You pick the *LOG VIEWER* up." + desk: + look_at: "You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" + inspect: "Desk, ornate, stuff" + log_viewer: + look_at: "logviewer looks like garbo" + inspect: "beep boop" + pick_up: "You pick up the *LOG VIEWER*." \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 57e3c0e..e85176c 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -9,17 +9,46 @@ class GameNavigator(npyscreen.Form): self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. def create(self): - self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', max_width=100, max_height=20, relx=21) + top_division_height = 20 + inventory_width = 20 + art_width = 100 + + self.artBox = self.add(npyscreen.BoxBasic, + name='ArtBox', + max_width=art_width, + max_height=top_division_height, + rely=2, + relx=inventory_width + 1, + editable=False) + self.artContent = self.add(npyscreen.MultiLineEdit, + rely=3, + relx=inventory_width + 2, + max_width=art_width - 2, + max_height=top_division_height - 2, + value=self.parentApp.gamelib['menu']['graphics']['not_found'], + editable=False) self.artBox.footer = 'Unknown Location' - self.artBox = self.add(npyscreen.BoxBasic, name='Inventory', max_width=20, max_height=20, relx=1, rely=2) + self.artBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) - self.DialogueBox = self.add(npyscreen.BoxBasic, name='Type Here', max_width=20, max_height=20, relx=1, rely=2) + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=3, + relx=1, + rely=top_division_height + 2) - #self.myName = self.add(npyscreen.TitleText, name='Name') - #self.myDepartment = self.add(npyscreen.TitleSelectOne, scroll_exit=True, max_height=3, name='Department', - # values=['Department 1', 'Department 2', 'Department 3']) - #self.myDate = self.add(npyscreen.TitleDateCombo, name='Date Employed') + self.dialogueBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 2, + max_height=1, + relx=2, + rely=top_division_height + 3) class MainMenu(npyscreen.Form): -- 2.43.0 From 04669d0f8f51761b15fc70f49fd659222b58de93 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 17 Feb 2021 22:46:21 -0500 Subject: [PATCH 22/80] Send button functions but needs implementation --- Adventure Game/adventure_game/main.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index e85176c..90e3fef 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,8 +1,12 @@ -import npyscreen +import npyscreen, sys from npyscreen import NotEnoughSpaceForWidget from yaml_parser import parse_datafile as parse +class ExitButton(npyscreen.ButtonPress): + def whenPressed(self): + sys.exit(0) + class GameNavigator(npyscreen.Form): def afterEditing(self): @@ -45,11 +49,13 @@ class GameNavigator(npyscreen.Form): self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', - max_width=inventory_width + art_width - 2, + max_width=inventory_width + art_width - 7, max_height=1, relx=2, rely=top_division_height + 3) + self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) + class MainMenu(npyscreen.Form): def afterEditing(self): -- 2.43.0 From b2466257ceb48e98015a99fcf4f532150d97ae87 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:13:02 -0500 Subject: [PATCH 23/80] Refactor Game navigator location also cleanup some unused files --- .../adventure_game/GameNavigator.py | 53 ++++++++++++++++ Adventure Game/adventure_game/example.py | 32 ---------- .../adventure_game/gamedata/gamelib.yaml | 9 +++ Adventure Game/adventure_game/main.py | 61 +++---------------- Adventure Game/adventure_game/text.py | 35 ----------- 5 files changed, 70 insertions(+), 120 deletions(-) create mode 100644 Adventure Game/adventure_game/GameNavigator.py delete mode 100644 Adventure Game/adventure_game/example.py delete mode 100644 Adventure Game/adventure_game/text.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py new file mode 100644 index 0000000..a342861 --- /dev/null +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -0,0 +1,53 @@ +import npyscreen, sys + +class ExitButton(npyscreen.ButtonPress): + def whenPressed(self): + sys.exit(0) + +class GameNavigator(npyscreen.Form): + def afterEditing(self): + self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. + + def create(self): + top_division_height = 20 + inventory_width = 20 + art_width = 100 + + self.artBox = self.add(npyscreen.BoxBasic, + name='ArtBox', + max_width=art_width, + max_height=top_division_height, + rely=2, + relx=inventory_width + 1, + editable=False) + self.artContent = self.add(npyscreen.MultiLineEdit, + rely=3, + relx=inventory_width + 2, + max_width=art_width - 2, + max_height=top_division_height - 2, + value=self.parentApp.gamelib['menu']['graphics']['not_found'], + editable=False) + self.artBox.footer = 'Unknown Location' + + self.artBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) + + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=3, + relx=1, + rely=top_division_height + 2) + + self.dialogueBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 7, + max_height=1, + relx=2, + rely=top_division_height + 3) + + self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) \ No newline at end of file diff --git a/Adventure Game/adventure_game/example.py b/Adventure Game/adventure_game/example.py deleted file mode 100644 index 6cf4ea8..0000000 --- a/Adventure Game/adventure_game/example.py +++ /dev/null @@ -1,32 +0,0 @@ -# encoding: utf-8 - -import npyscreen - - -class TestApp(npyscreen.NPSApp): - def main(self): - # These lines create the form and populate it with widgets. - # A fairly complex screen in only 8 or so lines of code - a line for each control. - F = npyscreen.Form(name="Welcome to Npyscreen", ) - t = F.add(npyscreen.TitleText, name="Text:", ) - fn = F.add(npyscreen.TitleFilename, name="Filename:") - fn2 = F.add(npyscreen.TitleFilenameCombo, name="Filename2:") - dt = F.add(npyscreen.TitleDateCombo, name="Date:") - s = F.add(npyscreen.TitleSlider, out_of=12, name="Slider") - ml = F.add(npyscreen.MultiLineEdit, - value="""try typing here!\nMutiline text, press ^R to reformat.\n""", - max_height=5, rely=9) - ms = F.add(npyscreen.TitleSelectOne, max_height=4, value=[1, ], name="Pick One", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - ms2 = F.add(npyscreen.TitleMultiSelect, max_height=-2, value=[1, ], name="Pick Several", - values=["Option1", "Option2", "Option3"], scroll_exit=True) - - # This lets the user interact with the Form. - F.edit() - - print(ms.get_selected_objects()) - - -if __name__ == "__main__": - App = TestApp() - App.run() diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index dc5deff..d817750 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -31,3 +31,12 @@ menu: -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------------------- + dimensions: + inventory_width: 23 + inventory_height: 20 + art_width: 101 + art_height: 20 + dialogue_width: 122 + dialogue_height: 20 + entry_box_width: 122 + entry_box_height: 3 diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 90e3fef..e99b86b 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,60 +1,9 @@ import npyscreen, sys from npyscreen import NotEnoughSpaceForWidget +from os import system from yaml_parser import parse_datafile as parse - -class ExitButton(npyscreen.ButtonPress): - def whenPressed(self): - sys.exit(0) - - -class GameNavigator(npyscreen.Form): - def afterEditing(self): - self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. - - def create(self): - top_division_height = 20 - inventory_width = 20 - art_width = 100 - - self.artBox = self.add(npyscreen.BoxBasic, - name='ArtBox', - max_width=art_width, - max_height=top_division_height, - rely=2, - relx=inventory_width + 1, - editable=False) - self.artContent = self.add(npyscreen.MultiLineEdit, - rely=3, - relx=inventory_width + 2, - max_width=art_width - 2, - max_height=top_division_height - 2, - value=self.parentApp.gamelib['menu']['graphics']['not_found'], - editable=False) - self.artBox.footer = 'Unknown Location' - - self.artBox = self.add(npyscreen.BoxBasic, - name='Inventory', - max_width=inventory_width, - max_height=top_division_height, - relx=1, - rely=2, - editable=False) - - self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, - max_width=inventory_width + art_width, - max_height=3, - relx=1, - rely=top_division_height + 2) - - self.dialogueBox = self.add(npyscreen.Textfield, - name='Type Here', - max_width=inventory_width + art_width - 7, - max_height=1, - relx=2, - rely=top_division_height + 3) - - self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) +from GameNavigator import GameNavigator class MainMenu(npyscreen.Form): @@ -86,6 +35,12 @@ class AdventureGame(npyscreen.NPSAppManaged): 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen + # Set screen size before drawing windows + dimensions = self.gamelib['menu']['graphics']['dimensions'] + system('mode con: cols={0} lines={1}'.format( + dimensions['inventory_width']+dimensions['art_width'], + 30)) # TODO: Finish setting this up. + # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu diff --git a/Adventure Game/adventure_game/text.py b/Adventure Game/adventure_game/text.py deleted file mode 100644 index 53df858..0000000 --- a/Adventure Game/adventure_game/text.py +++ /dev/null @@ -1,35 +0,0 @@ -import npyscreen - - -# npyscreen.disableColor() -class TestApp(npyscreen.NPSApp): - def main(self): - F = npyscreen.Form(name="Welcome to Npyscreen", ) - t = F.add(npyscreen.BoxBasic, name="Basic Box:", max_width=30, relx=2, max_height=3) - t.footer = "This is a footer" - - t1 = F.add(npyscreen.BoxBasic, name="Basic Box:", rely=2, relx=32, max_width=30, max_height=3) - - t2 = F.add(npyscreen.BoxTitle, name="Box Title:", max_height=6) - t3 = F.add(npyscreen.BoxTitle, name="Box Title2:", max_height=6, - scroll_exit=True, - contained_widget_arguments={ - 'color': "WARNING", - 'widgets_inherit_color': True, } - ) - - t2.entry_widget.scroll_exit = True - t2.values = ["Hello", - "This is a Test", - "This is another test", - "And here is another line", - "And here is another line, which is really very long. abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz", - "And one more."] - t3.values = t2.values - - F.edit() - - -if __name__ == "__main__": - App = TestApp() - App.run() \ No newline at end of file -- 2.43.0 From 5437129a768c36f0fddf2978865e7379feee27bc Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 19 Feb 2021 17:21:05 -0500 Subject: [PATCH 24/80] Eyy! fix bug 14, send button and ok button not working together --- Adventure Game/adventure_game/GameNavigator.py | 4 ++-- Adventure Game/adventure_game/player.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/player.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index a342861..143430c 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -4,9 +4,9 @@ class ExitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class GameNavigator(npyscreen.Form): +class GameNavigator(npyscreen.FormBaseNew): def afterEditing(self): - self.parentApp.setNextForm(None) # Nothing to do after this but exit the game. + self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 diff --git a/Adventure Game/adventure_game/player.py b/Adventure Game/adventure_game/player.py new file mode 100644 index 0000000..81620ec --- /dev/null +++ b/Adventure Game/adventure_game/player.py @@ -0,0 +1,7 @@ +from yaml_parser import parse_datafile as parse + +class Player: + def __init__(self, save_location): + self.save_location = save_location + + self.playerData = parse(save_location) \ No newline at end of file -- 2.43.0 From 7eb8dfde07460ee9b6618bd2fb85a645754b123e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sat, 20 Feb 2021 18:53:44 -0500 Subject: [PATCH 25/80] Basic UI should work fine now! TODO: slight bug with send button not 'clearing' screen? --- .../adventure_game/GameNavigator.py | 26 ++++++++++++++----- Adventure Game/adventure_game/MainMenu.py | 11 ++++++++ Adventure Game/adventure_game/Player.py | 11 ++++++++ Adventure Game/adventure_game/main.py | 22 +++++++--------- Adventure Game/adventure_game/player.py | 7 ----- .../playerdata/defaults/default_player.yaml | 4 +++ 6 files changed, 55 insertions(+), 26 deletions(-) create mode 100644 Adventure Game/adventure_game/MainMenu.py create mode 100644 Adventure Game/adventure_game/Player.py delete mode 100644 Adventure Game/adventure_game/player.py create mode 100644 Adventure Game/adventure_game/playerdata/defaults/default_player.yaml diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 143430c..81fd744 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -1,12 +1,18 @@ -import npyscreen, sys +import npyscreen +import sys -class ExitButton(npyscreen.ButtonPress): + +class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) +class SendButton(npyscreen.ButtonPress): + def whenPressed(self): + self.parent.parentApp.switchForm('GAME') + class GameNavigator(npyscreen.FormBaseNew): - def afterEditing(self): - self.parentApp.setNextForm('GAME') +# def afterEditing(self): +#it self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 @@ -41,7 +47,8 @@ class GameNavigator(npyscreen.FormBaseNew): max_width=inventory_width + art_width, max_height=3, relx=1, - rely=top_division_height + 2) + rely=top_division_height + 2, + editable=False) self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', @@ -50,4 +57,11 @@ class GameNavigator(npyscreen.FormBaseNew): relx=2, rely=top_division_height + 3) - self.tryAction = self.add(ExitButton, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3) \ No newline at end of file + self.sendButton = self.add(SendButton, + name="Send", + relx=inventory_width + art_width - 7, + rely=top_division_height + 3) + self.quitButton = self.add(QuitButton, + name="Quit", + relx=1, + rely=1) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py new file mode 100644 index 0000000..7afc67d --- /dev/null +++ b/Adventure Game/adventure_game/MainMenu.py @@ -0,0 +1,11 @@ +import npyscreen + +class MainMenu(npyscreen.Form): + def afterEditing(self): + # TODO: the game needs to happen after this inital main menu + self.parentApp.setNextForm('GAME') + + def create(self): + self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) + self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") + self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py new file mode 100644 index 0000000..b27cb37 --- /dev/null +++ b/Adventure Game/adventure_game/Player.py @@ -0,0 +1,11 @@ +from yaml_parser import parse_datafile as parse + +class Player: + """ + This class intended to abstract out the actual yaml data into a player.(item) that is more + friendly to handle in code. + """ + def __init__(self, save_location): + self.save_location = save_location + + self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index e99b86b..092fedb 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -1,20 +1,11 @@ -import npyscreen, sys +import npyscreen from npyscreen import NotEnoughSpaceForWidget from os import system from yaml_parser import parse_datafile as parse from GameNavigator import GameNavigator - - -class MainMenu(npyscreen.Form): - def afterEditing(self): - # TODO: the game needs to happen after this inital main menu - self.parentApp.setNextForm('GAME') - - def create(self): - self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) - self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") - self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) +from MainMenu import MainMenu +from Player import Player class AlphaWarning(npyscreen.Popup): @@ -33,7 +24,9 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu - self.playerSaveLocation = None # We'll load the save location after the player gets to the save select screen + self.playerSaveLocation = 'playerdata/defaults/default_player.yaml' #TODO: Actually load the player data + + self.player = Player(self.playerSaveLocation) # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] @@ -50,6 +43,9 @@ class AdventureGame(npyscreen.NPSAppManaged): if __name__ == '__main__': + # Set the screen size bigger + system('mode con: cols={0} lines={1}'.format(124, 30)) + # Make a new adventure game if not imported adventure_game = AdventureGame() diff --git a/Adventure Game/adventure_game/player.py b/Adventure Game/adventure_game/player.py deleted file mode 100644 index 81620ec..0000000 --- a/Adventure Game/adventure_game/player.py +++ /dev/null @@ -1,7 +0,0 @@ -from yaml_parser import parse_datafile as parse - -class Player: - def __init__(self, save_location): - self.save_location = save_location - - self.playerData = parse(save_location) \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml new file mode 100644 index 0000000..811f696 --- /dev/null +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -0,0 +1,4 @@ +player: + name: 'Default' + location: 'office' + inventory: ['test', 'test2'] \ No newline at end of file -- 2.43.0 From eb70e4a438288424b65c65ab0eb03ebfdb568a53 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:07:14 -0500 Subject: [PATCH 26/80] Organize where the player() is initalized --- Adventure Game/adventure_game/MainMenu.py | 6 ++++++ Adventure Game/adventure_game/main.py | 4 +--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 7afc67d..3943b0c 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -1,5 +1,9 @@ import npyscreen + +from Player import Player + + class MainMenu(npyscreen.Form): def afterEditing(self): # TODO: the game needs to happen after this inital main menu @@ -8,4 +12,6 @@ class MainMenu(npyscreen.Form): def create(self): self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") + + self.parentApp.player = Player('playerdata/defaults/default_player.yaml') self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 092fedb..ff04146 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -5,7 +5,6 @@ from os import system from yaml_parser import parse_datafile as parse from GameNavigator import GameNavigator from MainMenu import MainMenu -from Player import Player class AlphaWarning(npyscreen.Popup): @@ -24,9 +23,8 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup some important 'global' values we'll need later self.gamelib = parse( 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu - self.playerSaveLocation = 'playerdata/defaults/default_player.yaml' #TODO: Actually load the player data - self.player = Player(self.playerSaveLocation) + self.player = None # Intalize the player as none, the player will be created in the main menu. # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] -- 2.43.0 From fa0c2cac9e982e82dd7332567c52d1edf01efc92 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:07:20 -0500 Subject: [PATCH 27/80] handle a redraw! --- Adventure Game/adventure_game/GameNavigator.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 81fd744..7e90d40 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -8,12 +8,17 @@ class QuitButton(npyscreen.ButtonPress): class SendButton(npyscreen.ButtonPress): def whenPressed(self): - self.parent.parentApp.switchForm('GAME') + self.parent.artContent.value = 'Undraw!' + #self.parent.parentApp.switchForm('GAME') + self.parent.artContent.display() class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): #it self.parentApp.setNextForm('GAME') + def render(self): + self.artContent.value = 'Undraw!' + def create(self): top_division_height = 20 inventory_width = 20 -- 2.43.0 From 5fb78fece87d1656ed52c6ad89078856cec7f988 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:15:26 -0500 Subject: [PATCH 28/80] Move around/clean up game renderer Also add space for log window --- .../adventure_game/GameNavigator.py | 23 +++++++++---------- Adventure Game/adventure_game/main.py | 8 +++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 7e90d40..77803f8 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -6,18 +6,17 @@ class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class SendButton(npyscreen.ButtonPress): + +class Render(npyscreen.ButtonPress): def whenPressed(self): self.parent.artContent.value = 'Undraw!' - #self.parent.parentApp.switchForm('GAME') self.parent.artContent.display() + self.parent.parentApp.switchForm('GAME') + class GameNavigator(npyscreen.FormBaseNew): -# def afterEditing(self): -#it self.parentApp.setNextForm('GAME') - - def render(self): - self.artContent.value = 'Undraw!' + # def afterEditing(self): + # it self.parentApp.setNextForm('GAME') def create(self): top_division_height = 20 @@ -52,20 +51,20 @@ class GameNavigator(npyscreen.FormBaseNew): max_width=inventory_width + art_width, max_height=3, relx=1, - rely=top_division_height + 2, + rely=top_division_height + 2 + 9, editable=False) self.dialogueBox = self.add(npyscreen.Textfield, name='Type Here', - max_width=inventory_width + art_width - 7, + max_width=inventory_width + art_width - 14, max_height=1, relx=2, - rely=top_division_height + 3) + rely=top_division_height + 3 + 9) - self.sendButton = self.add(SendButton, + self.sendButton = self.add(Render, name="Send", relx=inventory_width + art_width - 7, - rely=top_division_height + 3) + rely=top_division_height + 3 + 9) self.quitButton = self.add(QuitButton, name="Quit", relx=1, diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index ff04146..741a2e1 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -28,9 +28,9 @@ class AdventureGame(npyscreen.NPSAppManaged): # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] - system('mode con: cols={0} lines={1}'.format( - dimensions['inventory_width']+dimensions['art_width'], - 30)) # TODO: Finish setting this up. + #system('mode con: cols={0} lines={1}'.format( + # dimensions['inventory_width']+dimensions['art_width'], + # 30)) # TODO: Finish setting this up. # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game @@ -42,7 +42,7 @@ class AdventureGame(npyscreen.NPSAppManaged): if __name__ == '__main__': # Set the screen size bigger - system('mode con: cols={0} lines={1}'.format(124, 30)) + system('mode con: cols={0} lines={1}'.format(124, 36)) # Make a new adventure game if not imported adventure_game = AdventureGame() -- 2.43.0 From fa3e73498def8bb11bb8c6a05876aac21b5e2672 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 17:17:19 -0500 Subject: [PATCH 29/80] Add in log window! --- Adventure Game/adventure_game/GameNavigator.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 77803f8..620d33c 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -47,6 +47,21 @@ class GameNavigator(npyscreen.FormBaseNew): rely=2, editable=False) + self.logBoxOutline = self.add(npyscreen.BoxBasic, + max_width=inventory_width + art_width, + max_height=9, + relx=1, + rely=top_division_height + 2, + editable=False) + + self.logBox = self.add(npyscreen.Textfield, + name='Type Here', + max_width=inventory_width + art_width - 7, + max_height=7, + relx=2, + rely=top_division_height + 3, + editable=False) + self.dialogueBoxOutline = self.add(npyscreen.BoxBasic, max_width=inventory_width + art_width, max_height=3, -- 2.43.0 From 2dd8b15a9d7f82ce5406abe525ca257a0057cced Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Sun, 21 Feb 2021 20:20:05 -0500 Subject: [PATCH 30/80] fix this bit --- Adventure Game/adventure_game/GameNavigator.py | 12 +++--------- Adventure Game/adventure_game/handler.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 9 deletions(-) create mode 100644 Adventure Game/adventure_game/handler.py diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 620d33c..44ba48e 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -1,19 +1,14 @@ import npyscreen import sys +from Handler import Handler + class QuitButton(npyscreen.ButtonPress): def whenPressed(self): sys.exit(0) -class Render(npyscreen.ButtonPress): - def whenPressed(self): - self.parent.artContent.value = 'Undraw!' - self.parent.artContent.display() - self.parent.parentApp.switchForm('GAME') - - class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): # it self.parentApp.setNextForm('GAME') @@ -55,7 +50,6 @@ class GameNavigator(npyscreen.FormBaseNew): editable=False) self.logBox = self.add(npyscreen.Textfield, - name='Type Here', max_width=inventory_width + art_width - 7, max_height=7, relx=2, @@ -76,7 +70,7 @@ class GameNavigator(npyscreen.FormBaseNew): relx=2, rely=top_division_height + 3 + 9) - self.sendButton = self.add(Render, + self.sendButton = self.add(Handler, name="Send", relx=inventory_width + art_width - 7, rely=top_division_height + 3 + 9) diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/handler.py new file mode 100644 index 0000000..874cb99 --- /dev/null +++ b/Adventure Game/adventure_game/handler.py @@ -0,0 +1,15 @@ +import npyscreen + + +class Handler(npyscreen.ButtonPress): + """ + Very important, called when the player hits send, there are several things we need to do here: + 1: handle the player's input, and run logic, this is done in handler.py + 2: prepare new items to display on the screen + 3: re-render the screen + """ + def whenPressed(self): + self.parent.logBox.value = self.parent.dialogueBox.value + self.parent.dialogueBox.value = '' + self.parent.artContent.display() + self.parent.parentApp.switchForm('GAME') \ No newline at end of file -- 2.43.0 From b396cee469dac703b81d87b4d66deebf40d9d9da Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 16:48:01 -0500 Subject: [PATCH 31/80] Logbox echo works! --- Adventure Game/adventure_game/GameNavigator.py | 14 +++++++++++++- Adventure Game/adventure_game/handler.py | 4 ++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 44ba48e..b80c284 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -13,10 +13,22 @@ class GameNavigator(npyscreen.FormBaseNew): # def afterEditing(self): # it self.parentApp.setNextForm('GAME') + def update_log(self, newline): + self.logList.append(newline) # Append the newline + self.logList = self.logList[-7:] # Truncate to only the last 5 lines + + res = '' # Convert the list to a string + for element in self.logList: + res = res + str(element) + '\n' + res = res.upper() # Log is always uppercase + + self.logBox.value = res # Set the logbox to that value + def create(self): top_division_height = 20 inventory_width = 20 art_width = 100 + self.logList = [] self.artBox = self.add(npyscreen.BoxBasic, name='ArtBox', @@ -49,7 +61,7 @@ class GameNavigator(npyscreen.FormBaseNew): rely=top_division_height + 2, editable=False) - self.logBox = self.add(npyscreen.Textfield, + self.logBox = self.add(npyscreen.MultiLineEdit, max_width=inventory_width + art_width - 7, max_height=7, relx=2, diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/handler.py index 874cb99..c12c38a 100644 --- a/Adventure Game/adventure_game/handler.py +++ b/Adventure Game/adventure_game/handler.py @@ -9,7 +9,7 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): - self.parent.logBox.value = self.parent.dialogueBox.value + self.parent.update_log(self.parent.dialogueBox.value) self.parent.dialogueBox.value = '' self.parent.artContent.display() - self.parent.parentApp.switchForm('GAME') \ No newline at end of file + self.parent.parentApp.switchForm('GAME') -- 2.43.0 From b55bcf77b8b762b7505f8329bd9eeed66276b999 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 16:59:45 -0500 Subject: [PATCH 32/80] Replace some helptext --- Adventure Game/adventure_game/GameNavigator.py | 9 +++++++-- Adventure Game/adventure_game/MainMenu.py | 4 ++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index b80c284..c24e3f2 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -10,8 +10,13 @@ class QuitButton(npyscreen.ButtonPress): class GameNavigator(npyscreen.FormBaseNew): - # def afterEditing(self): - # it self.parentApp.setNextForm('GAME') + """ + This class handles all the drawing and 'graphics' of our game. + only basic logic like initial loading should happen here. re-drawing + and game logic should be done in Handler.py + TODO: Find a fix for initial room startup + TODO: Find a way to reset the cursor after a user hits sendButton + """ def update_log(self, newline): self.logList.append(newline) # Append the newline diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 3943b0c..02ec615 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -5,6 +5,10 @@ from Player import Player class MainMenu(npyscreen.Form): + """ + This is the main menu, code here should only be for + initializing the player data and any settings they want to change + """ def afterEditing(self): # TODO: the game needs to happen after this inital main menu self.parentApp.setNextForm('GAME') -- 2.43.0 From 8b3dba02cc5e512afb17219a3fe4a8e2a9bc8aae Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 19:46:39 -0500 Subject: [PATCH 33/80] Experiment with themes --- Adventure Game/adventure_game/main.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/main.py index 741a2e1..286b32d 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/main.py @@ -32,6 +32,10 @@ class AdventureGame(npyscreen.NPSAppManaged): # dimensions['inventory_width']+dimensions['art_width'], # 30)) # TODO: Finish setting this up. + # Set theme + #TODO: modify custom theme? + npyscreen.setTheme(npyscreen.Themes.ElegantTheme) + # Draw game windows self.addForm('GAME', GameNavigator, name='Unnamed Adventure Game') # This window should draw the actual game self.addForm('MENU', MainMenu, name='Welcome to the main menu') # This window should draw the main menu -- 2.43.0 From 5ba6a20f1324321c12dc3895ff09248d6839522b Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:11:47 -0500 Subject: [PATCH 34/80] Update Handler.py How was this not fixed? --- Adventure Game/adventure_game/{handler.py => Handler.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Adventure Game/adventure_game/{handler.py => Handler.py} (100%) diff --git a/Adventure Game/adventure_game/handler.py b/Adventure Game/adventure_game/Handler.py similarity index 100% rename from Adventure Game/adventure_game/handler.py rename to Adventure Game/adventure_game/Handler.py -- 2.43.0 From 832e26232b9863542e51bff5dc08ca0cbb6d8d1f Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 20:17:54 -0500 Subject: [PATCH 35/80] Modualerize! --- Adventure Game/adventure_game/MainMenu.py | 2 +- .../adventure_game/{main.py => __main__.py} | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) rename Adventure Game/adventure_game/{main.py => __main__.py} (84%) diff --git a/Adventure Game/adventure_game/MainMenu.py b/Adventure Game/adventure_game/MainMenu.py index 02ec615..b01614b 100644 --- a/Adventure Game/adventure_game/MainMenu.py +++ b/Adventure Game/adventure_game/MainMenu.py @@ -17,5 +17,5 @@ class MainMenu(npyscreen.Form): self.add(npyscreen.FixedText, value='You cannot select a file yet! Just hit OK', editable=False) self.playerSaveLocation = self.add(npyscreen.TitleFilenameCombo, name="Your save file:") - self.parentApp.player = Player('playerdata/defaults/default_player.yaml') + self.parentApp.player = Player(self.parentApp.mainPath / 'playerdata/defaults/default_player.yaml') self.add(npyscreen.MultiLineEdit, value=self.parentApp.gamelib['menu']['graphics']['logo'], editable=False) \ No newline at end of file diff --git a/Adventure Game/adventure_game/main.py b/Adventure Game/adventure_game/__main__.py similarity index 84% rename from Adventure Game/adventure_game/main.py rename to Adventure Game/adventure_game/__main__.py index 286b32d..f035b1a 100644 --- a/Adventure Game/adventure_game/main.py +++ b/Adventure Game/adventure_game/__main__.py @@ -1,3 +1,4 @@ +import pathlib import npyscreen from npyscreen import NotEnoughSpaceForWidget from os import system @@ -21,10 +22,17 @@ class AdventureGame(npyscreen.NPSAppManaged): # Do on creation def onStart(self): # Setup some important 'global' values we'll need later + # Set the path all other files will follow + self.mainPath = pathlib.Path(__file__).parent + + # Parse world self.gamelib = parse( - 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + + # Intalize the player as none, the player will be created in the main menu. + self.player = None + - self.player = None # Intalize the player as none, the player will be created in the main menu. # Set screen size before drawing windows dimensions = self.gamelib['menu']['graphics']['dimensions'] -- 2.43.0 From 9fc4ed130c05c3625d506beca1b640bb15e7aa0d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:38 -0500 Subject: [PATCH 36/80] Add error handling to handler --- Adventure Game/adventure_game/Handler.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index c12c38a..fb4cc49 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -9,7 +9,20 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): - self.parent.update_log(self.parent.dialogueBox.value) + # This is the raw command from the user + raw_command = self.parent.dialogueBox.value + + # This is the raw command from the user + parsed_command = raw_command.split() + + try: + command = parsed_command.pop(0) + except IndexError: + pass + arguments = parsed_command + + self.parent.update_log('command: ' + command) + self.parent.update_log('args: {0}'.format(arguments)) self.parent.dialogueBox.value = '' self.parent.artContent.display() self.parent.parentApp.switchForm('GAME') -- 2.43.0 From e32e9895e5da0340188306a0c7814b173246e8b8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:49 -0500 Subject: [PATCH 37/80] Prepare logging! --- Adventure Game/adventure_game/__main__.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index f035b1a..7422f06 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -1,5 +1,6 @@ import pathlib import npyscreen +import logging from npyscreen import NotEnoughSpaceForWidget from os import system @@ -19,12 +20,19 @@ class AlphaWarning(npyscreen.Popup): class AdventureGame(npyscreen.NPSAppManaged): + """ + This is the 'root' of the entire game! + """ # Do on creation def onStart(self): # Setup some important 'global' values we'll need later # Set the path all other files will follow self.mainPath = pathlib.Path(__file__).parent - + + # Setup logging + self.log = logging + self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', filemode='w', level=logging.DEBUG) + # Parse world self.gamelib = parse( self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu -- 2.43.0 From e58af07b5e28da46c26c872383a8eda711eb3c2a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:30:53 -0500 Subject: [PATCH 38/80] Create AdventureGame.log --- Adventure Game/adventure_game/logs/AdventureGame.log | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Adventure Game/adventure_game/logs/AdventureGame.log diff --git a/Adventure Game/adventure_game/logs/AdventureGame.log b/Adventure Game/adventure_game/logs/AdventureGame.log new file mode 100644 index 0000000..e69de29 -- 2.43.0 From 87fdc6b91ea45e9f3c145c3730b9985524f30604 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:07 -0500 Subject: [PATCH 39/80] Add log to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 11e2a47..46b3e76 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *.pyc -.idea \ No newline at end of file +.idea +Adventure Game/adventure_game/logs/AdventureGame.log -- 2.43.0 From 0c1770ef0ace5cb9b9789309ac2e9932877dd435 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:20 -0500 Subject: [PATCH 40/80] add some extra verbose logging to __main__ --- Adventure Game/adventure_game/__main__.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index 7422f06..64ca805 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -31,11 +31,15 @@ class AdventureGame(npyscreen.NPSAppManaged): # Setup logging self.log = logging - self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', filemode='w', level=logging.DEBUG) + self.log.basicConfig(filename=self.mainPath / 'logs/AdventureGame.log', + filemode='w', + level=logging.DEBUG) + self.log.info('Logging started!') - # Parse world + # parse this data first (since it includes graphics for the main menu self.gamelib = parse( - self.mainPath / 'gamedata/gamelib.yaml') # parse this data first (since it includes graphics for the main menu + self.mainPath / 'gamedata/gamelib.yaml') + self.log.debug('Gamelib at {0}'.format(self.mainPath / 'gamedata/gamelib.yaml')) # Intalize the player as none, the player will be created in the main menu. self.player = None -- 2.43.0 From cc0f6f9f9eff2a858cbb1596461811534be11ed7 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:48:33 -0500 Subject: [PATCH 41/80] Clean up logging in handler.py --- Adventure Game/adventure_game/Handler.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index fb4cc49..78ac1a7 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -9,8 +9,10 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ def whenPressed(self): + self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user raw_command = self.parent.dialogueBox.value + self.parent.dialogueBox.value = '' # Clear the dialogue box, TODO: This may become unneeded if issue #8 is fixed # This is the raw command from the user parsed_command = raw_command.split() @@ -18,11 +20,12 @@ class Handler(npyscreen.ButtonPress): try: command = parsed_command.pop(0) except IndexError: - pass - arguments = parsed_command + self.parent.parentApp.log.warn('Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) + command = '' + arguments = parsed_command # Whatever is left in the list, are arguments. + self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) self.parent.update_log('command: ' + command) self.parent.update_log('args: {0}'.format(arguments)) - self.parent.dialogueBox.value = '' self.parent.artContent.display() self.parent.parentApp.switchForm('GAME') -- 2.43.0 From aaf4842b0b0c336933628a1d9a720d9c7ab8efaa Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:41:17 -0500 Subject: [PATCH 42/80] Update alpha warning --- Adventure Game/adventure_game/__main__.py | 8 ++++++-- Adventure Game/adventure_game/logs/AdventureGame.log | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index 64ca805..9532fde 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -15,8 +15,12 @@ class AlphaWarning(npyscreen.Popup): def create(self): self.add(npyscreen.Pager, values=['Welcome to Unnamed Adventure game!', - 'Please enjoy your stay and report any bugs at', - 'kitsunehosting.net'], editable=False) + 'This game is still in ALPHA! And a TON', + 'of features are not implemented.', + 'Please check out the git project for', + 'details and updates! and please report', + 'any bugs! Thank you and enjoy!', + 'https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues'], editable=False) class AdventureGame(npyscreen.NPSAppManaged): diff --git a/Adventure Game/adventure_game/logs/AdventureGame.log b/Adventure Game/adventure_game/logs/AdventureGame.log index e69de29..db24599 100644 --- a/Adventure Game/adventure_game/logs/AdventureGame.log +++ b/Adventure Game/adventure_game/logs/AdventureGame.log @@ -0,0 +1,2 @@ +INFO:root:Logging started! +DEBUG:root:Gamelib at adventure_game\gamedata\gamelib.yaml -- 2.43.0 From f0f7c40617c4862020d93ae6a3f3269ba9142b0b Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:42:24 -0500 Subject: [PATCH 43/80] Update the alpha warning again --- Adventure Game/adventure_game/__main__.py | 15 ++++++++------- .../adventure_game/logs/AdventureGame.log | 3 +++ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index 9532fde..28aec21 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -14,13 +14,14 @@ class AlphaWarning(npyscreen.Popup): self.parentApp.setNextForm('MENU') def create(self): - self.add(npyscreen.Pager, values=['Welcome to Unnamed Adventure game!', - 'This game is still in ALPHA! And a TON', - 'of features are not implemented.', - 'Please check out the git project for', - 'details and updates! and please report', - 'any bugs! Thank you and enjoy!', - 'https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues'], editable=False) + self.add(npyscreen.MultiLineEdit, value="""Welcome to Unnamed Adventure game! +This game is still in ALPHA! And a TON +of features are not implemented. +Please check out the git project for +details and updates! and please report +any bugs! Thank you and enjoy! +https://kitsunehosting.net/gitea/Kenwood/SNHU-IT-140/issues""", + editable=False) class AdventureGame(npyscreen.NPSAppManaged): diff --git a/Adventure Game/adventure_game/logs/AdventureGame.log b/Adventure Game/adventure_game/logs/AdventureGame.log index db24599..af934e6 100644 --- a/Adventure Game/adventure_game/logs/AdventureGame.log +++ b/Adventure Game/adventure_game/logs/AdventureGame.log @@ -1,2 +1,5 @@ INFO:root:Logging started! DEBUG:root:Gamelib at adventure_game\gamedata\gamelib.yaml +DEBUG:root:Send button pressed! +WARNING:root:Command "" could not be split, was it malformed or incomplete? +INFO:root:Parsed command "" with arguments "[]" -- 2.43.0 From 5184bd9121f258d0b171d153f2cb4ec72bf595d2 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:53:27 -0500 Subject: [PATCH 44/80] Add some more handling for commands --- Adventure Game/adventure_game/Handler.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 78ac1a7..860bb65 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -22,10 +22,22 @@ class Handler(npyscreen.ButtonPress): except IndexError: self.parent.parentApp.log.warn('Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) command = '' - arguments = parsed_command # Whatever is left in the list, are arguments. + arguments = parsed_command # Whatever is left in the list, are arguments. + # Handle an empty command + if len(command) <= 2: + self.parent.update_log('Command was too short, try something like "MOVE", "PICK UP" or "USE".') + + else: + # Concatenate everything back together (just to show the user the program understood them correctly + self.parent.update_log(command + ' ' + ' '.join(str(s) for s in arguments)) + + # Log the command that we parsed self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) - self.parent.update_log('command: ' + command) - self.parent.update_log('args: {0}'.format(arguments)) + + # Make sure to re-draw the art box when we're all done (in case we updated it in logic above) self.parent.artContent.display() + + # Switch back to the game menu. + #TODO: possibly deprecate this statement? self.parent.parentApp.switchForm('GAME') -- 2.43.0 From 6c162e42b40929744ee81a6387631b856d7f9c64 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Tue, 23 Feb 2021 23:59:06 -0500 Subject: [PATCH 45/80] handler is aware of player data --- Adventure Game/adventure_game/Handler.py | 13 ++++++++++++- Adventure Game/adventure_game/__main__.py | 3 +-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 860bb65..1919dca 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -12,7 +12,9 @@ class Handler(npyscreen.ButtonPress): self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user raw_command = self.parent.dialogueBox.value - self.parent.dialogueBox.value = '' # Clear the dialogue box, TODO: This may become unneeded if issue #8 is fixed + + # Clear the dialogue box, TODO: This may become unneeded if issue #8 is fixed + self.parent.dialogueBox.value = '' # This is the raw command from the user parsed_command = raw_command.split() @@ -32,6 +34,15 @@ class Handler(npyscreen.ButtonPress): # Concatenate everything back together (just to show the user the program understood them correctly self.parent.update_log(command + ' ' + ' '.join(str(s) for s in arguments)) + """ + This is where real logic can happen! + """ + + # Localize the player + player = self.parent.parentApp.player + room = player.playerData['player']['location'] # This is ugly, and should point to the room's name and not the system name + self.parent.update_log('You are in {0}.'.format(room)) + # Log the command that we parsed self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) diff --git a/Adventure Game/adventure_game/__main__.py b/Adventure Game/adventure_game/__main__.py index 28aec21..6ea3e1b 100644 --- a/Adventure Game/adventure_game/__main__.py +++ b/Adventure Game/adventure_game/__main__.py @@ -42,8 +42,7 @@ class AdventureGame(npyscreen.NPSAppManaged): self.log.info('Logging started!') # parse this data first (since it includes graphics for the main menu - self.gamelib = parse( - self.mainPath / 'gamedata/gamelib.yaml') + self.gamelib = parse(self.mainPath / 'gamedata/gamelib.yaml') self.log.debug('Gamelib at {0}'.format(self.mainPath / 'gamedata/gamelib.yaml')) # Intalize the player as none, the player will be created in the main menu. -- 2.43.0 From 56f3fb2feeeb12c593a7f1134a58113a208d840b Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:02:33 -0500 Subject: [PATCH 46/80] Handler can load the current room! --- Adventure Game/adventure_game/Handler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 1919dca..10cad2b 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -1,5 +1,7 @@ import npyscreen +from yaml_parser import parse_datafile as parse + class Handler(npyscreen.ButtonPress): """ @@ -40,7 +42,8 @@ class Handler(npyscreen.ButtonPress): # Localize the player player = self.parent.parentApp.player - room = player.playerData['player']['location'] # This is ugly, and should point to the room's name and not the system name + roomlocation = player.playerData['player']['location'] + '.yaml' + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) self.parent.update_log('You are in {0}.'.format(room)) # Log the command that we parsed -- 2.43.0 From 773d48b7324dd6b794891402cbdb0a25f16282a2 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:08:32 -0500 Subject: [PATCH 47/80] Handler can now log critical room load errors, --- Adventure Game/adventure_game/Handler.py | 10 +++++++++- .../adventure_game/gamedata/world/blank_room.yaml | 4 ++++ .../playerdata/defaults/default_player.yaml | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 Adventure Game/adventure_game/gamedata/world/blank_room.yaml diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 10cad2b..00ac1a2 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -43,7 +43,15 @@ class Handler(npyscreen.ButtonPress): # Localize the player player = self.parent.parentApp.player roomlocation = player.playerData['player']['location'] + '.yaml' - room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) + try: + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) + + # If the file could not be found + except FileNotFoundError: + # Log a critical error! + self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) + # Put the player in a blank room i forgot to finish + room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') self.parent.update_log('You are in {0}.'.format(room)) # Log the command that we parsed diff --git a/Adventure Game/adventure_game/gamedata/world/blank_room.yaml b/Adventure Game/adventure_game/gamedata/world/blank_room.yaml new file mode 100644 index 0000000..5302880 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/world/blank_room.yaml @@ -0,0 +1,4 @@ +blank_room: + grid: [-1, -1] + upon_enter: "You're in a blank room. It looks unfinished, like joe forgot to put something here" + look_around: "There is nothing to look at, you should tell joe you're here." \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml index 811f696..57088df 100644 --- a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -1,4 +1,4 @@ player: name: 'Default' - location: 'office' + location: 'officee' inventory: ['test', 'test2'] \ No newline at end of file -- 2.43.0 From 705a00fe9c5ec93fdfdd09a916c5e0d212b30254 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:09:07 -0500 Subject: [PATCH 48/80] look around is a better thing to suggest a user do --- Adventure Game/adventure_game/Handler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 00ac1a2..66a7797 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -30,7 +30,7 @@ class Handler(npyscreen.ButtonPress): # Handle an empty command if len(command) <= 2: - self.parent.update_log('Command was too short, try something like "MOVE", "PICK UP" or "USE".') + self.parent.update_log('Command was too short, try something like "MOVE", "LOOK AROUND" or "USE".') else: # Concatenate everything back together (just to show the user the program understood them correctly -- 2.43.0 From 4d85b25dab22362ade5f834efba46830f1cf0ee8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:10:44 -0500 Subject: [PATCH 49/80] commands should be compared to uppercase commands --- Adventure Game/adventure_game/Handler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 66a7797..1afe77d 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -13,7 +13,7 @@ class Handler(npyscreen.ButtonPress): def whenPressed(self): self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user - raw_command = self.parent.dialogueBox.value + raw_command = self.parent.dialogueBox.value.upper() # Clear the dialogue box, TODO: This may become unneeded if issue #8 is fixed self.parent.dialogueBox.value = '' @@ -52,7 +52,10 @@ class Handler(npyscreen.ButtonPress): self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) # Put the player in a blank room i forgot to finish room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') - self.parent.update_log('You are in {0}.'.format(room)) + + # By now we should be situated in our room, and with our player. + if command == '': + self.parent.update_log('You are in {0}.'.format(room)) # Log the command that we parsed self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) -- 2.43.0 From 234d03db60396cd2df0f9cb81b51ba467e1c4f01 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:17:43 -0500 Subject: [PATCH 50/80] =?UTF-8?q?Add=20a=20cute=20little=20carrot=20to=20t?= =?UTF-8?q?he=20player's=20log=20=E2=99=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Adventure Game/adventure_game/GameNavigator.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index c24e3f2..c32f50b 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -19,7 +19,7 @@ class GameNavigator(npyscreen.FormBaseNew): """ def update_log(self, newline): - self.logList.append(newline) # Append the newline + self.logList.append('> ' + newline) # Append the newline self.logList = self.logList[-7:] # Truncate to only the last 5 lines res = '' # Convert the list to a string -- 2.43.0 From 695fcca5220c0db984390c3370fd4d8dfa70b7be Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:20:11 -0500 Subject: [PATCH 51/80] Looking around works!! --- Adventure Game/adventure_game/Handler.py | 26 +++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 1afe77d..42b9e02 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -10,6 +10,7 @@ class Handler(npyscreen.ButtonPress): 2: prepare new items to display on the screen 3: re-render the screen """ + def whenPressed(self): self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user @@ -24,7 +25,8 @@ class Handler(npyscreen.ButtonPress): try: command = parsed_command.pop(0) except IndexError: - self.parent.parentApp.log.warn('Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) + self.parent.parentApp.log.warn( + 'Command "{0}" could not be split, was it malformed or incomplete?'.format(raw_command)) command = '' arguments = parsed_command # Whatever is left in the list, are arguments. @@ -44,17 +46,31 @@ class Handler(npyscreen.ButtonPress): player = self.parent.parentApp.player roomlocation = player.playerData['player']['location'] + '.yaml' try: - room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation) + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)[ + player.playerData['player']['location']] # If the file could not be found except FileNotFoundError: # Log a critical error! - self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) + self.parent.parentApp.log.critical( + 'Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format( + self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) # Put the player in a blank room i forgot to finish room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') # By now we should be situated in our room, and with our player. - if command == '': + self.parent.parentApp.log.debug(room) + + # TODO: Should upgrade these to use fuzzy words library! and not direct comparisons! + if command == 'LOOK': + if arguments[0] == 'AROUND': + try: + self.parent.update_log(room['look_around']) + except KeyError: + self.parent.update_log('There is nothing to look at?.. This might be a bug.') + + if command == 'WHERE': + # TODO: this should take the human readable room name, not the code-name self.parent.update_log('You are in {0}.'.format(room)) # Log the command that we parsed @@ -64,5 +80,5 @@ class Handler(npyscreen.ButtonPress): self.parent.artContent.display() # Switch back to the game menu. - #TODO: possibly deprecate this statement? + # TODO: possibly deprecate this statement? self.parent.parentApp.switchForm('GAME') -- 2.43.0 From 45b32528384847d9b68cd5a0cdb6f870d2c63193 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:20:20 -0500 Subject: [PATCH 52/80] Fixed error in the default player yaml --- .../adventure_game/playerdata/defaults/default_player.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml index 57088df..811f696 100644 --- a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -1,4 +1,4 @@ player: name: 'Default' - location: 'officee' + location: 'office' inventory: ['test', 'test2'] \ No newline at end of file -- 2.43.0 From 6f10d6420b9459f061018b4fb6044e23051cf17d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:28:47 -0500 Subject: [PATCH 53/80] Fixed looking at things --- Adventure Game/adventure_game/Handler.py | 6 ++++++ .../adventure_game/logs/AdventureGame.log | 13 +++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 42b9e02..a5350fa 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -68,6 +68,12 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log(room['look_around']) except KeyError: self.parent.update_log('There is nothing to look at?.. This might be a bug.') + if arguments[0] == 'AT': + try: + # Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it. + self.parent.update_log(room[arguments[1].lower()]['look_at']) + except KeyError: + self.parent.update_log("Not sure what you're trying to look at.") if command == 'WHERE': # TODO: this should take the human readable room name, not the code-name diff --git a/Adventure Game/adventure_game/logs/AdventureGame.log b/Adventure Game/adventure_game/logs/AdventureGame.log index af934e6..0ab50e5 100644 --- a/Adventure Game/adventure_game/logs/AdventureGame.log +++ b/Adventure Game/adventure_game/logs/AdventureGame.log @@ -1,5 +1,14 @@ INFO:root:Logging started! DEBUG:root:Gamelib at adventure_game\gamedata\gamelib.yaml DEBUG:root:Send button pressed! -WARNING:root:Command "" could not be split, was it malformed or incomplete? -INFO:root:Parsed command "" with arguments "[]" +DEBUG:root:{'grid': [0, 0], 'upon_enter': 'You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'look_around': 'You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|', 'pick_up_logviewer': 'You pick the *LOG VIEWER* up.', 'desk': {'look_at': 'You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'inspect': 'Desk, ornate, stuff'}, 'log_viewer': {'look_at': 'logviewer looks like garbo', 'inspect': 'beep boop', 'pick_up': 'You pick up the *LOG VIEWER*.'}} +INFO:root:Parsed command "LOOK" with arguments "['AROUND']" +DEBUG:root:Send button pressed! +DEBUG:root:{'grid': [0, 0], 'upon_enter': 'You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'look_around': 'You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|', 'pick_up_logviewer': 'You pick the *LOG VIEWER* up.', 'desk': {'look_at': 'You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'inspect': 'Desk, ornate, stuff'}, 'log_viewer': {'look_at': 'logviewer looks like garbo', 'inspect': 'beep boop', 'pick_up': 'You pick up the *LOG VIEWER*.'}} +INFO:root:Parsed command "LOOK" with arguments "['AT', 'DESK']" +DEBUG:root:Send button pressed! +DEBUG:root:{'grid': [0, 0], 'upon_enter': 'You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'look_around': 'You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|', 'pick_up_logviewer': 'You pick the *LOG VIEWER* up.', 'desk': {'look_at': 'You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'inspect': 'Desk, ornate, stuff'}, 'log_viewer': {'look_at': 'logviewer looks like garbo', 'inspect': 'beep boop', 'pick_up': 'You pick up the *LOG VIEWER*.'}} +INFO:root:Parsed command "LOOK" with arguments "['AT', 'DOOR']" +DEBUG:root:Send button pressed! +DEBUG:root:{'grid': [0, 0], 'upon_enter': 'You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'look_around': 'You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|', 'pick_up_logviewer': 'You pick the *LOG VIEWER* up.', 'desk': {'look_at': 'You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|', 'inspect': 'Desk, ornate, stuff'}, 'log_viewer': {'look_at': 'logviewer looks like garbo', 'inspect': 'beep boop', 'pick_up': 'You pick up the *LOG VIEWER*.'}} +INFO:root:Parsed command "LOOK" with arguments "['AT', 'BOOKSHELF']" -- 2.43.0 From 392808409849f03463026e7a0504f2f5b82693c0 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:37:54 -0500 Subject: [PATCH 54/80] Player can pick up items but cannot yet add them to the inventory. --- Adventure Game/adventure_game/Handler.py | 17 +++++++++++++++++ .../adventure_game/gamedata/world/office.yaml | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index a5350fa..6580229 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -75,6 +75,23 @@ class Handler(npyscreen.ButtonPress): except KeyError: self.parent.update_log("Not sure what you're trying to look at.") + if command == 'PICK': + if arguments[0] == 'UP': + if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + try: + # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. + self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) + self.parent.update_log(room[arguments[1].lower()]['pick_up']) + except KeyError: + self.parent.update_log("You cant pick that up.") + else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer + try: + long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between + self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) + self.parent.update_log(room[long_arg.lower()]['pick_up']) + except KeyError: + self.parent.update_log("You cant pick that up.") + if command == 'WHERE': # TODO: this should take the human readable room name, not the code-name self.parent.update_log('You are in {0}.'.format(room)) diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index 3d88078..d6c17e7 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -7,6 +7,6 @@ office: look_at: "You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" inspect: "Desk, ornate, stuff" log_viewer: - look_at: "logviewer looks like garbo" + look_at: "log viewer looks like garbo" inspect: "beep boop" pick_up: "You pick up the *LOG VIEWER*." \ No newline at end of file -- 2.43.0 From 0d58881e94b443ddebf4d37fa87dff4cfec884e6 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 00:57:28 -0500 Subject: [PATCH 55/80] add some todos --- Adventure Game/adventure_game/GameNavigator.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index c32f50b..c81e75e 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -95,3 +95,12 @@ class GameNavigator(npyscreen.FormBaseNew): name="Quit", relx=1, rely=1) + + """ + We've reached end of __init__ basicly by this point + its up to Handler.py to actually play the game, but we should + do some basic initalization here + """ + #TODO: load art from the last place the player was in + #TODO: load up inventory + #TODO: loadup enter_text -- 2.43.0 From 9fa60fe4044593660d78df552c1046400fea66b8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 01:00:38 -0500 Subject: [PATCH 56/80] Add dev note and welcome back/starter text --- Adventure Game/adventure_game/GameNavigator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index c81e75e..b986b47 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -103,4 +103,8 @@ class GameNavigator(npyscreen.FormBaseNew): """ #TODO: load art from the last place the player was in #TODO: load up inventory - #TODO: loadup enter_text + + #TODO: Expand this by loding the text from the game + #WARN: THIS MAY REQUIRE REWRITING HANDLER.PY TO INTALIZE THE ROOM OBJECT OUTSIDE OF HANDLER.PY + self.update_log('Welcome back! Try "LOOK AROUND" to get started.') + self.update_log('>>Note from joe: Welcome! you\'re playing the demo! Please dont mind text issues like |this| and *this*\ni have yet to implement color!') -- 2.43.0 From 4c6e3a51afa0cc961fbaba63de9bd21042c235d3 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 01:13:28 -0500 Subject: [PATCH 57/80] Add some 'office art' --- .../adventure_game/gamedata/world/office.yaml | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index d6c17e7..4a67eb8 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -2,11 +2,30 @@ office: grid: [0, 0] upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|" - pick_up_logviewer: "You pick the *LOG VIEWER* up." desk: look_at: "You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" - inspect: "Desk, ornate, stuff" + inspect: "The desk is large and ornate with one of those silly lamps hovering over it." log_viewer: - look_at: "log viewer looks like garbo" - inspect: "beep boop" - pick_up: "You pick up the *LOG VIEWER*." \ No newline at end of file + item: yes + look_at: "The log viewer is a small piece of ornate code, allowing you to examine |entities| more closely." + inspect: "The dials are wiggly and the viewer makes Beep Boop sounds sometimes." + pick_up: "You pick up the *LOG VIEWER*." + art: | + + + + | | + | OFFICE STUFF? | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + + + -- 2.43.0 From 2b176aebdd2fbdb98fc90e84ea1e611342b74a3c Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 01:13:41 -0500 Subject: [PATCH 58/80] Make the default missing texture cuter --- .../adventure_game/gamedata/gamelib.yaml | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index d817750..cd3ae8d 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -13,24 +13,25 @@ menu: \____/_/ |_/_/ /_/_____/ not_found: | - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -----------------------------------------------/ \----------------------------------------------- - ----------------------------------------------/ !! \---------------------------------------------- - ---------------------------------------------/ \--------------------------------------------- - --------------------------------------No Art for this location------------------------------------ - ----------------------------------Consider making a pull request?--------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- - -------------------------------------------------------------------------------------------------- + +------------------------------------------------------------------------------------------------+ + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |---------------------------------------------+/ \+---------------------------------------------| + |--------------------------------------------+/ !! \+--------------------------------------------| + |-------------------------------------------+/ \+-------------------------------------------| + |------------------------------------+No Art for this location+----------------------------------| + |--------------------------------|Consider making a pull request?|-------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + |------------------------------------------------------------------------------------------------| + +------------------------------------------------------------------------------------------------+ + dimensions: inventory_width: 23 inventory_height: 20 -- 2.43.0 From 2d60766c0ffff9067532afe542acac7971068a19 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 01:19:48 -0500 Subject: [PATCH 59/80] Add missingno easteregg --- .../adventure_game/gamedata/gamelib.yaml | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index cd3ae8d..dfb77ea 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -13,21 +13,21 @@ menu: \____/_/ |_/_/ /_/_____/ not_found: | - +------------------------------------------------------------------------------------------------+ - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |---------------------------------------------+/ \+---------------------------------------------| - |--------------------------------------------+/ !! \+--------------------------------------------| - |-------------------------------------------+/ \+-------------------------------------------| - |------------------------------------+No Art for this location+----------------------------------| - |--------------------------------|Consider making a pull request?|-------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| - |------------------------------------------------------------------------------------------------| + +--------------------------------------------------------------------------------NNN0ddk0000kkX--+ + |--------------------------------------------------------------------------------N0OOkkkO0OkxON--| + |--------------------------------------------------------------------------------KkOkkkxkOxloON--| + |--------------------------------------------------------------------------------0xOO00000kdokX--| + |---------------------------------------------+/ \+-----------------------------XOxdddxdl:;cdX--| + |--------------------------------------------+/ !! \+----------------------------XOxoldxllc:oON--| + |-------------------------------------------+/ \+---------------------------0xkddkxdOxod0W--| + |------------------------------------+No Art for this location+------------------XkddkxodkxkxxX--| + |--------------------------------|Consider making a pull request?|---------NXXXKOOkxxxddodxkkOX--| + |--------------------------------------------------------------------------NXNNXxclddxkkxkOOO0N--| + |--------------------------------------------------------------------------XkxxxdddoxkkxkOkxkKW--| + |--------------------------------------------------------------------------KxxxxdollloodO0kkk0N--| + |--------------------------------------------------------------------------XkxxxdlclddkOOkk0OON--| + |--------------------------------------------------------------------------N0dooxdlcdkOkkkkxcoX--| + |--------------------------------------------------------------------------WXKKKKOOO0K0kxxxdodX--| |------------------------------------------------------------------------------------------------| |------------------------------------------------------------------------------------------------| +------------------------------------------------------------------------------------------------+ -- 2.43.0 From 1c4f962201dd111173f47363671085d9ea3699a8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 16:11:14 -0500 Subject: [PATCH 60/80] Add some more world --- .../adventure_game/gamedata/world/hallway.yaml | 11 +++++++++++ .../adventure_game/gamedata/world/office.yaml | 7 +++++++ 2 files changed, 18 insertions(+) create mode 100644 Adventure Game/adventure_game/gamedata/world/hallway.yaml diff --git a/Adventure Game/adventure_game/gamedata/world/hallway.yaml b/Adventure Game/adventure_game/gamedata/world/hallway.yaml new file mode 100644 index 0000000..a8bde34 --- /dev/null +++ b/Adventure Game/adventure_game/gamedata/world/hallway.yaml @@ -0,0 +1,11 @@ +office: + grid: [0, 1] + upon_enter: "You are standing just outside your office door." + look_around: "You look up, and down the hallway, you see the receptionists |desk|. And a |closet| at the other end of the hall." + closet: + look_at: "Its a closet door." + inspect: "Its still a closet door." + open: "You cant open this door." + desk: + look_at: "Its your receptionists desks, she's not sitting behind it." + inspect: "She's still not there." diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index 4a67eb8..6223826 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -5,11 +5,18 @@ office: desk: look_at: "You move to stand behind your desk. You see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" inspect: "The desk is large and ornate with one of those silly lamps hovering over it." + bookshelf: + look_at: "The bookshelf is a bookshelf." + inspect: "Its still a bookshelf." log_viewer: item: yes look_at: "The log viewer is a small piece of ornate code, allowing you to examine |entities| more closely." inspect: "The dials are wiggly and the viewer makes Beep Boop sounds sometimes." pick_up: "You pick up the *LOG VIEWER*." + door: + leads_to: hallway.yaml + look_at: "Its a door, it leads to the Hallway. You should try to |OPEN| it." + inspect: "Its ornate but basic, the other side of the door has your name on a plaque." art: | + + | | -- 2.43.0 From d1c85a7738456570a394c7c039fc67810de22328 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 16:14:20 -0500 Subject: [PATCH 61/80] Handle commands that dont match existing handlers --- Adventure Game/adventure_game/Handler.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 6580229..989adea 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -59,7 +59,6 @@ class Handler(npyscreen.ButtonPress): room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') # By now we should be situated in our room, and with our player. - self.parent.parentApp.log.debug(room) # TODO: Should upgrade these to use fuzzy words library! and not direct comparisons! if command == 'LOOK': @@ -75,7 +74,7 @@ class Handler(npyscreen.ButtonPress): except KeyError: self.parent.update_log("Not sure what you're trying to look at.") - if command == 'PICK': + elif command == 'PICK': if arguments[0] == 'UP': if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg try: @@ -91,6 +90,9 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log(room[long_arg.lower()]['pick_up']) except KeyError: self.parent.update_log("You cant pick that up.") + else: + self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) + self.parent.update_log('I didn\'t understand {0}'.format(command)) if command == 'WHERE': # TODO: this should take the human readable room name, not the code-name -- 2.43.0 From 1eb7f0b07b65936bb6a73aa8af602dbd3b44aa3e Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 16:14:30 -0500 Subject: [PATCH 62/80] Dont be quite as verbose --- Adventure Game/adventure_game/Handler.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 989adea..5b5a266 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -59,6 +59,7 @@ class Handler(npyscreen.ButtonPress): room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') # By now we should be situated in our room, and with our player. + #self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! # TODO: Should upgrade these to use fuzzy words library! and not direct comparisons! if command == 'LOOK': -- 2.43.0 From f400a4c7c36fe6ff3efd3cc3421054cd30f3b4fc Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Wed, 24 Feb 2021 16:16:03 -0500 Subject: [PATCH 63/80] Clean up handler --- Adventure Game/adventure_game/Handler.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 5b5a266..b8e02c4 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -59,7 +59,7 @@ class Handler(npyscreen.ButtonPress): room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') # By now we should be situated in our room, and with our player. - #self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! + # self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! # TODO: Should upgrade these to use fuzzy words library! and not direct comparisons! if command == 'LOOK': @@ -77,16 +77,17 @@ class Handler(npyscreen.ButtonPress): elif command == 'PICK': if arguments[0] == 'UP': - if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + if len( + arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg try: # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) self.parent.update_log(room[arguments[1].lower()]['pick_up']) except KeyError: self.parent.update_log("You cant pick that up.") - else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer + else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer try: - long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between + long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) self.parent.update_log(room[long_arg.lower()]['pick_up']) except KeyError: -- 2.43.0 From 377bb43e42cef2cad9b3d30d4fb141939d51e30d Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 20:45:49 -0500 Subject: [PATCH 64/80] Add (most) of a handler for OPEN command TODO: finish by updating the player locatio --- Adventure Game/adventure_game/GameNavigator.py | 7 +++++++ Adventure Game/adventure_game/Handler.py | 11 +++++++++++ Adventure Game/adventure_game/Player.py | 9 ++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index b986b47..9abc7d7 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -29,6 +29,13 @@ class GameNavigator(npyscreen.FormBaseNew): self.logBox.value = res # Set the logbox to that value + def update_location(self, location): + """ + This may not be needed in the future, dynamic + handling of location is something the navigator should do and should inherit from player. + """ + pass + def create(self): top_division_height = 20 inventory_width = 20 diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index b8e02c4..eb28edd 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -92,6 +92,17 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log(room[long_arg.lower()]['pick_up']) except KeyError: self.parent.update_log("You cant pick that up.") + + elif command == 'OPEN': + try: + self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) + new_room = room[arguments[0].lower()]['leads_to'] + self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) + except KeyError: + self.parent.update_log("You cant open that.") + except IndexError: + self.parent.update_log("you must specify something to open") + else: self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) self.parent.update_log('I didn\'t understand {0}'.format(command)) diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py index b27cb37..0c865c9 100644 --- a/Adventure Game/adventure_game/Player.py +++ b/Adventure Game/adventure_game/Player.py @@ -8,4 +8,11 @@ class Player: def __init__(self, save_location): self.save_location = save_location - self.playerData = parse(save_location) \ No newline at end of file + self.playerData = parse(save_location) + + def change_room(self, new_room): + """ + Should move the player to a new room + TODO: Put a check here that checks if the room we're moving to exists! + """ + self.playerData['player']['location'] = new_room \ No newline at end of file -- 2.43.0 From 301d3d75db13c62d3ceab849864bf79655fe0cf8 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:34:08 -0500 Subject: [PATCH 65/80] Add some extra handlers to make engine less likely to crash unexpectedly --- Adventure Game/adventure_game/Handler.py | 62 +++++++++++++----------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index eb28edd..235b77c 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -63,35 +63,43 @@ class Handler(npyscreen.ButtonPress): # TODO: Should upgrade these to use fuzzy words library! and not direct comparisons! if command == 'LOOK': - if arguments[0] == 'AROUND': - try: - self.parent.update_log(room['look_around']) - except KeyError: - self.parent.update_log('There is nothing to look at?.. This might be a bug.') - if arguments[0] == 'AT': - try: - # Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it. - self.parent.update_log(room[arguments[1].lower()]['look_at']) - except KeyError: - self.parent.update_log("Not sure what you're trying to look at.") + try: + if arguments[0] == 'AROUND': + try: + self.parent.update_log(room['look_around']) + except KeyError: + self.parent.update_log('There is nothing to look at?.. This might be a bug.') + if arguments[0] == 'AT': + try: + # Argument[1] is the "thing" you want to look at, yaml is lowercase so we lowercase it. + self.parent.update_log(room[arguments[1].lower()]['look_at']) + except KeyError: + self.parent.update_log("Im not sure what you're trying to look at.") + except IndexError: + self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments)) + self.parent.update_log("You must specify something to look at.") elif command == 'PICK': - if arguments[0] == 'UP': - if len( - arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg - try: - # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. - self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) - self.parent.update_log(room[arguments[1].lower()]['pick_up']) - except KeyError: - self.parent.update_log("You cant pick that up.") - else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer - try: - long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between - self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) - self.parent.update_log(room[long_arg.lower()]['pick_up']) - except KeyError: - self.parent.update_log("You cant pick that up.") + try: + if arguments[0] == 'UP': + if len( + arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + try: + # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. + self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) + self.parent.update_log(room[arguments[1].lower()]['pick_up']) + except KeyError: + self.parent.update_log("You cant pick that up.") + else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer + try: + long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between + self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) + self.parent.update_log(room[long_arg.lower()]['pick_up']) + except KeyError: + self.parent.update_log("You cant pick that up.") + except IndexError: + self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments)) + self.parent.update_log("You must specify something to pick up.") elif command == 'OPEN': try: -- 2.43.0 From 3aa6d426feb98301829bf36c4e297ee3ca903608 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:45:36 -0500 Subject: [PATCH 66/80] Make room global 'room' not name of room --- Adventure Game/adventure_game/gamedata/world/hallway.yaml | 2 +- Adventure Game/adventure_game/gamedata/world/office.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Adventure Game/adventure_game/gamedata/world/hallway.yaml b/Adventure Game/adventure_game/gamedata/world/hallway.yaml index a8bde34..e6dfa89 100644 --- a/Adventure Game/adventure_game/gamedata/world/hallway.yaml +++ b/Adventure Game/adventure_game/gamedata/world/hallway.yaml @@ -1,4 +1,4 @@ -office: +room: grid: [0, 1] upon_enter: "You are standing just outside your office door." look_around: "You look up, and down the hallway, you see the receptionists |desk|. And a |closet| at the other end of the hall." diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index 6223826..b0883f1 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -1,4 +1,4 @@ -office: +room: grid: [0, 0] upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|" -- 2.43.0 From bcb2ee060d1eb2030af8b88a5e057c8084db47dc Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:45:58 -0500 Subject: [PATCH 67/80] add more try/except. Also handle new method of parenting room names --- Adventure Game/adventure_game/Handler.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 235b77c..945bcd4 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -46,8 +46,7 @@ class Handler(npyscreen.ButtonPress): player = self.parent.parentApp.player roomlocation = player.playerData['player']['location'] + '.yaml' try: - room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)[ - player.playerData['player']['location']] + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room'] # If the file could not be found except FileNotFoundError: @@ -102,14 +101,16 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log("You must specify something to pick up.") elif command == 'OPEN': - try: - self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) - new_room = room[arguments[0].lower()]['leads_to'] - self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) - except KeyError: - self.parent.update_log("You cant open that.") - except IndexError: - self.parent.update_log("you must specify something to open") + #try: + self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) + new_room = room[arguments[0].lower()]['leads_to'] + self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) + upon_enter = player.change_room(new_room) # Change the player to that new room. + self.parent.update_log(upon_enter) # Print the new room upon enter text. + #except KeyError: + # self.parent.update_log("You cant open that.") + #except IndexError: + # self.parent.update_log("you must specify something to open") else: self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) -- 2.43.0 From 2f8dd761ba929b7c41b66ff5f938857a1653c6bd Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:46:08 -0500 Subject: [PATCH 68/80] player can now change rooms! --- Adventure Game/adventure_game/Player.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py index 0c865c9..fb5085d 100644 --- a/Adventure Game/adventure_game/Player.py +++ b/Adventure Game/adventure_game/Player.py @@ -1,10 +1,12 @@ from yaml_parser import parse_datafile as parse + class Player: """ This class intended to abstract out the actual yaml data into a player.(item) that is more friendly to handle in code. """ + def __init__(self, save_location): self.save_location = save_location @@ -15,4 +17,8 @@ class Player: Should move the player to a new room TODO: Put a check here that checks if the room we're moving to exists! """ - self.playerData['player']['location'] = new_room \ No newline at end of file + self.playerData['player']['location'] = new_room + + room = self.playerData['player']['location'] + + return parse('adventure_game/gamedata/world/' + room)['room']['upon_enter'] -- 2.43.0 From a1f215cc93f85740e6d4c4a3e30707881322a2b3 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:51:34 -0500 Subject: [PATCH 69/80] handle updating location --- .../adventure_game/GameNavigator.py | 27 ++++++++++--------- Adventure Game/adventure_game/Handler.py | 6 +++++ .../adventure_game/gamedata/world/office.yaml | 1 + 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index 9abc7d7..ccf3ba0 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -34,7 +34,7 @@ class GameNavigator(npyscreen.FormBaseNew): This may not be needed in the future, dynamic handling of location is something the navigator should do and should inherit from player. """ - pass + self.artBox.footer = location def create(self): top_division_height = 20 @@ -58,13 +58,13 @@ class GameNavigator(npyscreen.FormBaseNew): editable=False) self.artBox.footer = 'Unknown Location' - self.artBox = self.add(npyscreen.BoxBasic, - name='Inventory', - max_width=inventory_width, - max_height=top_division_height, - relx=1, - rely=2, - editable=False) + self.inventoryBox = self.add(npyscreen.BoxBasic, + name='Inventory', + max_width=inventory_width, + max_height=top_division_height, + relx=1, + rely=2, + editable=False) self.logBoxOutline = self.add(npyscreen.BoxBasic, max_width=inventory_width + art_width, @@ -108,10 +108,11 @@ class GameNavigator(npyscreen.FormBaseNew): its up to Handler.py to actually play the game, but we should do some basic initalization here """ - #TODO: load art from the last place the player was in - #TODO: load up inventory + # TODO: load art from the last place the player was in + # TODO: load up inventory - #TODO: Expand this by loding the text from the game - #WARN: THIS MAY REQUIRE REWRITING HANDLER.PY TO INTALIZE THE ROOM OBJECT OUTSIDE OF HANDLER.PY + # TODO: Expand this by loding the text from the game + # WARN: THIS MAY REQUIRE REWRITING HANDLER.PY TO INTALIZE THE ROOM OBJECT OUTSIDE OF HANDLER.PY self.update_log('Welcome back! Try "LOOK AROUND" to get started.') - self.update_log('>>Note from joe: Welcome! you\'re playing the demo! Please dont mind text issues like |this| and *this*\ni have yet to implement color!') + self.update_log( + '>>Note from joe: Welcome! you\'re playing the demo! Please dont mind text issues like |this| and *this*\ni have yet to implement color!') diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 945bcd4..458780d 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -57,6 +57,12 @@ class Handler(npyscreen.ButtonPress): # Put the player in a blank room i forgot to finish room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') + # This sets the footer text in the art window + try: + self.parent.update_location(room['name']) + except KeyError: + self.parent.update_location('Unknown Location') + # By now we should be situated in our room, and with our player. # self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index b0883f1..2848ef4 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -1,4 +1,5 @@ room: + name: "Your Office" grid: [0, 0] upon_enter: "You are standing behind your desk, you see a |NAMEPLATE|, a |TAPE RECORDER| and your trusty |LOG VIEWER|" look_around: "You look around the room, you see a |DESK|, a |BOOKSHELF| and the |DOOR|" -- 2.43.0 From 21bd3c39bba30419f192ab9afc2e9d14e8d198e9 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:53:41 -0500 Subject: [PATCH 70/80] Change where we set art, inventory and location --- Adventure Game/adventure_game/Handler.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 458780d..f2c6238 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -57,12 +57,6 @@ class Handler(npyscreen.ButtonPress): # Put the player in a blank room i forgot to finish room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') - # This sets the footer text in the art window - try: - self.parent.update_location(room['name']) - except KeyError: - self.parent.update_location('Unknown Location') - # By now we should be situated in our room, and with our player. # self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! @@ -129,6 +123,15 @@ class Handler(npyscreen.ButtonPress): # Log the command that we parsed self.parent.parentApp.log.info('Parsed command "{0}" with arguments "{1}"'.format(command, arguments)) + """ + Do a little bit of final setup, change the art if we + need to, change the text at the bottom and update the inventory. + """ + try: + self.parent.update_location(room['name']) + except KeyError: + self.parent.update_location('Unknown Location') + # Make sure to re-draw the art box when we're all done (in case we updated it in logic above) self.parent.artContent.display() -- 2.43.0 From 493b663b4e9ee2cb33d4409416b24884b620637a Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:54:59 -0500 Subject: [PATCH 71/80] Must handle these --- Adventure Game/adventure_game/Handler.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index f2c6238..4c866e9 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -101,16 +101,16 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log("You must specify something to pick up.") elif command == 'OPEN': - #try: - self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) - new_room = room[arguments[0].lower()]['leads_to'] - self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) - upon_enter = player.change_room(new_room) # Change the player to that new room. - self.parent.update_log(upon_enter) # Print the new room upon enter text. - #except KeyError: - # self.parent.update_log("You cant open that.") - #except IndexError: - # self.parent.update_log("you must specify something to open") + try: + self.parent.parentApp.log.info('Player tried to open door: {0}'.format(arguments[0])) + new_room = room[arguments[0].lower()]['leads_to'] + self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) + upon_enter = player.change_room(new_room) # Change the player to that new room. + self.parent.update_log(upon_enter) # Print the new room upon enter text. + except KeyError: + self.parent.update_log("You cant open that.") + except IndexError: + self.parent.update_log("you must specify something to open") else: self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) -- 2.43.0 From e844ac23f4bfbda7663fb27b257c8b8b79290b95 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 21:59:58 -0500 Subject: [PATCH 72/80] Fix critical error when moving between rooms. --- Adventure Game/adventure_game/Handler.py | 5 ++--- Adventure Game/adventure_game/gamedata/world/hallway.yaml | 6 +++++- .../adventure_game/playerdata/defaults/default_player.yaml | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 4c866e9..4e3b727 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -44,15 +44,14 @@ class Handler(npyscreen.ButtonPress): # Localize the player player = self.parent.parentApp.player - roomlocation = player.playerData['player']['location'] + '.yaml' + roomlocation = player.playerData['player']['location'] try: room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room'] # If the file could not be found except FileNotFoundError: # Log a critical error! - self.parent.parentApp.log.critical( - 'Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format( + self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format( self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) # Put the player in a blank room i forgot to finish room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') diff --git a/Adventure Game/adventure_game/gamedata/world/hallway.yaml b/Adventure Game/adventure_game/gamedata/world/hallway.yaml index e6dfa89..e6855db 100644 --- a/Adventure Game/adventure_game/gamedata/world/hallway.yaml +++ b/Adventure Game/adventure_game/gamedata/world/hallway.yaml @@ -7,5 +7,9 @@ room: inspect: "Its still a closet door." open: "You cant open this door." desk: - look_at: "Its your receptionists desks, she's not sitting behind it." + look_at: "Its your receptionists desk, she's not sitting behind it." inspect: "She's still not there." + door: + leads_to: office.yaml + look_at: "Its a door, it leads to your office. You should try to |OPEN| it." + inspect: "Its ornate but basic, this side of the door has your name on a plaque." \ No newline at end of file diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml index 811f696..3c3c126 100644 --- a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -1,4 +1,4 @@ player: name: 'Default' - location: 'office' + location: 'office.yaml' inventory: ['test', 'test2'] \ No newline at end of file -- 2.43.0 From 50d1fc5cae3b778e4fa10e26d60c93575a163d0f Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:13:26 -0500 Subject: [PATCH 73/80] Change up inventory structure --- Adventure Game/adventure_game/Handler.py | 16 +++++++++++++--- Adventure Game/adventure_game/Player.py | 10 ++++++++++ .../adventure_game/gamedata/world/office.yaml | 2 +- 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 4e3b727..0a91c26 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -80,12 +80,12 @@ class Handler(npyscreen.ButtonPress): elif command == 'PICK': try: if arguments[0] == 'UP': - if len( - arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg try: # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) self.parent.update_log(room[arguments[1].lower()]['pick_up']) + player.add_inventory(room[arguments[1].lower()]['item_name']) except KeyError: self.parent.update_log("You cant pick that up.") else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer @@ -93,6 +93,7 @@ class Handler(npyscreen.ButtonPress): long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) self.parent.update_log(room[long_arg.lower()]['pick_up']) + player.add_inventory(room[long_arg.lower()]['item_name']) except KeyError: self.parent.update_log("You cant pick that up.") except IndexError: @@ -109,7 +110,16 @@ class Handler(npyscreen.ButtonPress): except KeyError: self.parent.update_log("You cant open that.") except IndexError: - self.parent.update_log("you must specify something to open") + self.parent.update_log("You must specify something to open") + + elif command == 'INSPECT': + try: + self.parent.parentApp.log.info('Player inspecting: {0}'.format(arguments[0])) + self.parent.update_log(room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists + except KeyError: + self.parent.update_log("Nothing more to inspect here.") + except IndexError: + self.parent.update_log("You must specify something to inspect.") else: self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) diff --git a/Adventure Game/adventure_game/Player.py b/Adventure Game/adventure_game/Player.py index fb5085d..c18f37b 100644 --- a/Adventure Game/adventure_game/Player.py +++ b/Adventure Game/adventure_game/Player.py @@ -1,4 +1,5 @@ from yaml_parser import parse_datafile as parse +from errors import ItemAlreadyTaken class Player: @@ -22,3 +23,12 @@ class Player: room = self.playerData['player']['location'] return parse('adventure_game/gamedata/world/' + room)['room']['upon_enter'] + + def add_inventory(self, item): + if item in self.playerData['player']['inventory']: + raise ItemAlreadyTaken + else: + self.playerData['player']['inventory'].append(item) + + def remove_inventory(self, item): + pass \ No newline at end of file diff --git a/Adventure Game/adventure_game/gamedata/world/office.yaml b/Adventure Game/adventure_game/gamedata/world/office.yaml index 2848ef4..e0a960a 100644 --- a/Adventure Game/adventure_game/gamedata/world/office.yaml +++ b/Adventure Game/adventure_game/gamedata/world/office.yaml @@ -10,7 +10,7 @@ room: look_at: "The bookshelf is a bookshelf." inspect: "Its still a bookshelf." log_viewer: - item: yes + item_name: "Log Viewer" look_at: "The log viewer is a small piece of ornate code, allowing you to examine |entities| more closely." inspect: "The dials are wiggly and the viewer makes Beep Boop sounds sometimes." pick_up: "You pick up the *LOG VIEWER*." -- 2.43.0 From 66279c3bec6ddc002cc0b1cfb0e90f0770547d1b Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:13:32 -0500 Subject: [PATCH 74/80] add custom errors! --- Adventure Game/adventure_game/errors.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Adventure Game/adventure_game/errors.py diff --git a/Adventure Game/adventure_game/errors.py b/Adventure Game/adventure_game/errors.py new file mode 100644 index 0000000..ba772be --- /dev/null +++ b/Adventure Game/adventure_game/errors.py @@ -0,0 +1,6 @@ +class ItemAlreadyTaken(Exception): + pass + + +class ItemRequired(Exception): + pass -- 2.43.0 From c022293335fe34b1f7369ca201690c54323a505c Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:19:17 -0500 Subject: [PATCH 75/80] you can pick up items! --- Adventure Game/adventure_game/GameNavigator.py | 16 ++++++++++++++++ Adventure Game/adventure_game/Handler.py | 2 ++ 2 files changed, 18 insertions(+) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index ccf3ba0..c1f7734 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -36,6 +36,14 @@ class GameNavigator(npyscreen.FormBaseNew): """ self.artBox.footer = location + def update_inventory(self, items): + res = '' + for element in items: + res = res + str(element) + '\n' + res = res.upper() # Inventory is always uppercase + + self.inventoryContent.value = res # Set the logbox to that value + def create(self): top_division_height = 20 inventory_width = 20 @@ -66,6 +74,14 @@ class GameNavigator(npyscreen.FormBaseNew): rely=2, editable=False) + self.inventoryContent = self.add(npyscreen.MultiLineEdit, + max_width=inventory_width, + max_height=top_division_height, + relx=2, + rely=3, + value='------------------', + editable=False) + self.logBoxOutline = self.add(npyscreen.BoxBasic, max_width=inventory_width + art_width, max_height=9, diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 0a91c26..597c8f0 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -141,6 +141,8 @@ class Handler(npyscreen.ButtonPress): except KeyError: self.parent.update_location('Unknown Location') + self.parent.update_inventory(player.playerData['player']['inventory']) + # Make sure to re-draw the art box when we're all done (in case we updated it in logic above) self.parent.artContent.display() -- 2.43.0 From bab62f0174321fe84065d296fe34bd920bb5a110 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:21:44 -0500 Subject: [PATCH 76/80] Remove some testing mess --- .../adventure_game/playerdata/defaults/default_player.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml index 3c3c126..070aa57 100644 --- a/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml +++ b/Adventure Game/adventure_game/playerdata/defaults/default_player.yaml @@ -1,4 +1,4 @@ player: name: 'Default' location: 'office.yaml' - inventory: ['test', 'test2'] \ No newline at end of file + inventory: ['Detective Hat'] -- 2.43.0 From 22017b2c425451c5b829bb68c8aac0e84ec68f66 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:27:15 -0500 Subject: [PATCH 77/80] add start to begin art --- .../adventure_game/gamedata/gamelib.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Adventure Game/adventure_game/gamedata/gamelib.yaml b/Adventure Game/adventure_game/gamedata/gamelib.yaml index dfb77ea..6a08498 100644 --- a/Adventure Game/adventure_game/gamedata/gamelib.yaml +++ b/Adventure Game/adventure_game/gamedata/gamelib.yaml @@ -32,6 +32,25 @@ menu: |------------------------------------------------------------------------------------------------| +------------------------------------------------------------------------------------------------+ + start_to_continue: | + + + + | | + | TYPE | + | START | + | TO BEGIN! | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + | | + + + dimensions: inventory_width: 23 inventory_height: 20 -- 2.43.0 From ebd518dd0117b8ef4b1c0ac0626b3dff282f80d5 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:41:26 -0500 Subject: [PATCH 78/80] Add in some better art handling. --- .../adventure_game/GameNavigator.py | 8 ++- Adventure Game/adventure_game/Handler.py | 49 +++++++++++++------ 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/Adventure Game/adventure_game/GameNavigator.py b/Adventure Game/adventure_game/GameNavigator.py index c1f7734..693f4a1 100644 --- a/Adventure Game/adventure_game/GameNavigator.py +++ b/Adventure Game/adventure_game/GameNavigator.py @@ -29,12 +29,16 @@ class GameNavigator(npyscreen.FormBaseNew): self.logBox.value = res # Set the logbox to that value - def update_location(self, location): + def update_location(self, location, art=None): """ This may not be needed in the future, dynamic handling of location is something the navigator should do and should inherit from player. """ self.artBox.footer = location + if art != None: + self.artContent.value = art + else: + self.artContent.value = self.parentApp.gamelib['menu']['graphics']['not_found'] def update_inventory(self, items): res = '' @@ -62,7 +66,7 @@ class GameNavigator(npyscreen.FormBaseNew): relx=inventory_width + 2, max_width=art_width - 2, max_height=top_division_height - 2, - value=self.parentApp.gamelib['menu']['graphics']['not_found'], + value=self.parentApp.gamelib['menu']['graphics']['start_to_continue'], editable=False) self.artBox.footer = 'Unknown Location' diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 597c8f0..3958aed 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -11,6 +11,23 @@ class Handler(npyscreen.ButtonPress): 3: re-render the screen """ + def localize_room(self, roomlocation): + """ + This method can re-localize the room. + """ + try: + room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room'] + + # If the file could not be found + except FileNotFoundError: + # Log a critical error! + self.parent.parentApp.log.critical( + 'Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format( + self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) + # Put the player in a blank room i forgot to finish + room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') + return room + def whenPressed(self): self.parent.parentApp.log.debug('Send button pressed!') # This is the raw command from the user @@ -44,17 +61,8 @@ class Handler(npyscreen.ButtonPress): # Localize the player player = self.parent.parentApp.player - roomlocation = player.playerData['player']['location'] - try: - room = parse(self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)['room'] - # If the file could not be found - except FileNotFoundError: - # Log a critical error! - self.parent.parentApp.log.critical('Handler could not load the current room! Is the player file corrupt or was there a typo? Path was {0}'.format( - self.parent.parentApp.mainPath / 'gamedata/world' / roomlocation)) - # Put the player in a blank room i forgot to finish - room = parse(self.parent.parentApp.mainPath / 'gamedata/world/blank_room.yaml') + room = self.localize_room(player.playerData['player']['location']) # Localize the room # By now we should be situated in our room, and with our player. # self.parent.parentApp.log.debug(room) # We dont need to log this, its too verbose! @@ -80,7 +88,8 @@ class Handler(npyscreen.ButtonPress): elif command == 'PICK': try: if arguments[0] == 'UP': - if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + if len( + arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg try: # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) @@ -90,8 +99,10 @@ class Handler(npyscreen.ButtonPress): self.parent.update_log("You cant pick that up.") else: # if its a longer list of args, the player prolly wants to pick up an item with multiple words, like hand_axe, or log_viewer try: - long_arg = '_'.join(arguments[1:]) # Joins whatever comes after 1 in our args with '_' between - self.parent.parentApp.log.info('Player tried to pick up long object {0}'.format(long_arg)) + long_arg = '_'.join( + arguments[1:]) # Joins whatever comes after 1 in our args with '_' between + self.parent.parentApp.log.info( + 'Player tried to pick up long object {0}'.format(long_arg)) self.parent.update_log(room[long_arg.lower()]['pick_up']) player.add_inventory(room[long_arg.lower()]['item_name']) except KeyError: @@ -107,6 +118,8 @@ class Handler(npyscreen.ButtonPress): self.parent.parentApp.log.debug('New room is: {0}'.format(new_room)) upon_enter = player.change_room(new_room) # Change the player to that new room. self.parent.update_log(upon_enter) # Print the new room upon enter text. + + room = self.localize_room(player.playerData['player']['location']) # Re-Localize! except KeyError: self.parent.update_log("You cant open that.") except IndexError: @@ -115,12 +128,16 @@ class Handler(npyscreen.ButtonPress): elif command == 'INSPECT': try: self.parent.parentApp.log.info('Player inspecting: {0}'.format(arguments[0])) - self.parent.update_log(room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists + self.parent.update_log( + room[arguments[0].lower()]['inspect']) # Prints the inspect text, if it exists except KeyError: self.parent.update_log("Nothing more to inspect here.") except IndexError: self.parent.update_log("You must specify something to inspect.") + elif command == 'START': + self.parent.update_log('Welcome to the game! Try to |LOOK AROUND|.') + else: self.parent.parentApp.log.info('Player\'s command was not understood: {0}'.format(command)) self.parent.update_log('I didn\'t understand {0}'.format(command)) @@ -137,7 +154,9 @@ class Handler(npyscreen.ButtonPress): need to, change the text at the bottom and update the inventory. """ try: - self.parent.update_location(room['name']) + self.parent.update_location( + room['name'], + room['art']) except KeyError: self.parent.update_location('Unknown Location') -- 2.43.0 From 5c97859f4c246ac637359d10a28bc06f3fb2c4bc Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:48:08 -0500 Subject: [PATCH 79/80] slightly more stuff added to hallway. --- .../adventure_game/gamedata/world/hallway.yaml | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Adventure Game/adventure_game/gamedata/world/hallway.yaml b/Adventure Game/adventure_game/gamedata/world/hallway.yaml index e6855db..21b797c 100644 --- a/Adventure Game/adventure_game/gamedata/world/hallway.yaml +++ b/Adventure Game/adventure_game/gamedata/world/hallway.yaml @@ -1,15 +1,20 @@ room: + name: "The Hallway" grid: [0, 1] upon_enter: "You are standing just outside your office door." - look_around: "You look up, and down the hallway, you see the receptionists |desk|. And a |closet| at the other end of the hall." + look_around: "You look up, and down the hallway, you see the receptionists |desk|. A |closet| at the other end of the hall and the |Office Door| Behind you." closet: look_at: "Its a closet door." inspect: "Its still a closet door." - open: "You cant open this door." desk: look_at: "Its your receptionists desk, she's not sitting behind it." inspect: "She's still not there." - door: + office_door: leads_to: office.yaml look_at: "Its a door, it leads to your office. You should try to |OPEN| it." - inspect: "Its ornate but basic, this side of the door has your name on a plaque." \ No newline at end of file + inspect: "Its ornate but basic, this side of the door has your name on a |plaque|." + plaque: + item_name: "Plaque" + look_at: "Its a small brass plate, it has your name on it." + inspect: "Its still a small brass plate, and it has your name on it. Beyond that its nothing special." + pick_up: "You tear off the *PLAQUE*, and now you're stuck with it i guess." -- 2.43.0 From 752977aa94514e8eb42fd0777ee54d42a549bd47 Mon Sep 17 00:00:00 2001 From: Joe S <31870999+KenwoodFox@users.noreply.github.com> Date: Fri, 26 Feb 2021 22:53:22 -0500 Subject: [PATCH 80/80] take and pick up now work the same --- Adventure Game/adventure_game/Handler.py | 9 +++++---- .../adventure_game/gamedata/world/hallway.yaml | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Adventure Game/adventure_game/Handler.py b/Adventure Game/adventure_game/Handler.py index 3958aed..a40af42 100644 --- a/Adventure Game/adventure_game/Handler.py +++ b/Adventure Game/adventure_game/Handler.py @@ -85,11 +85,12 @@ class Handler(npyscreen.ButtonPress): self.parent.parentApp.log.error('Could not handle {0}, {1}'.format(command, arguments)) self.parent.update_log("You must specify something to look at.") - elif command == 'PICK': + elif command in ['PICK', 'TAKE']: try: - if arguments[0] == 'UP': - if len( - arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg + if arguments[0] == 'UP' or command in ['TAKE']: + if command in ['TAKE']: + arguments = ['UP'] + arguments # This is a messy way to fix take logic vs pick up logic but it works. + if len(arguments) <= 2: # If there are only 2 args ex:up, item then we dont need to merge that last arg try: # Argument[1] is the "thing" you want to pick up, yaml is lowercase so we lowercase it. self.parent.parentApp.log.info('Player tried to pick up {0}'.format(arguments[1])) diff --git a/Adventure Game/adventure_game/gamedata/world/hallway.yaml b/Adventure Game/adventure_game/gamedata/world/hallway.yaml index 21b797c..ea45ce6 100644 --- a/Adventure Game/adventure_game/gamedata/world/hallway.yaml +++ b/Adventure Game/adventure_game/gamedata/world/hallway.yaml @@ -14,7 +14,7 @@ room: look_at: "Its a door, it leads to your office. You should try to |OPEN| it." inspect: "Its ornate but basic, this side of the door has your name on a |plaque|." plaque: - item_name: "Plaque" + item_name: "Office Door Plaque" look_at: "Its a small brass plate, it has your name on it." inspect: "Its still a small brass plate, and it has your name on it. Beyond that its nothing special." pick_up: "You tear off the *PLAQUE*, and now you're stuck with it i guess." -- 2.43.0