Skip to content

Instantly share code, notes, and snippets.

@gabryon99
Created March 17, 2022 07:44
Show Gist options
  • Save gabryon99/4afaca0a9f9f34605ec8ab66b273d793 to your computer and use it in GitHub Desktop.
Save gabryon99/4afaca0a9f9f34605ec8ab66b273d793 to your computer and use it in GitHub Desktop.
Wheel of Fortune!
#!/usr/bin/python3
import curses
import time
import random
def read_names():
return ["Foo", "Bar", "Baz", "FooBaz"]
def main() -> None:
index = 0
delay = 50
countdown = 5000 # seconds
# Initialize the random seed using the epochtime
random.seed(time.time())
# Initialize curses
screen = curses.initscr()
names = []
screen.addstr(0, 0, "🍀 WHEEL"); screen.refresh(); curses.napms(500)
screen.addstr(0, 9, "OF"); screen.refresh(); curses.napms(500)
screen.addstr(0, 12, "FORTUNE! 🍀"); screen.refresh(); curses.napms(500)
screen.addstr(1, 0, "Print any key to spin the wheel (or press CTRL+C to quit)...")
_ = screen.getch()
names_len = len(names)
while countdown >= 0:
screen.addstr(0, 0, names[index])
screen.refresh()
screen.clear()
curses.napms(delay)
index = (index + 1) % names_len
countdown -= delay
# Sort the final winner using the rand function
random_index = random.randint(0, names_len - 1)
screen.addstr(0, 0, f"The winner is: {names[random_index]}. Congratulations! 🎉")
screen.refresh()
# Wait for an input
_ = screen.getch()
# End the curses window
curses.endwin()
return
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment