Added monochrome compatibility

This commit is contained in:
xereeto 2024-03-09 18:07:17 +00:00
parent dfecaf222d
commit 99d9b71a89
1 changed files with 62 additions and 30 deletions

View File

@ -1,19 +1,36 @@
#!/usr/bin/env python3
from colored import bg, fg, attr
import blessed
import datetime
import time
from getch import getch
import possible
import os
term = blessed.Terminal()
unicode=False
eightColor=True
termwhite = term.bold_white
termgreen = term.bold_green
if 'TERM' in os.environ:
if 'xterm' in os.environ['TERM']:
unicode=True
if not 'ansi' in os.environ['TERM']:
eightColor=False
termwhite=term.bright_white
termgreen=term.bright_green
if eightColor:
colors =[ term.white_on_white, term.gray_on_gray,term.yellow_on_yellow,term.green_on_green,term.black_on_lightgray]
cardLetterColors =[ term.black_on_white, term.black_on_gray,term.bold_white_on_yellow,term.bold_white_on_green,term.black_on_lightgray]
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")]
reset = bg("black")+fg("white")
keycolors = [term.bold_white_on_black, term.black_on_black,term.yellow_on_black,term.bold_green_on_black]
reset = term.white_on_black
else:
colors =[ term.white_on_white, term.dimgray_on_dimgray,term.bright_yellow_on_bright_yellow,term.reverse_green_on_bright_white,term.lightgray_on_lightgray]
cardLetterColors =[ term.black_on_white, term.bright_white_on_dimgray,term.reverse_bright_yellow_on_dimgray,term.reverse_green_on_bright_white,term.on_lightgray]
keycolors = [termwhite, term.black_on_black,term.bright_yellow_on_black,term.bold_green_on_black]
reset=term.white_on_black + term.normal
class Wordle:
def check(self):
@ -59,10 +76,13 @@ class Wordle:
for line in range(3):
placeCursor(baseCol, baseRow+line)
for k,letter in enumerate(guess[0]):
if line!=1:
put(colors[letter]+" "+reset+" ")
drawing=["_|","_|","_|"," |","_|"];
if line==0:
put(colors[letter]+" "+reset+term.black_on_black+drawing[letter][1]+reset)
elif line==2:
put(colors[letter]+drawing[letter][0]*5+reset+term.black_on_black+drawing[letter][1]+reset)
else:
put(colors[letter]+" "+guess[1][k]+" "+reset+" ")
put(colors[letter]+" "+cardLetterColors[letter]+guess[1][k]+term.normal+colors[letter]+" "+reset+term.black_on_black(drawing[letter][1])+reset)
def drawStatusLine(self):
placeCursor(9,21)
put(reset+str(self.number))
@ -71,27 +91,28 @@ class Wordle:
t=self.turn
else:
t=self.turn+1
put("Turn: "+str(min(t,6))+"/6"+colors[0])
placeCursor(40,21)
put(str(min(t,6))+"/6"+colors[0])
def drawKeyboard(self):
def putKey(key):
if key.upper() in self.guessedKeys:
if self.guessedKeys[key.upper()] > 1:
put(keycolors[self.guessedKeys[key.upper()]]+key+' '+term.normal)
else:
put(reset+' ')
else:
put(reset+key+' ')
placeCursor(13,17)
for key in "qwertyuiop":
if key.upper() in self.guessedKeys:
put(keycolors[self.guessedKeys[key.upper()]]+key+' ')
else:
put(reset+key+' ')
putKey(key)
placeCursor(14,18)
for key in "asdfghjkl":
if key.upper() in self.guessedKeys:
put(keycolors[self.guessedKeys[key.upper()]]+key+' ')
else:
put(reset+key+' ')
putKey(key)
placeCursor(16,19)
for key in "zxcvbnm":
if key.upper() in self.guessedKeys:
put(keycolors[self.guessedKeys[key.upper()]]+key+' ')
else:
put(reset+key+' ')
putKey(key)
put(colors[0])
@ -111,10 +132,15 @@ class Wordle:
self.drawStatusLine()
self.drawKeyboard()
self.errorStatus=""
def updateError(self,e=reset+" "+colors[0]):
def updateError(self,e=" +"):
if e[-1]=="+":
e=e[:-1]
put(reset)
else:
put(term.white_on_black_reverse)
self.errorStatus = e
placeCursor(3, 22)
put(e)
put(e+colors[0]+term.normal)
self.placeCursor()
@ -139,28 +165,31 @@ def putCursorInside(guess,letter):
placeCursor(col,row);
put(colors[0])
def blankScreen():
put(reset+term.clear)
placeCursor(0,0)
'''
put(reset+'\033[2J')
placeCursor(0,0)
put(reset+((" "*80+"\n")*24));
placeCursor(0,0)
placeCursor(0,0)'''
def main():
cursorLocation = 0
blankScreen()
if not unicode:
screen=fg('green')+''' _ _
screen=termgreen+''' _ _
__ _____ _ __ __| | | ___
\ \ /\ / / _ \| '__/ _` | |/ _ \
\ V V / (_) | | | (_| | | __/
\_/\_/ \___/|_| \__,_|_|\___| '''
else:
screen=fg('green')+'''
screen=term.bright_green+'''
'''
screen +='''
clone by xereeto
original by josh wardle '''+fg('white')+'''
original by josh wardle '''+termwhite+'''
----------------------------------------
Guess the WORDLE in 6 tries.
Each guess must be a valid 5 letter word.
@ -175,7 +204,7 @@ def main():
a s d f g h j k l
z x c v b n m
----------------------------------------
Game:
Game: Turn:
'''
put(screen)
goHome()
@ -189,6 +218,7 @@ def main():
char = 0
w.placeCursor()
while not turnOver:
put(term.black)
try:
char = getch().upper()
except OverflowError:
@ -220,7 +250,7 @@ def main():
elif w.check():
turnOver=True
else:
w.updateError("You have to enter a real word!")
w.updateError("Word not in dictionary!")
if w.wonGame():
s="s"
if w.turn==1:
@ -243,13 +273,15 @@ def main():
import sys
w=None
try:
w=main()
with term.fullscreen(), term.hidden_cursor():
w=main()
except KeyboardInterrupt:
pass
finally:
blankScreen()
print("Goodbye!")
with term.fullscreen():
put(term.clear)
print(reset+"Goodbye!")
#put("Goodbye!")
cliflag = sys.argv[1] if len(sys.argv) > 1 else ''
if(w and cliflag != "--no-unicode" and unicode):