diff --git a/README.md b/README.md index 1159cbd..73dd60a 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ Fallout Terminal Simulates a computer terminal from fallout. -Currently only implements the login portion. - Usage ================ @@ -13,21 +11,12 @@ python fallout.py ``` or for hard mode where the user must manually enter the correct input in the -boot script, +boot and login scripts ``` python fallout.py hard ``` -To only use the login in another program: - -``` -import fallout_login - -# returns true if the correct password is entered, false otherwise -fallout_login.beginLogin() -``` - Passwords ================ diff --git a/fallout.py b/fallout.py index 942b98a..584607c 100755 --- a/fallout.py +++ b/fallout.py @@ -3,6 +3,7 @@ import fallout_login as login import fallout_boot as boot import fallout_locked as locked import fallout_hack as hack +import fallout_selection as select import sys hard = False @@ -13,7 +14,7 @@ if boot.beginBoot(hard): pwd = hack.beginLogin() if pwd != None: login.beginLogin(hard, 'ADMIN', pwd) - print 'Login successful' + print select.beginSelection() else: locked.beginLocked() print 'Login failed' diff --git a/fallout_functions.py b/fallout_functions.py index 88149e6..2e349fe 100644 --- a/fallout_functions.py +++ b/fallout_functions.py @@ -6,7 +6,7 @@ LETTER_PAUSE = 5 INPUT_PAUSE = 500 # ms -TYPE_DELAY = 30 +TYPE_DELAY = 40 HIDDEN_MASK = '*' @@ -59,3 +59,11 @@ def upperInput(window, hidden = False, can_newline = True): elif can_newline: window.addch(NEWLINE) return instr + +def centeredWrite(window, text, pause = LETTER_PAUSE): + """ + Writes to the current line but centers the text + """ + width = window.getmaxyx()[1] + window.move(window.getyx()[0], width / 2 - len(text) / 2) + slowWrite(window, text, pause) diff --git a/fallout_locked.py b/fallout_locked.py index 111f1eb..c0ffbeb 100644 --- a/fallout_locked.py +++ b/fallout_locked.py @@ -1,6 +1,7 @@ import curses from fallout_functions import slowWrite +from fallout_functions import centeredWrite ################## text strings ###################### @@ -25,10 +26,10 @@ def runLocked(scr): # set screen to initial position scr.erase() curses.curs_set(0) - scr.move(height / 2 - 1, width / 2 - len(LOCKED_1) / 2) - slowWrite(scr, LOCKED_1) - scr.move(height / 2 + 1, width / 2 - len(LOCKED_2) / 2) - slowWrite(scr, LOCKED_2) + scr.move(height / 2 - 1, 0) + centeredWrite(scr, LOCKED_1) + scr.move(height / 2 + 1, 0) + centeredWrite(scr, LOCKED_2) scr.refresh() curses.napms(LOCKED_OUT_TIME) diff --git a/fallout_selection.py b/fallout_selection.py new file mode 100644 index 0000000..fc54f9a --- /dev/null +++ b/fallout_selection.py @@ -0,0 +1,97 @@ +import curses +from fallout_functions import slowWrite +from fallout_functions import centeredWrite +from fallout_functions import NEWLINE + +####################### text strings ######################## + +CENTERED_HEADERS = ( + 'ROBCO INDUSTRIES UNIFIED OPERATING SYSTEM', + 'COPYRIGHT 2075-2077 ROBCO INDUSTRIES', + '-SERVER 6-', + '' +) + +OTHER_HEADERS = ( + '\tSoftLock Solutions, Inc', + '"Your Security is Our Security"', + '>\\ Welcome, USER', + '' +) + +SELECTIONS = ( + 'Disengage Lock', + 'Deactivate Turrets', + 'Read Log' +) + +###################### Functions ############################ + +def makeSelection(scr): + """ + ALlow the user to select an option + Returns the line number of the users selection starting at 0 + """ + inchar = 0 + selection = 0 + selection_count = len(SELECTIONS) + selection_start_y = scr.getyx()[0] + width = scr.getmaxyx()[1] + + while inchar != NEWLINE: + # move to start of selections and hightlight current selection + scr.move(selection_start_y, 0) + line = 0 + for sel in SELECTIONS: + whole_line = '> ' + SELECTIONS[line] + space = width - len(whole_line) % width + whole_line += ' ' * space + + if line == selection: + scr.addstr(whole_line, curses.A_REVERSE) + else: + scr.addstr(whole_line) + line += 1 + scr.refresh() + + inchar = scr.getch() + + # move up and down + if inchar == curses.KEY_UP and selection > 0: + selection -= 1 + elif inchar == curses.KEY_DOWN and selection < selection_count - 1: + selection += 1 + + return selection + + +def runSelection(scr): + """ + Print the selections and allow the user to select one + """ + curses.use_default_colors() + scr.erase() + scr.move(0, 0) + curses.curs_set(0) + curses.noecho() + + width = scr.getmaxyx()[1] + + for header in CENTERED_HEADERS: + centeredWrite(scr, header + '\n') + + for header in OTHER_HEADERS: + slowWrite(scr, header + '\n') + + for i in xrange(width): + scr.addch(curses.ACS_BSBS) + scr.refresh() + + return makeSelection(scr) + +def beginSelection(): + """ + Initialize curses and start the boot process + """ + res = curses.wrapper(runSelection) + return res