adventure-game #3

Open
Kenwood wants to merge 80 commits from adventure-game into master
2 changed files with 61 additions and 150 deletions
Showing only changes of commit e87c70e04f - Show all commits

View File

@ -2,88 +2,85 @@ import curses
from curses.textpad import Textbox, rectangle 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): # This is just done once at startup to get inital windows sizes
# Command is the last char the user entered. # TODO: handle live window resize!
command = 0 self.height, self.width = self.stdscr.getmaxyx()
# Clear, and refresh the screen self.command = 0
stdscr.clear()
stdscr.refresh()
# Clear and refresh the screen
self.stdscr.clear()
self.stdscr.refresh()
# Setup some colors!
# Start some curses colors # Start some curses colors
curses.start_color() curses.start_color()
curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK) curses.init_pair(1, curses.COLOR_CYAN, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE) curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
while command != ord('q'): # Setup art_win
# Clear the screen art_win_width = int((self.width / 3) * 2)
stdscr.clear() art_win_begin_x = int(self.width - art_win_width)
# Get the height, and width art_win_begin_y = 1 # Must be at least 1 (to allow header)
height, width = stdscr.getmaxyx() 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)
# Temporary strings, replace these with libdocs! # Setup dialogue_win
title = 'Untitled Adventure Game PRE ALPHA'[:width - 1] dialogue_win_width = self.width
subtitle = 'Joe Sedutto'[:width - 1] dialogue_win_begin_x = 0
statusbarstr = "Press 'q' to exit " 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,
# Centering calculations dialogue_win = curses.newwin(dialogue_win_height, dialogue_win_width, dialogue_win_begin_y,
start_x_title = int((width // 2) - (len(title) // 2) - len(title) % 2) dialogue_win_begin_x)
start_x_subtitle = int((width // 2) - (len(subtitle) // 2) - len(subtitle) % 2)
start_y = int((height // 2) - 2)
# Rendering some text while self.command != ord('q'):
whstr = 'Width: {}, Height: {}'.format(width, height) # Get the height of everything
stdscr.addstr(0, 0, whstr, curses.color_pair(1)) 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 # Render status bar
stdscr.attron(curses.color_pair(3)) self.stdscr.attron(curses.color_pair(3))
stdscr.addstr(height - 1, 0, statusbarstr) self.stdscr.addstr(self.height - 1, 0, self.statusbarstr)
stdscr.addstr(height - 1, len(statusbarstr), ' ' * (width - len(statusbarstr) - 1)) self.stdscr.addstr(self.height - 1, len(self.statusbarstr), ' ' * (self.width - len(self.statusbarstr) - 1))
stdscr.attroff(curses.color_pair(3)) self.stdscr.attroff(curses.color_pair(3))
# Turning on attributes for title # Render major game windows
stdscr.attron(curses.color_pair(2)) self.draw_art_window(art_win)
stdscr.attron(curses.A_BOLD) self.command = self.draw_dialogue_box(dialogue_win)
# 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 # Refresh the screen
stdscr.refresh() self.stdscr.refresh()
# Wait for next input # Wait for next input
command = stdscr.getch() # self.command = self.stdscr.getch()
curses.echo()
#self.command = self.stdscr.getstr(0, 0)
def draw_main_menu(self):
pass
def main_textbox(stdscr): def draw_art_window(self, window):
stdscr.addstr(0, 0, "Enter IM message: (hit Ctrl-G to send)") window.addstr(0, 0, "Wip")
window.box()
window.refresh()
editwin = curses.newwin(5,30, 2,1) def draw_dialogue_box(self, window):
rectangle(stdscr, 1,0, 1+5+1, 1+30+1) window.box()
stdscr.refresh() window.refresh()
box = Textbox(editwin) textbox = Textbox(window)
return textbox.gather()
# Let the user edit until Ctrl-G is struck.
box.edit()
# Get resulting contents
message = box.gather()
def main():
curses.wrapper(main_textbox)
if __name__ == '__main__': if __name__ == '__main__':
main() curses.wrapper(AdventureGame)

View File

@ -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)