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=""
@ -127,7 +131,7 @@ def putCursorInside(guess,letter):
def main(): def main():
cursorLocation = 0 cursorLocation = 0
print(reset+"\033c") print(reset+"\033c")
screen=fg('green')+''' screen="\x1b[?25l"+fg('green')+'''
@ -150,7 +154,6 @@ def main():
---------------------------------------- ----------------------------------------
Game: XXX Game: XXX
''' '''
import time
goHome() goHome()
print(screen,end="") print(screen,end="")
goHome() goHome()
@ -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")