From d318ce41a416f268cc59dfd8241e7ca50972e85c Mon Sep 17 00:00:00 2001 From: adithyagenie Date: Mon, 28 Nov 2022 01:32:47 +0530 Subject: [PATCH] Huge amount of UI improvement + Wordle scoring. Hopefully the final review. --- maze/menu.py | 33 ++--- maze/modules/PlayerBase_func.py | 29 ++-- maze/modules/about.py | 38 +++--- maze/modules/maze.py | 126 ++++-------------- maze/modules/maze_saveandload.py | 17 ++- pong.py | 2 + snake.py | 16 ++- starter.py | 5 +- {wordle-curses => wordle}/dictionary.py | 4 +- {wordle-curses => wordle}/solver.py | 0 {wordle-curses => wordle}/wordle-solver.py | 2 +- .../main_readable.py => wordle/wordle.py | 50 +++++-- {wordle-curses => wordle}/words.txt | 0 13 files changed, 141 insertions(+), 181 deletions(-) rename {wordle-curses => wordle}/dictionary.py (96%) rename {wordle-curses => wordle}/solver.py (100%) rename {wordle-curses => wordle}/wordle-solver.py (97%) rename wordle-curses/main_readable.py => wordle/wordle.py (81%) rename {wordle-curses => wordle}/words.txt (100%) diff --git a/maze/menu.py b/maze/menu.py index 232efed..4dfc82f 100644 --- a/maze/menu.py +++ b/maze/menu.py @@ -8,13 +8,14 @@ import maze.modules.PlayerBase_func as database import pong import snake from maze.modules.about import about - +import wordle.wordle as wordlegame def menu(screen): exit = False y, x = screen.getmaxyx() screen.clear() screen.nodelay(True) + curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) screen.refresh() text = """ \t\t\t██ █████ ██████ ██ ██ ██████ ██ ███ ██ ████████ ██ ██ @@ -23,14 +24,14 @@ def menu(screen): \t\t\t██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ \t\t\t███████ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ██ ██ ██""" - screen.addstr(1, 5, str(text)) - screen.addstr(10, x // 2 - 2, "MENU") - screen.addstr(13, 1, "space - Play") - screen.addstr(14, 1, "f - Load game from file") - screen.addstr(15, 1, "a - Account Settings") - screen.addstr(16, 1, "l - Leaderboard") - screen.addstr(17, 1, "x - About") - screen.addstr(18, 1, "esc - Quit") + screen.addstr(1, x // 2 - 34, str(text), curses.color_pair(5)) + screen.addstr(10, x // 2 - 2, "MENU", curses.color_pair(3) | curses.A_BOLD) + screen.addstr(13, x // 2 - 6, "space - PLAY", curses.A_BOLD) + screen.addstr(15, x // 2 - 11, "f - LOAD GAME FROM FILE", curses.A_BOLD) + screen.addstr(17, x // 2 - 10, "a - ACCOUNT SETTINGS", curses.A_BOLD) + screen.addstr(19, x // 2 - 7, "l - LEADERBOARD", curses.A_BOLD) + screen.addstr(21, x // 2 - 4, "x - ABOUT", curses.A_BOLD) + screen.addstr(23, x // 2 - 4, "esc - QUIT", curses.A_BOLD) screen.border() while True: if exit: @@ -40,11 +41,11 @@ def menu(screen): screen.clear() screen.refresh() screen.border() - screen.addstr(1, x // 2 - 2, "PLAY") - screen.addstr(y // 2 - 4, x // 2 - 2, "1. MAZE") - screen.addstr(y // 2 - 2, x // 2 - 2, "2. PONG") - screen.addstr(y // 2, x // 2 - 2, "3. SNAKE") - screen.addstr(y // 2 + 2, x // 2 - 2, "4. WORDLE") + screen.addstr(1, x // 2 - 2, "PLAY", curses.color_pair(3) | curses.A_BOLD) + screen.addstr(y // 2 - 4, x // 2 - 2, "1. MAZE", curses.A_BOLD) + screen.addstr(y // 2 - 2, x // 2 - 2, "2. PONG", curses.A_BOLD) + screen.addstr(y // 2, x // 2 - 2, "3. SNAKE", curses.A_BOLD) + screen.addstr(y // 2 + 2, x // 2 - 2, "4. WORDLE", curses.A_BOLD) while True: key2 = screen.getch() if key2 == ord("1"): @@ -54,7 +55,9 @@ def menu(screen): elif key2 == ord("3"): snake.main(screen) elif key2 == ord("4"): - pass + screen.nodelay(False) + screen.keypad(False) + wordlegame.main(screen) elif key2 == 27: menu(screen) break diff --git a/maze/modules/PlayerBase_func.py b/maze/modules/PlayerBase_func.py index 9f15d3c..84c5552 100644 --- a/maze/modules/PlayerBase_func.py +++ b/maze/modules/PlayerBase_func.py @@ -106,9 +106,9 @@ def screenhandler(screen): # MAIN MENU global loggedin, U, gamerid screen.clear() screen.refresh() - screen.addstr(1, w // 2 - 8, "ACCOUNT SETTINGS") + screen.addstr(1, w // 2 - 8, "ACCOUNT SETTINGS", curses.color_pair(3) | curses.A_BOLD) if loggedin: - screen.addstr(2, w // 2 - 8, f"Logged in as: {U}") + screen.addstr(2, w // 2 - 8, f"Logged in as: {U}", curses.color_pair(6) | curses.A_BOLD) screen.addstr(h // 2 - 3, w // 2 - 4, "1. Login") screen.addstr(h // 2 - 2, w // 2 - 8, "2. Create Account") screen.addstr(h // 2 - 1, w // 2 - 12, "3. Modify account details") @@ -203,7 +203,7 @@ def login(screen, calledby=None): # Function to log in screen.border() y, x = screen.getmaxyx() usernamelist = list_getter("username") - screen.addstr(1, x // 2 - 3, "LOGIN") + screen.addstr(1, x // 2 - 3, "LOGIN", curses.color_pair(3) | curses.A_BOLD) screen.addstr(y // 2 - 2, x // 2 - 7, "Username: ") while True: inputU = input(y // 2 - 2, x // 2 + 3, screen) @@ -253,21 +253,21 @@ def login(screen, calledby=None): # Function to log in loggedin = True gamerid = res[0][1] U = inputU - screen.addstr(y // 2 + 2, x // 2 - 4, "Login Successful!") + screen.addstr(y // 2 + 3, x // 2 - 9, "Login Successful!", curses.color_pair(6) | curses.A_BOLD) if calledby is not None: - screen.addstr(y // 2 + 3, x // 2 - 4, "Updating score...") + screen.addstr(y // 2 + 4, x // 2 - 8, "Updating score...", curses.color_pair(6) | curses.A_BOLD) screen.refresh() sleep(3) Update_score(calledby[0], calledby[1]) return else: - screen.addstr(y // 2 + 3, x // 2 - 4, "Returning to menu screen...") + screen.addstr(y // 2 + 4, x // 2 - 13, "Returning to menu screen...") screen.refresh() sleep(3) screenhandler(screen) return else: - screen.addstr(y // 2 + 2, x // 2 - 4, "Wrong password. Try again.") + screen.addstr(y // 2 + 2, x // 2 - 13, "Wrong password. Try again.") while True: key = screen.getch() if key == 10: @@ -397,7 +397,7 @@ def new_add(screen, calledby=None): screen.border() y, x = screen.getmaxyx() global quitting - screen.addstr(1, x // 2 - 8, "ACCOUNT CREATION") + screen.addstr(1, x // 2 - 8, "ACCOUNT CREATION", curses.color_pair(3) | curses.A_BOLD) add_name = user( screen, y // 2 - 4, x // 2 - 10 ) # calling fn user for username, password and email @@ -452,7 +452,7 @@ def modify_account(screen): screen.border() y, x = screen.getmaxyx() global loggedin, quitting, U - screen.addstr(1, x // 2 - 8, "MODIFY ACCOUNT SETTINGS") + screen.addstr(1, x // 2 - 8, "MODIFY ACCOUNT SETTINGS", curses.color_pair(3) | curses.A_BOLD) if loggedin == False: screen.addstr( y // 2, @@ -522,7 +522,7 @@ def view_account(screen): screen.clear() screen.refresh() screen.border() - screen.addstr(1, x // 2 - 9, "VIEW ACCOUNT DETAILS") + screen.addstr(1, x // 2 - 9, "VIEW ACCOUNT DETAILS", curses.color_pair(3) | curses.A_BOLD) if not loggedin: screen.addstr( y // 2, @@ -568,6 +568,7 @@ def delete(screen): screen.clear() screen.refresh() screen.border() + screen.addstr(1, x // 2 - 6, "DELETE ACCOUNT", curses.color_pair(3) | curses.A_BOLD) if loggedin == False: screen.addstr( y // 2, @@ -645,7 +646,7 @@ def forgotpassword(screen): screen.clear() screen.refresh() y, x = screen.getmaxyx() - screen.addstr(1, x // 2 - 7, "FORGOT PASSWORD") + screen.addstr(1, x // 2 - 7, "FORGOT PASSWORD", curses.color_pair(3) | curses.A_BOLD) screen.refresh() global quitting usernamelist = list_getter("username") @@ -770,13 +771,13 @@ def logout(screen): screen.clear() screen.refresh() scree.border() - screen.addstr(1, x // 2 - 2, "LOGOUT") + screen.addstr(1, x // 2 - 2, "LOGOUT", curses.color_pair(3) | curses.A_BOLD) screen.addstr(y // 2, 5, "Logging out of your account...") global loggedin, U, gamerid loggedin = False U = gamerid = None screen.refresh() - sleep(5) + sleep(3) screen.clear() screen.refresh() screenhandler(screen) @@ -795,7 +796,7 @@ def leaderboard(screen): screen.clear() screen.border() screen.refresh() - screen.addstr(1, x // 2 - 5, "LEADERBOARD", curses.A_BOLD) + screen.addstr(1, x // 2 - 5, "LEADERBOARD", curses.color_pair(3) | curses.A_BOLD) screen.addstr(3, x // 2 - 2, f"{tables[current_page].split('_')[0].upper()}", curses.color_pair(6) | curses.A_BOLD) res = get( f"SELECT p.gamerid,\ diff --git a/maze/modules/about.py b/maze/modules/about.py index cee5c21..66895e5 100644 --- a/maze/modules/about.py +++ b/maze/modules/about.py @@ -1,50 +1,50 @@ import maze.menu - +import curses def about(screen): y, x = screen.getmaxyx() screen.clear() screen.refresh() screen.border() - screen.addstr(1, x // 2 - 2, "ABOUT US") + screen.addstr(1, x // 2 - 2, "ABOUT US", curses.color_pair(3) | curses.A_BOLD) screen.addstr( 3, 5, "This game which you have played was developed as a Computer Science Project by", ) - screen.addstr(5, 5, "B. Adithya\t\t\t - XII - C - Roll no: 3") - screen.addstr(6, 5, "V. Kirthivaasan\t\t - XII - C - Roll no: 17") - screen.addstr(7, 5, "R. Manwanthakrishnan\t - XII - C - Roll no: 21") + screen.addstr(5, 5, "B. Adithya\t\t\t - XII - C - Roll no: 3", curses.A_BOLD) + screen.addstr(6, 5, "V. Kirthivaasan\t\t - XII - C - Roll no: 17", curses.A_BOLD) + screen.addstr(7, 5, "R. Manwanthakrishnan\t - XII - C - Roll no: 22", curses.A_BOLD) screen.addstr( 9, 5, - "This game aims at generating a maze which always has a path towards the right bottom corner", + "There are a series of retro games namely the maze, pong, snake and wordle.", ) screen.addstr( - 10, 5, "by using a famous generation algorithm named Depth First Search (DFS)." + 10, 5, "The maze is generated which always has a path towards the right bottom corner by using " ) - screen.addstr( - 11, - 5, - "This game makes use of the 'curses' module which runs on any operating system in the native terminal without", - ) - screen.addstr(12, 5, "use of any other external modules.") + screen.addstr(11, 5, "a famous generation algorithm named Depth First Search (DFS).") screen.addstr( 13, 5, - "It makes use of SQL tables to store login details and maintain a leaderboard.", + "This game makes use of the 'curses' module which runs on any operating system in the native terminal.", ) screen.addstr( 14, 5, - "It also makes use of binary files to save and load mazes.", + "It makes use of SQL tables to store login details and maintain a leaderboard.", ) - screen.addstr(16, 5, "This project has been an absolute blast to make.") screen.addstr( - 17, 5, "We thank you for playing this! Hope you liked it as much as we did!" + 15, + 5, + "It also makes use of binary files to save and load mazes and other credentials necessary.", ) - screen.addstr(20, 5, "Signing off,") - screen.addstr(21, 5, "The Labyrinth") + screen.addstr(17, 5, "This project has been an absolute blast to make.") + screen.addstr( + 18, 5, "We thank you for playing this! Hope you liked it as much as we did!" + ) + screen.addstr(21, 5, "Signing off,") + screen.addstr(22, 5, "The Labyrinth") screen.addstr(y - 2, x - 31, "Press Esc to exit this screen.") screen.refresh() while True: diff --git a/maze/modules/maze.py b/maze/modules/maze.py index aed3a87..8d00245 100644 --- a/maze/modules/maze.py +++ b/maze/modules/maze.py @@ -216,8 +216,8 @@ def coords(node): def construction_demo(maze, screen): - head = (".", curses.color_pair(3)) - trail = (".", curses.color_pair(2)) + head = (".", curses.color_pair(5) | curses.A_BOLD) + trail = (".", curses.color_pair(2) | curses.A_BOLD) draw_path( maze.track(), screen, delay=0.01, head=head, trail=trail, skip_first=False ) @@ -290,21 +290,20 @@ def pathfinding_demo( elif current_coords[0] == won_coords[0] and current_coords[1] == won_coords[1]: screen.clear() screen.refresh() + screen.border() + winmsg = """ + \t\t\t██ ██ ██████ ██ ██ ██ ██ ██████ ███ ██ ██ + \t\t\t ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ + \t\t\t ████ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██ + \t\t\t ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ + \t\t\t ██ ██████ ██████ ███ ███ ██████ ██ ████ ██""" screen.addstr( - 0, - 0, - """ - -██ ██ ██████ ██ ██ ██ ██ ██████ ███ ██ ██ - ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ - ████ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██ - ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ - ██ ██████ ██████ ███ ███ ██████ ██ ████ ██ - - - -""", + maxy // 2 - 5, + maxx // 2 - 31, + winmsg, + curses.color_pair(5) ) + screen.border() screen.refresh() global WON WON = WON + 1 @@ -317,7 +316,7 @@ def pathfinding_demo( # if state & curses.BUTTON3_PRESSED: # reset(finish, cell, curses.color_pair(2)) # elif state & curses.BUTTON1_PRESSED: - # reset(start, cell, curses.color_pair(3)) + # reset(start, cell, curses.color_pair(1)) elif key == curses.KEY_UP: if ( @@ -410,64 +409,6 @@ def pathfinding_demo( # print(screen.instr(current_coords[0],current_coords[1]+1,1).decode("utf-8"), "RSIDE PRESS") -# def menu(screen): -# y, x = screen.getmaxyx() -# screen.clear() -# screen.refresh() -# text = """ -# \t\t\t██ █████ ██████ ██ ██ ██████ ██ ███ ██ ████████ ██ ██ -# \t\t\t██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ -# \t\t\t██ ███████ ██████ ████ ██████ ██ ██ ██ ██ ██ ███████ -# \t\t\t██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -# \t\t\t███████ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ██ ██ ██""" -# -# screen.addstr(1, 5, str(text)) -# screen.addstr(10, x // 2 - 2, "MENU") -# screen.addstr(13, 1, "space - Play") -# screen.addstr(14, 1, "f - Load game from file") -# screen.addstr(15, 1, "a - Account Settings") -# screen.addstr(16, 1, "l - Leaderboard") -# screen.addstr(17, 1, "x - About") -# screen.addstr(18, 1, "esc - Quit") -# screen.border() -# while True: -# key = screen.getch() -# if key == ord(" "): -# play(screen) -# elif key == 27: -# screen.clear() -# screen.refresh() -# screen.border() -# screen.addstr(y // 2 - 5, x // 2 - 5, "THANK YOU!") -# while True: -# breakkey = screen.getch() -# if breakkey: -# time.sleep(1) -# sys.exit() -# elif key == ord("a"): -# database.screenhandler(screen) -# elif key == ord("l"): -# database.leaderboard(screen) -# elif key == ord("x"): -# about(screen) -# elif key == ord("f"): -# present = sl.check() -# if present: -# maze = sl.load(screen) -# if maze: -# play(screen, maze[0], maze[1], maze[2]) -# return -# else: -# screen.addstr( -# 20, 5, "No saved mazes present. Press enter to continue..." -# ) -# while True: -# key2 = screen.getch() -# if key2 == 10: -# screen.addstr(20, 5, " " * (x - 10)) -# break - - def play( screen, loadedmaze=None, @@ -484,16 +425,18 @@ def play( screen.clear() screen.refresh() screen.border() - screen.addstr(y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score)))) + screen.addstr(y // 2 - 5, x // 2 - 7, str("Your score is: " + str(int(score))), curses.color_pair(3) | curses.A_BOLD) res = database.Update_score(int(score), game) if res == "guest": screen.addstr( height - 1, - 5, + 31, "You are not signed in. You will lose your score if you proceed.", + curses.color_pair(1) | curses.A_BOLD ) screen.addstr( - height, 5, "Do you want to login and save your progress? (y/n)" + height, 37, "Do you want to login and save your progress? (y/n)", + curses.color_pair(1) | curses.A_BOLD ) while True: key = screen.getch() @@ -551,37 +494,16 @@ def play( score = 0 guestswitch(score, game="maze") - # res = database.Update_score(int(score)) - # if res == "guest": - # screen.addstr( - # height - 1, - # 5, - # "You are not signed in. You will lose your score if you proceed.", - # ) - # screen.addstr( - # height, 5, "Do you want to login and save your progress? (y/n)" - # ) - # while True: - # key = screen.getch() - # if key == ord("y"): - # database.login(screen, calledby=int(score)) - # break - # elif key == ord("n"): - # break - # screen.clear() - # screen.refresh() - # came_out = 0 - # menu(screen) - # return - def main(screen): screen.nodelay(True) curses.curs_set(False) curses.mousemask(curses.ALL_MOUSE_EVENTS) - curses.init_pair(1, curses.COLOR_BLUE, curses.COLOR_BLACK) + curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) - curses.init_pair(3, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) + curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK) + curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK) screen.clear() screen.refresh() y, x = screen.getmaxyx() diff --git a/maze/modules/maze_saveandload.py b/maze/modules/maze_saveandload.py index d3eabc3..e367de6 100644 --- a/maze/modules/maze_saveandload.py +++ b/maze/modules/maze_saveandload.py @@ -1,6 +1,7 @@ import os import pickle from time import sleep +import curses import maze.menu as m @@ -50,19 +51,21 @@ def load(screen): y, x = screen.getmaxyx() screen.clear() screen.refresh() - screen.addstr(2, x // 2 - 4, "LOAD MAZE") + screen.border() + screen.addstr(2, x // 2 - 4, "LOAD MAZE", curses.color_pair(3) | curses.A_BOLD) mazes = os.listdir("saves") - sy = 4 + sy = 5 for i in range(len(mazes)): + msg = f"{str(i + 1)}. Maze {((mazes[i].replace('.maze', '')).split('_'))[1]} - {((mazes[i].replace('.maze', '')).split('_'))[2]}" screen.addstr( sy, - 10, - f"{str(i + 1)}. Maze {((mazes[i].replace('.maze', '')).split('_'))[1]} - {((mazes[i].replace('.maze', '')).split('_'))[2]}", + x // 2 - len(msg) // 2, + msg ) sy += 1 while True: - screen.addstr(y // 2 + 5, 0, "Enter preferred maze number: ") - num = input(y // 2 + 5, 30, screen) + screen.addstr(y // 2 + 5, x // 2 - 15, "Enter preferred maze number: ") + num = input(y // 2 + 5, x // 2 + 14, screen) if num and type(int(num)) == type(0): num = int(num) - 1 else: @@ -73,7 +76,7 @@ def load(screen): if num < len(mazes): break else: - screen.addstr(y - 1, 0, "Entered maze doesn't exist. Please try again.") + screen.addstr(y - 5, x // 2 - 23, "Entered maze doesn't exist. Please try again.", curses.color_pair(1)) while True: key = screen.getch() if key == 10: diff --git a/pong.py b/pong.py index 8b015f7..c615ba2 100644 --- a/pong.py +++ b/pong.py @@ -206,3 +206,5 @@ def main(screen): player_thread.run() time.sleep(1) m1.play(screen, executeguest=True, outerscore=score.score, outergame="pong") + maze.menu.menu(stdscr) + return diff --git a/snake.py b/snake.py index 2c9bd25..b9e8a28 100644 --- a/snake.py +++ b/snake.py @@ -33,9 +33,14 @@ def main(stdscr): # initial settings curses.curs_set(0) stdscr.nodelay(1) + curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) + curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK) + curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK) + curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK) stdscr.timeout(100) stdscr.clear() stdscr.refresh() + # create a game box sh, sw = stdscr.getmaxyx() box = [[3, 3], [sh - 3, sw - 3]] # [[ul_y, ul_x], [dr_y, dr_x]] @@ -47,11 +52,11 @@ def main(stdscr): # draw snake for y, x in snake: - stdscr.addstr(y, x, "#") + stdscr.addstr(y, x, "█", curses.color_pair(3) | curses.A_BOLD) # create food food = create_food(snake, box) - stdscr.addstr(food[0], food[1], "*") + stdscr.addstr(food[0], food[1], "🍎") # print score score = 0 @@ -84,7 +89,7 @@ def main(stdscr): new_head = [head[0] - 1, head[1]] # insert and print new head - stdscr.addstr(new_head[0], new_head[1], "#") + stdscr.addstr(new_head[0], new_head[1], "█", curses.color_pair(3) | curses.A_BOLD) snake.insert(0, new_head) # if sanke head is on food @@ -96,7 +101,7 @@ def main(stdscr): # create new food food = create_food(snake, box) - stdscr.addstr(food[0], food[1], "*") + stdscr.addstr(food[0], food[1], "🍎", curses.color_pair(1) | curses.A_BOLD) # increase speed of game stdscr.timeout(100 - (len(snake) // 3) % 90) @@ -112,7 +117,8 @@ def main(stdscr): or snake[0] in snake[1:] ): msg = "Game Over!" - stdscr.addstr(sh // 2, sw // 2 - len(msg) // 2, msg) + stdscr.addstr(sh // 2, sw // 2 - len(msg) // 2, msg, curses.color_pair(1) | curses.A_BOLD) + stdscr.addstr(sh // 2 + 1, sw // 2 - 8, "The Score is: "+str(score), curses.color_pair(3) | curses.A_BOLD) while stdscr.getch() == -1: pass time.sleep(2) diff --git a/starter.py b/starter.py index 3a1921e..783887b 100644 --- a/starter.py +++ b/starter.py @@ -49,9 +49,8 @@ if len(sys.argv) == 1: bruh() except KeyboardInterrupt: pass - finally: - player.sql.close() - sys.exit() + player.sql.close() + sys.exit() else: if sys.argv[1] == "dumpsample": getcreds() diff --git a/wordle-curses/dictionary.py b/wordle/dictionary.py similarity index 96% rename from wordle-curses/dictionary.py rename to wordle/dictionary.py index 64da3a1..0de8480 100644 --- a/wordle-curses/dictionary.py +++ b/wordle/dictionary.py @@ -1,6 +1,4 @@ -import curses import requests -import json app_id = "4a8fca56" app_key = "85885b5929e5b14402e75fcb4898d7f5" @@ -23,7 +21,7 @@ def defnsyn(w): baseindex = s1[lexicalCategories.index("verb")]['entries'][0]['senses'][0] defn = (baseindex['shortDefinitions'][0]) if "synonyms" in baseindex: - no = 3 if len(baseindex["synonyms"]) > 3 else len(baseindex["synonyms"]) + no = 2 if len(baseindex["synonyms"]) > 3 else len(baseindex["synonyms"]) while no: synonyms.append(baseindex["synonyms"][no]["text"]) no -= 1 diff --git a/wordle-curses/solver.py b/wordle/solver.py similarity index 100% rename from wordle-curses/solver.py rename to wordle/solver.py diff --git a/wordle-curses/wordle-solver.py b/wordle/wordle-solver.py similarity index 97% rename from wordle-curses/wordle-solver.py rename to wordle/wordle-solver.py index 74476da..4b7bb42 100644 --- a/wordle-curses/wordle-solver.py +++ b/wordle/wordle-solver.py @@ -1,4 +1,4 @@ -words = open("words.txt").read().split() +words = open("wordle\\words.txt").read().split() guesslist = [] maxguesses = 6 diff --git a/wordle-curses/main_readable.py b/wordle/wordle.py similarity index 81% rename from wordle-curses/main_readable.py rename to wordle/wordle.py index 998671f..4e353d9 100644 --- a/wordle-curses/main_readable.py +++ b/wordle/wordle.py @@ -1,9 +1,12 @@ # A slightly more readable version of wordle-curses import curses, random, time -from dictionary import defnsyn +from wordle.dictionary import defnsyn +import maze.menu +import maze.modules.maze as m1 -words = open("words.txt", "r").read().split("\n") +quitwordle = False +words = open("wordle\\words.txt", "r").read().split("\n") colorPairBindings = {"c": 2, "w": 3, "n": 7, "u": 6} completionMessages = [ "", @@ -80,7 +83,9 @@ def getWord(s, y): if k == 8: # backspace word = word[:-1] elif k == 27: # esc - exit() + global quitwordle + quitwordle = True + return "hello" elif chr(k) == "\n" and len(word) == 5: return word elif chr(k).isalpha() and len(word) < 5: @@ -90,13 +95,16 @@ def getWord(s, y): def run(s): s.clear() word = random.choice(words) #chosen word - print("Chosen word: ", word) + with open("log.txt", "a") as f: + f.write("Chosen word: "+ word+"\n") defn, synonyms = defnsyn(word) guesses = [] # stores each guess and its result alphabet = ["u"] * 26 # current status of each letter whether used or not # c = correct positon, w = correct letter but not position, n = wrong letter, u = not used # "ccccc" means all letters are in correct spot while not (len(guesses)) or (guesses[-1][1] != "ccccc" and len(guesses) < 6): + if quitwordle: + return render(s, guesses, alphabet) # Update current state of board from start guess = getWord(s, len(guesses) * 2 + 7).lower() if not (guess in words): # Check if given word is valid @@ -124,11 +132,28 @@ def run(s): s.addstr(len(guesses) * 2 + 9, 8, defn) s.addstr(len(guesses) * 2 + 10, 0, "Some synonyms: ", curses.color_pair(2)) s.addstr(len(guesses) * 2 + 10, 16, synonyms) - s.addstr(len(guesses) * 2 + 11, 0, "[esc] to quit, [enter] to play again", curses.color_pair(3)) + if len(guesses) == 6 and guesses[-1][1] != "ccccc": + guesses.append("Bruh") + finalscore = allocatescore(guesses) + return finalscore + +def allocatescore(guesses): + finalscore = 0 + if len(guesses) <= 3: + finalscore = 50 + elif len(guesses) == 4: + finalscore = 40 + elif len(guesses) == 5: + finalscore = 30 + elif len(guesses) == 6: + finalscore = 20 + return finalscore # Main function def main(s): # Initialize colors + global quitwordle + quitwordle = False for p in [ (1, curses.COLOR_RED), (2, curses.COLOR_GREEN), @@ -138,10 +163,11 @@ def main(s): ]: curses.init_pair(p[0], p[1], curses.COLOR_BLACK) # Run game - while True: - run(s) - if s.getch() == 27: # esc - break - -if __name__ == "__main__": - curses.wrapper(main) \ No newline at end of file + finalscore = run(s) + with open("log.txt", "a") as f: + f.write(str(finalscore)+"\n") + while s.getch() == -1: + pass + m1.play(s, executeguest=True, outerscore=finalscore, outergame="wordle") + maze.menu.menu(s) + return \ No newline at end of file diff --git a/wordle-curses/words.txt b/wordle/words.txt similarity index 100% rename from wordle-curses/words.txt rename to wordle/words.txt