updated end screen

This commit is contained in:
xereeto 2024-03-09 18:06:30 +00:00
parent 085beca867
commit 3c4cc86b26
1 changed files with 43 additions and 32 deletions

View File

@ -1,9 +1,10 @@
from colored import bg, fg, attr from colored import bg, fg, attr
from datetime import date import datetime
import time
from getch import getch from getch import getch
import possible import possible
colors = [bg("white")+fg("black"), bg("dark_gray")+fg("white"),bg("light_yellow")+fg("dark_gray"),bg("green")+fg("white")] colors = [bg("white")+fg("black"), bg("dark_gray")+fg("white"),bg("light_yellow")+fg("dark_gray"),bg("green")+fg("white"),bg("light_gray")]
keycolors = [fg("white")+bg("black"), fg("dark_gray")+bg("black"),fg("light_yellow")+bg("black"),fg("green")+bg("black")] keycolors = [fg("white")+bg("black"), fg("dark_gray")+bg("black"),fg("light_yellow")+bg("black"),fg("green")+bg("black")]
reset = bg("black")+fg("white") reset = bg("black")+fg("white")
@ -14,6 +15,9 @@ class Wordle:
return False return False
else: else:
turn=self.turn turn=self.turn
self.guesses[turn][0]=[4,4,4,4,4]
self.drawGuessLine(turn)
time.sleep(0.05)
self.guesses[turn][1] = word self.guesses[turn][1] = word
processed=[] processed=[]
for i,letter in enumerate(word): for i,letter in enumerate(word):
@ -26,11 +30,11 @@ class Wordle:
processed.append(letter) processed.append(letter)
self.guesses[turn][0][i] = 2 self.guesses[turn][0][i] = 2
if letter not in self.guessedKeys: if letter not in self.guessedKeys:
self.guessedKeys[letter] = 2 self.guessedKeys[letter] = 2
else: else:
self.guesses[turn][0][i] = max(self.guesses[turn][0][i],1) self.guesses[turn][0][i] = max(self.guesses[turn][0][i]%4,1)
if letter not in self.guessedKeys: if letter not in self.guessedKeys:
self.guessedKeys[letter] = 1 self.guessedKeys[letter] = 1
self.drawGuessLine(self.turn) self.drawGuessLine(self.turn)
self.turn +=1 self.turn +=1
self.drawStatusLine() self.drawStatusLine()
@ -56,7 +60,7 @@ class Wordle:
placeCursor(9,21) placeCursor(9,21)
put(reset+str(self.number)) put(reset+str(self.number))
placeCursor(34,21) placeCursor(34,21)
put("Turn: "+str(self.turn+1)+"/6"+colors[0]) put("Turn: "+str(min(self.turn+1,6))+"/6"+colors[0])
def drawKeyboard(self): def drawKeyboard(self):
placeCursor(13,17) placeCursor(13,17)
@ -82,8 +86,8 @@ class Wordle:
put(colors[0]) put(colors[0])
def __init__(self): def __init__(self):
start = date(2021,6,19) start = datetime.date(2021,6,19)
number = (date.today()-start).days number = (datetime.date.today()-start).days
self.number = number self.number = number
self.turn = 0 self.turn = 0
self.curGuess="" self.curGuess=""
@ -120,39 +124,38 @@ def placeCursor(x,y):
move("d",y) move("d",y)
def putCursorInside(guess,letter): def putCursorInside(guess,letter):
row = guess * 4 + 1; row = guess * 4 + 1;
col = 48 + letter * 6; col = 48 + letter * 6;
placeCursor(col,row); placeCursor(col,row);
put(colors[0]) put(colors[0])
def main(): def main():
cursorLocation = 0 cursorLocation = 0
print(reset+"\033c") print(reset+"\033c")
screen=fg('green')+''' screen="\x1b[?25l"+fg('green')+'''
clone by xereeto clone by xereeto
original by josh wardle'''+fg('white')+''' original by josh wardle'''+fg('white')+'''
---------------------------------------- ----------------------------------------
Guess the WORDLE in 6 tries. Guess the WORDLE in 6 tries.
Each guess must be a valid 5 letter word. Each guess must be a valid 5 letter word.
Press the enter button to submit. Press the enter button to submit.
After each guess, the color of the tiles After each guess, the color of the tiles
will change to show how close your guess will change to show how close your guess
was to the word. was to the word.
---------------------------------------- ----------------------------------------
Keys: Keys:
q w e r t y u i o p q w e r t y u i o p
a s d f g h j k l a s d f g h j k l
z x c v b n m z x c v b n m
---------------------------------------- ----------------------------------------
Game: XXX Game: XXX
''' '''
import time
goHome() goHome()
print(screen,end="") print(screen,end="")
goHome() goHome()
w = Wordle() w = Wordle()
while w.turn<6 and not w.wonGame(): while w.turn<6 and not w.wonGame():
@ -166,6 +169,8 @@ def main():
char = getch().upper() char = getch().upper()
except OverflowError: except OverflowError:
pass pass
if ord(char)==3:
return
prevchar = ord(char) prevchar = ord(char)
if char>="A" and char <="Z" and prevchar !=91: if char>="A" and char <="Z" and prevchar !=91:
if len(w.curGuess)<5: if len(w.curGuess)<5:
@ -193,9 +198,15 @@ def main():
else: else:
w.updateError("You have to enter a real word!") w.updateError("You have to enter a real word!")
if w.wonGame(): if w.wonGame():
w.updateError("You won!") s="s"
if w.turn==1:
s=""
w.updateError("You won in "+str(w.turn)+" turn"+s+"!")
else: else:
w.updateError("You lost :(") w.updateError("You lost :( The word was "+w.answer+"!")
time.sleep(2)
midnight = (datetime.datetime.now() + datetime.timedelta(days=1)).replace(hour=0, minute=0, microsecond=0, second=0)
w.updateError("Next WORDLE in: "+str(datetime.timedelta(seconds=(midnight-datetime.datetime.now()).seconds)))
time.sleep(2) time.sleep(2)
@ -207,4 +218,4 @@ try:
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
finally: finally:
print("\033c"+reset+"Goodbye!") print("\033c"+reset+"Goodbye!\x1b[?25h")