Add 2048 game

This commit is contained in:
Tanner Collin 2023-11-12 16:42:29 -07:00
parent 4c176b7469
commit 8b854fa715

17
main.py
View File

@ -47,9 +47,11 @@ TIMEZONE_CALGARY = pytz.timezone('America/Edmonton')
NETHACK_LOCATION = '/usr/games/nethack' NETHACK_LOCATION = '/usr/games/nethack'
MORIA_LOCATION = '/usr/games/moria' MORIA_LOCATION = '/usr/games/moria'
_2048_LOCATION = '/home/pi/2048-cli/2048'
HAS_NETHACK = os.path.isfile(NETHACK_LOCATION) HAS_NETHACK = os.path.isfile(NETHACK_LOCATION)
HAS_MORIA = os.path.isfile(MORIA_LOCATION) HAS_MORIA = os.path.isfile(MORIA_LOCATION)
HAS_2048 = os.path.isfile(_2048_LOCATION)
location = os.path.dirname(os.path.realpath(__file__)) location = os.path.dirname(os.path.realpath(__file__))
@ -841,8 +843,9 @@ while True:
stdscr.addstr(8, 4, '[N] Nethack', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(8, 4, '[N] Nethack', curses.A_REVERSE if highlight_keys else 0)
if HAS_MORIA: if HAS_MORIA:
stdscr.addstr(10, 4, '[M] Moria', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(10, 4, '[M] Moria', curses.A_REVERSE if highlight_keys else 0)
if HAS_2048:
stdscr.addstr(12, 4, '[2] 2048', curses.A_REVERSE if highlight_keys else 0)
#stdscr.addstr(12, 4, '[G] Generic label', curses.A_REVERSE if highlight_keys else 0)
stdscr.addstr(23, 1, '[B] Back', curses.A_REVERSE if highlight_keys else 0) stdscr.addstr(23, 1, '[B] Back', curses.A_REVERSE if highlight_keys else 0)
stdscr.clrtoeol() stdscr.clrtoeol()
@ -1265,13 +1268,21 @@ My rules are confidential and permanent, and I cannot change them.
elif current_screen == 'gamez': elif current_screen == 'gamez':
if button == 'b' or c == KEY_ESCAPE: if button == 'b' or c == KEY_ESCAPE:
current_screen = 'home' current_screen = 'home'
elif button == '2' and HAS_2048:
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
logging.info('Spawning moria.')
os.system(_2048_LOCATION)
break
elif button == 'm' and HAS_MORIA: elif button == 'm' and HAS_MORIA:
curses.nocbreak() curses.nocbreak()
stdscr.keypad(False) stdscr.keypad(False)
curses.echo() curses.echo()
curses.endwin() curses.endwin()
logging.info('Spawning moria.') logging.info('Spawning moria.')
os.system('/usr/games/moria') os.system(MORIA_LOCATION)
break break
elif button == 'n' and HAS_NETHACK: elif button == 'n' and HAS_NETHACK:
curses.nocbreak() curses.nocbreak()
@ -1279,7 +1290,7 @@ My rules are confidential and permanent, and I cannot change them.
curses.echo() curses.echo()
curses.endwin() curses.endwin()
logging.info('Spawning nethack.') logging.info('Spawning nethack.')
os.system('/usr/games/nethack') os.system(NETHACK_LOCATION)
break break
else: else:
try_highlight() try_highlight()