Display a menu once the end of the deck has been reached, offering
multiple options on how to continue.
"""
- stdscr.addstr("Good job, you've completed a round!\n\n",
- curses.color_pair(1))
- stdscr.addstr("Choose one of the following options:\n" +
+ def menu_print(stdscr, stack, headers, idx, string, err=False):
+ stdscr.clear()
+ if err:
+ stdscr.addstr(string + "\n\n", curses.color_pair(2))
+ else:
+ stdscr.addstr(string + "\n\n", curses.color_pair(1))
+ disp_menu(stdscr, stack, headers, idx)
+
+ stdscr.addstr("Choose one of the following options:\n\n" +
+ "[y]: reset stack to original state\n" +
+ "[z]: shuffle stack\n" +
+ "[f]: flip all cards in stack\n" +
+ "[t]: reverse stack order\n" +
+ "[u]: unstar all\n" +
+ "[s]: update stack to include starred only\n\n" +
"[r]: restart\n" +
- "[s]: restart with starred only\n" +
- "[u]: restart and unstar all\n" +
- "[z]: restart and shuffle cards\n" +
- "[f]: restart and show the other side first\n" +
- "[t]: restart in reverse order\n" +
"[q]: quit")
+ idx.setIdx(0)
while True:
key = stdscr.getkey()
if key == "q":
sys.exit(0)
- elif key == "r":
- idx.setIdx(0)
- get_key(stdscr, stack, headers, idx)
+ elif key == "y":
+ stack = lightcards.get_orig()[1]
+ menu_print(stdscr, stack, headers, idx,
+ "Stack reset!")
+ elif key == "u":
+ [x.unStar() for x in stack]
+ menu_print(stdscr, stack, headers, idx,
+ "All unstarred!")
+ elif key == "t":
+ stack.reverse()
+ menu_print(stdscr, stack, headers, idx,
+ "Stack reversed!")
+ elif key == "z":
+ shuffle(stack)
+ menu_print(stdscr, stack, headers, idx,
+ "Stack shuffled!")
+ elif key == "f":
+ for x in stack:
+ x[0], x[1] = x[1], x[0]
+ headers[0], headers[1] = headers[1], headers[0]
+ menu_print(stdscr, stack, headers, idx,
+ "Cards flipped!")
elif key == "s":
# Check if there are any starred cards before proceeding, and if
# not, don't allow to proceed and show an error message
for x in stack:
if x.getStar():
cont = True
+ break
if cont:
- idx.setIdx(0)
stack = [x for x in stack if x.getStar()]
- get_key(stdscr, stack, headers, idx)
+ menu_print(stdscr, stack, headers, idx,
+ "Stars only!")
else:
- stdscr.clear()
- stdscr.addstr("ERR: Stack empty. Choose another option\n\n",
- curses.color_pair(2))
- disp_menu(stdscr, stack, headers, idx)
- elif key == "u":
- idx.setIdx(0)
- for x in stack:
- x.unStar()
- get_key(stdscr, stack, headers, idx)
- elif key == "z":
- idx.setIdx(0)
- shuffle(stack)
- get_key(stdscr, stack, headers, idx)
- elif key == "f":
- idx.setIdx(0)
- for x in stack:
- x[0], x[1] = x[1], x[0]
- headers[0], headers[1] = headers[1], headers[0]
- get_key(stdscr, stack, headers, idx)
- elif key == "t":
- idx.setIdx(0)
- stack.reverse()
+ menu_print(stdscr, stack, headers, idx,
+ "ERR: None are starred!",
+ err=True)
+ elif key == "r":
get_key(stdscr, stack, headers, idx)