Skip to content

Instantly share code, notes, and snippets.

@Fortyseven
Created April 25, 2024 04:46
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 Fortyseven/0b74029a61a4fd022fbf20c7689df361 to your computer and use it in GitHub Desktop.
Save Fortyseven/0b74029a61a4fd022fbf20c7689df361 to your computer and use it in GitHub Desktop.
# NOTE: This was generated using Llama3 on Meta.ai using this
# prompt. The first sentence is mine, and the rest is the gameplay
# description direct from Wikipedia...
"""
I'm going to describe some gameplay and I want you to create a
curses-based game in Python that implements it:
Every day, a five-letter word is chosen which players aim to
guess within six tries. After every guess, each letter is marked
as either green, yellow or gray: green indicates that the letter
is correct and in the correct position, yellow means it is in
the answer but not in the right position, while gray indicates
it is not in the answer at all. Multiple instances of the same
letter in a guess, such as the "o"s in "robot", will be colored
green or yellow only if the letter also appears multiple times
in the answer; otherwise, excess repeating letters will be
colored gray. The game has a "hard mode" option, which requires
players to include letters marked as green and yellow in subsequent
guesses. The daily word is the same for everyone. The game also
has a dark theme as well as a high-contrast theme for colorblind
accessibility, which changes the color scheme from green and
yellow to orange and blue.
"""
import curses
import random
# Initialize the daily word
daily_word = random.choice(["apple", "basic", "cloud", "dance", "flute"])
def draw_menu(stdscr):
stdscr.clear()
stdscr.addstr(0, 0, "Wordle Game")
stdscr.addstr(1, 0, "1. Play Game")
stdscr.addstr(2, 0, "2. Hard Mode")
stdscr.addstr(3, 0, "3. Dark Theme")
stdscr.addstr(4, 0, "4. High Contrast Theme")
stdscr.addstr(5, 0, "5. Quit")
stdscr.refresh()
def draw_game(stdscr, guesses, hard_mode, theme):
stdscr.clear()
for i, guess in enumerate(guesses):
for j, letter in enumerate(guess):
if letter == daily_word[j]:
if theme == "dark":
stdscr.addstr(i, j, letter, curses.color_pair(1))
elif theme == "high-contrast":
stdscr.addstr(i, j, letter, curses.color_pair(2))
else:
stdscr.addstr(i, j, letter, curses.color_pair(3))
elif letter in daily_word:
if theme == "dark":
stdscr.addstr(i, j, letter, curses.color_pair(4))
elif theme == "high-contrast":
stdscr.addstr(i, j, letter, curses.color_pair(5))
else:
stdscr.addstr(i, j, letter, curses.color_pair(6))
else:
stdscr.addstr(i, j, letter)
stdscr.refresh()
def main(stdscr):
curses.start_color()
curses.use_default_colors()
curses.init_pair(1, curses.COLOR_GREEN, -1)
curses.init_pair(2, curses.COLOR_CYAN, -1)
curses.init_pair(3, curses.COLOR_GREEN, -1)
curses.init_pair(4, curses.COLOR_YELLOW, -1)
curses.init_pair(5, curses.COLOR_MAGENTA, -1)
curses.init_pair(6, curses.COLOR_YELLOW, -1)
curses.echo() # Enable character echoing
hard_mode = False
theme = "normal"
while True:
draw_menu(stdscr)
c = stdscr.getch()
if c == ord('1'):
guesses = []
for _ in range(6):
stdscr.move(10, 0)
stdscr.clrtoeol()
guess = ''
while len(guess) < 5:
char = stdscr.getch()
if char >= ord('a') and char <= ord('z'):
stdscr.addch(10, len(guess), char)
guess += chr(char)
guesses.append(guess)
draw_game(stdscr, guesses, hard_mode, theme)
elif c == ord('2'):
hard_mode = not hard_mode
elif c == ord('3'):
theme = "dark"
elif c == ord('4'):
theme = "high-contrast"
elif c == ord('5'):
break
curses.wrapper(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment