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)