Calvin (Deutschbein)
W5Mon: 23 Sep
def spaces_to_underscores(s:str) -> str:
new = ""
for index in range(len(s)):
if s[index] in " ":
new += "_"
else:
new += s[index]
return new
from WordleGraphics import * # WordleGWindow, N_ROWS, ...
from english import * # ENGLISH_WORDS, is_english_word
import random
def wordle():
# The main function to play the Wordle game.
def enter_action():
# What should happen when RETURN/ENTER is pressed.
gw.show_message("You need to implement this method")
gw = WordleGWindow()
gw.add_enter_listener(enter_action)
# Startup boilerplate
if __name__ == "__main__":
wordle()
Function | Description |
---|---|
gw.set_square_letter(row, col, l) |
Sets the letter in the specified row and col |
gw.get_square_letter(row, col) |
Returns letter in the specified row and col |
gw.add_enter_listener(func) |
Specifies function run when enter pressed |
gw.show_message(msg) |
Shows a message below the squares |
gw.set_square_color(row, col, c) |
Sets the color of the specified square |
gw.set_current_row(row_idx) |
Sets row where typed characters appear |
gw.get_current_row() |
Returns the current row index |
gw.set_key_color(letter, color) |
Sets the color of the specified key letter |
gw.get_key_color(letter) |
Returns the color of the specified key letter |
word_to_row(word:str, row:int)
word_from_row(row:int) -> str
gw.set_square_letter
def wordle():
# The main function to play the Wordle game.
def enter_action():
# What should happen when RETURN/ENTER is pressed.
gw.show_message("To do: enter_action")
def word_to_row(word:str, row:int):
gw.show_message("To do: word_to_row")
def word_from_row(row:int) -> str:
gw.show_message("To do: row_to_word")
return "" # placeholder
# to see if a word is in ENGLISH_WORDS, make it lower case.
guess_str = "Hello"
guess_low = guess_str.lower()
guess_cap = guess_str.upper()
print(guess_str, guess_str in ENGLISH_WORDS) # Hello False
print(guess_low, guess_low in ENGLISH_WORDS) # hello True
print(guess_cap, guess_cap in ENGLISH_WORDS) # HELLO False
# places 'H' in the upper left
gw.set_square_letter(0,0,guess_cap[0]
Guess = "Hello" # use a mixed capital name for unknown
guess = Guess.lower() # use lower if you've made lower
GUESS = Guess.upper() # use upper if you've made upper
def wordle():
def enter_action():
if # your code here
gw.show_message("That's a 5 letter English word")
else:
gw.show_message("Not in word list")
color_row(row:int, answer:str)
from WordleGraphics import *
Color | Description |
---|---|
CORRECT_COLOR |
A shade of green |
PRESENT_COLOR |
A shade of brownish yellow |
MISSING_COLOR |
A shade of gray |
UNKNOWN_COLOR |
Initial white color |
import random # we'll discuss further - don't worry
gw.show_message()
random.shuffle(ENGLISH_WORDS) # de-alphabetizes
for word in ENGLISH_WORDS:
print(word) # prints words in a random order
gw.show_message("something nice not literally this")
gw.set_current_row(N_ROWS) # stop reading
gw.show_message("reveal the answer")
def spaces_to_underscores(s:str) -> str:
new = ""
for index in range(len(s)):
if s[index] in " ":
new += "_"
else:
new += s[index]
return new