Skip to content

Instantly share code, notes, and snippets.

@estevaofon
Created February 5, 2023 06:34
Show Gist options
  • Save estevaofon/1f91c0af8b3ccb86a82ceae357ae49bf to your computer and use it in GitHub Desktop.
Save estevaofon/1f91c0af8b3ccb86a82ceae357ae49bf to your computer and use it in GitHub Desktop.
import curses
import time
class Tamagoshi:
def __init__(self):
self.life = 100
self.evolved = False
tamagoshi = Tamagoshi()
fed = time.time()
born = time.time()
def main(stdscr):
curses.curs_set(0)
curses.start_color()
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)
curses.init_pair(2, curses.COLOR_YELLOW, curses.COLOR_BLACK)
height, width = stdscr.getmaxyx()
win = curses.newwin(6, 30, height//2 - 1, width // 2 - 7)
win.bkgd(' ', curses.color_pair(1))
menu = curses.newwin(6, 30, height//2 - 10, width // 2 - 7)
menu.bkgd(' ', curses.color_pair(2))
while True:
stdscr.keypad(True)
stdscr.nodelay(True)
c = stdscr.getch()
if c == ord('1'):
feed_animation(win)
win.addstr(1, 8, " ")
if c == ord('2'):
die(win)
time.sleep(30)
win.addstr(1, 8, " ")
if tamagoshi.life > 0:
if not tamagoshi.evolved:
idle(win)
else:
evolve(win)
menu.addstr(5, 0, "1. Alimentar")
menu.addstr(4, 0, f"Vida: {tamagoshi.life}%")
menu.refresh()
menu.addstr(4, 0, f" "*len(f"Vida: {tamagoshi.life}%"+" "))
time.sleep(0.5)
global fed
if time.time() - fed > 20:
tamagoshi.life -= 10
if tamagoshi.life <= 0:
tamagoshi.life = 0
menu.addstr(4, 0, f"Vida: {tamagoshi.life}%")
win.refresh()
time.sleep(0.5)
die(win)
if time.time() - born > 120:
tamagoshi.evolved = True
def idle(win):
win.refresh()
win.addstr(2, 1, "(=^ .^=) ")
win.refresh()
time.sleep(0.5)
win.addstr(2, 1, "(= '.'=)")
win.refresh()
time.sleep(0.5)
def die(win):
win.addstr(4, 0, " ")
win.addstr(2, 1, "(=X-X=) ")
win.refresh()
time.sleep(0.5)
win.addstr(2, 1, "(=X.X=) ")
win.refresh()
time.sleep(0.5)
win.addstr(0, 8, " | ")
win.addstr(1,8, "-----")
win.addstr(2,8, " | ")
win.refresh()
time.sleep(0.5)
def evolve(win):
win.addstr(1, 1, " /\ /\\")
win.refresh()
time.sleep(0.5)
win.addstr(2, 1, "(=^ .^=) ")
win.refresh()
time.sleep(0.5)
win.addstr(2, 1, "(= '.'=)")
win.refresh()
time.sleep(0.5)
win.addstr(3, 1, "( u u )")
win.refresh()
time.sleep(0.5)
def feed_animation(win):
global fed
fed = time.time()
tamagoshi.life += 30
if tamagoshi.life > 100:
tamagoshi.life = 100
win.addstr(2, 1, "(=^-^=) ")
win.refresh()
time.sleep(0.5)
win.addstr(2, 1, "(=^o^=) ")
win.refresh()
time.sleep(0.5)
win.addstr(1,8, "( )")
win.addstr(2,8, " V ")
win.refresh()
time.sleep(0.5)
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment