Skip to content

Instantly share code, notes, and snippets.

@ana0
Created June 30, 2014 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ana0/0d267b5057d7d6bd0689 to your computer and use it in GitHub Desktop.
Save ana0/0d267b5057d7d6bd0689 to your computer and use it in GitHub Desktop.
class Sequence(object):
def __init__(self, query, answers):
self.query = query
self.answers = answers
def text_wrapping(self, text):
#simple textwrapper, check how much space is left on the x-axis of the screen
#if a word's length is longer than the remaining space, adds a newline
maxx = stdscr.getmaxyx()[1] - stdscr.getyx()[1]
if text not in [",", "?", ".", ":"]:
text = " " + text
if len(text) + 1 > maxx:
stdscr.addstr("\n")
return text
def pretty_printing(self, text):
#splits text, a string, into a list of strings, checks dicts for them, and changes print colour accordingly
words = text.split(" ")
for i in words:
if vocabulary[i.lower()] == "noun":
stdscr.addstr(self.text_wrapping(i), curses.color_pair(2))
elif vocabulary[i.lower()] == "adjective":
stdscr.addstr(self.text_wrapping(i), curses.color_pair(3))
elif vocabulary[i.lower()] == "verb":
stdscr.addstr(self.text_wrapping(i), curses.color_pair(4))
elif vocabulary[i.lower()] == "adverb":
stdscr.addstr(self.text_wrapping(i), curses.color_pair(5))
elif vocabulary[i.lower()] == "pronoun":
stdscr.addstr(self.text_wrapping(i), curses.color_pair(6))
else:
stdscr.addstr(self.text_wrapping(i))
stdscr.refresh()
def game_play(self, *funcs):
#fundamental gameplay method, checks answer (int) against a list index to print the
#corresponding statement, also iterates through a list of possible wrong answers stored above as global variables
global wrong
global patience
stdscr.clear()
self.pretty_printing(self.query)
answer = stdscr.getstr(0, 0).decode(encoding = "utf-8")
range_check = [i for i in range(len(self.answers))]
while answer not in str(range_check) or answer.isdigit() == False:
try:
stdscr.clear()
stdscr.addstr(0, 1, "ERR: Wrong input \n\n", curses.color_pair(1))
stdscr.refresh()
self.pretty_printing(wrong_answers[wrong])
wrong += 1
except IndexError:
stdscr.clear()
stdscr.addstr(0, 1, "ERR: Wrong input \n\n", curses.color_pair(1))
stdscr.refresh()
stdscr.addstr(1,0, "\n " + str(patience), curses.color_pair(1))
patience += 1
stdscr.getch()
stdscr.clear()
self.pretty_printing(self.query)
answer = stdscr.getstr(0, 0).decode(encoding = "utf-8")
else:
stdscr.clear()
self.pretty_printing(self.answers[int(answer)])
stdscr.getch()
if len(funcs) > 0:
stdscr.clear()
eval(funcs[int(answer)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment