adventure-game #3

Open
Kenwood wants to merge 80 commits from adventure-game into master
5 changed files with 71 additions and 180 deletions
Showing only changes of commit 52d4f5bbfe - Show all commits

View File

@ -1 +1,2 @@
venv
inspectionProfiles

View File

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

View File

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

View File

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

View File

@ -1,2 +1 @@
# Blessed handles our terminal "graphics"
blessed==1.17.12
npyscreen~=4.10.5