Huge amount of UI improvement + Wordle scoring. Hopefully the final review.
This commit is contained in:
parent
dea8f183be
commit
d318ce41a4
13 changed files with 141 additions and 181 deletions
33
maze/menu.py
33
maze/menu.py
|
@ -8,13 +8,14 @@ import maze.modules.PlayerBase_func as database
|
||||||
import pong
|
import pong
|
||||||
import snake
|
import snake
|
||||||
from maze.modules.about import about
|
from maze.modules.about import about
|
||||||
|
import wordle.wordle as wordlegame
|
||||||
|
|
||||||
def menu(screen):
|
def menu(screen):
|
||||||
exit = False
|
exit = False
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.nodelay(True)
|
screen.nodelay(True)
|
||||||
|
curses.init_pair(5, curses.COLOR_MAGENTA, curses.COLOR_BLACK)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
text = """
|
text = """
|
||||||
\t\t\t██ █████ ██████ ██ ██ ██████ ██ ███ ██ ████████ ██ ██
|
\t\t\t██ █████ ██████ ██ ██ ██████ ██ ███ ██ ████████ ██ ██
|
||||||
|
@ -23,14 +24,14 @@ def menu(screen):
|
||||||
\t\t\t██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
\t\t\t██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
\t\t\t███████ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ██ ██ ██"""
|
\t\t\t███████ ██ ██ ██████ ██ ██ ██ ██ ██ ████ ██ ██ ██"""
|
||||||
|
|
||||||
screen.addstr(1, 5, str(text))
|
screen.addstr(1, x // 2 - 34, str(text), curses.color_pair(5))
|
||||||
screen.addstr(10, x // 2 - 2, "MENU")
|
screen.addstr(10, x // 2 - 2, "MENU", curses.color_pair(3) | curses.A_BOLD)
|
||||||
screen.addstr(13, 1, "space - Play")
|
screen.addstr(13, x // 2 - 6, "space - PLAY", curses.A_BOLD)
|
||||||
screen.addstr(14, 1, "f - Load game from file")
|
screen.addstr(15, x // 2 - 11, "f - LOAD GAME FROM FILE", curses.A_BOLD)
|
||||||
screen.addstr(15, 1, "a - Account Settings")
|
screen.addstr(17, x // 2 - 10, "a - ACCOUNT SETTINGS", curses.A_BOLD)
|
||||||
screen.addstr(16, 1, "l - Leaderboard")
|
screen.addstr(19, x // 2 - 7, "l - LEADERBOARD", curses.A_BOLD)
|
||||||
screen.addstr(17, 1, "x - About")
|
screen.addstr(21, x // 2 - 4, "x - ABOUT", curses.A_BOLD)
|
||||||
screen.addstr(18, 1, "esc - Quit")
|
screen.addstr(23, x // 2 - 4, "esc - QUIT", curses.A_BOLD)
|
||||||
screen.border()
|
screen.border()
|
||||||
while True:
|
while True:
|
||||||
if exit:
|
if exit:
|
||||||
|
@ -40,11 +41,11 @@ def menu(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
screen.border()
|
||||||
screen.addstr(1, x // 2 - 2, "PLAY")
|
screen.addstr(1, x // 2 - 2, "PLAY", curses.color_pair(3) | curses.A_BOLD)
|
||||||
screen.addstr(y // 2 - 4, x // 2 - 2, "1. MAZE")
|
screen.addstr(y // 2 - 4, x // 2 - 2, "1. MAZE", curses.A_BOLD)
|
||||||
screen.addstr(y // 2 - 2, x // 2 - 2, "2. PONG")
|
screen.addstr(y // 2 - 2, x // 2 - 2, "2. PONG", curses.A_BOLD)
|
||||||
screen.addstr(y // 2, x // 2 - 2, "3. SNAKE")
|
screen.addstr(y // 2, x // 2 - 2, "3. SNAKE", curses.A_BOLD)
|
||||||
screen.addstr(y // 2 + 2, x // 2 - 2, "4. WORDLE")
|
screen.addstr(y // 2 + 2, x // 2 - 2, "4. WORDLE", curses.A_BOLD)
|
||||||
while True:
|
while True:
|
||||||
key2 = screen.getch()
|
key2 = screen.getch()
|
||||||
if key2 == ord("1"):
|
if key2 == ord("1"):
|
||||||
|
@ -54,7 +55,9 @@ def menu(screen):
|
||||||
elif key2 == ord("3"):
|
elif key2 == ord("3"):
|
||||||
snake.main(screen)
|
snake.main(screen)
|
||||||
elif key2 == ord("4"):
|
elif key2 == ord("4"):
|
||||||
pass
|
screen.nodelay(False)
|
||||||
|
screen.keypad(False)
|
||||||
|
wordlegame.main(screen)
|
||||||
elif key2 == 27:
|
elif key2 == 27:
|
||||||
menu(screen)
|
menu(screen)
|
||||||
break
|
break
|
||||||
|
|
|
@ -106,9 +106,9 @@ def screenhandler(screen): # MAIN MENU
|
||||||
global loggedin, U, gamerid
|
global loggedin, U, gamerid
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
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:
|
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 - 3, w // 2 - 4, "1. Login")
|
||||||
screen.addstr(h // 2 - 2, w // 2 - 8, "2. Create Account")
|
screen.addstr(h // 2 - 2, w // 2 - 8, "2. Create Account")
|
||||||
screen.addstr(h // 2 - 1, w // 2 - 12, "3. Modify account details")
|
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()
|
screen.border()
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
usernamelist = list_getter("username")
|
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: ")
|
screen.addstr(y // 2 - 2, x // 2 - 7, "Username: ")
|
||||||
while True:
|
while True:
|
||||||
inputU = input(y // 2 - 2, x // 2 + 3, screen)
|
inputU = input(y // 2 - 2, x // 2 + 3, screen)
|
||||||
|
@ -253,21 +253,21 @@ def login(screen, calledby=None): # Function to log in
|
||||||
loggedin = True
|
loggedin = True
|
||||||
gamerid = res[0][1]
|
gamerid = res[0][1]
|
||||||
U = inputU
|
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:
|
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()
|
screen.refresh()
|
||||||
sleep(3)
|
sleep(3)
|
||||||
Update_score(calledby[0], calledby[1])
|
Update_score(calledby[0], calledby[1])
|
||||||
return
|
return
|
||||||
else:
|
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()
|
screen.refresh()
|
||||||
sleep(3)
|
sleep(3)
|
||||||
screenhandler(screen)
|
screenhandler(screen)
|
||||||
return
|
return
|
||||||
else:
|
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:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
if key == 10:
|
if key == 10:
|
||||||
|
@ -397,7 +397,7 @@ def new_add(screen, calledby=None):
|
||||||
screen.border()
|
screen.border()
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
global quitting
|
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(
|
add_name = user(
|
||||||
screen, y // 2 - 4, x // 2 - 10
|
screen, y // 2 - 4, x // 2 - 10
|
||||||
) # calling fn user for username, password and email
|
) # calling fn user for username, password and email
|
||||||
|
@ -452,7 +452,7 @@ def modify_account(screen):
|
||||||
screen.border()
|
screen.border()
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
global loggedin, quitting, U
|
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:
|
if loggedin == False:
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
y // 2,
|
y // 2,
|
||||||
|
@ -522,7 +522,7 @@ def view_account(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
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:
|
if not loggedin:
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
y // 2,
|
y // 2,
|
||||||
|
@ -568,6 +568,7 @@ def delete(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
screen.border()
|
||||||
|
screen.addstr(1, x // 2 - 6, "DELETE ACCOUNT", curses.color_pair(3) | curses.A_BOLD)
|
||||||
if loggedin == False:
|
if loggedin == False:
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
y // 2,
|
y // 2,
|
||||||
|
@ -645,7 +646,7 @@ def forgotpassword(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
y, x = screen.getmaxyx()
|
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()
|
screen.refresh()
|
||||||
global quitting
|
global quitting
|
||||||
usernamelist = list_getter("username")
|
usernamelist = list_getter("username")
|
||||||
|
@ -770,13 +771,13 @@ def logout(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
scree.border()
|
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...")
|
screen.addstr(y // 2, 5, "Logging out of your account...")
|
||||||
global loggedin, U, gamerid
|
global loggedin, U, gamerid
|
||||||
loggedin = False
|
loggedin = False
|
||||||
U = gamerid = None
|
U = gamerid = None
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
sleep(5)
|
sleep(3)
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screenhandler(screen)
|
screenhandler(screen)
|
||||||
|
@ -795,7 +796,7 @@ def leaderboard(screen):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.border()
|
screen.border()
|
||||||
screen.refresh()
|
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)
|
screen.addstr(3, x // 2 - 2, f"{tables[current_page].split('_')[0].upper()}", curses.color_pair(6) | curses.A_BOLD)
|
||||||
res = get(
|
res = get(
|
||||||
f"SELECT p.gamerid,\
|
f"SELECT p.gamerid,\
|
||||||
|
|
|
@ -1,50 +1,50 @@
|
||||||
import maze.menu
|
import maze.menu
|
||||||
|
import curses
|
||||||
|
|
||||||
def about(screen):
|
def about(screen):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
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(
|
screen.addstr(
|
||||||
3,
|
3,
|
||||||
5,
|
5,
|
||||||
"This game which you have played was developed as a Computer Science Project by",
|
"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(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")
|
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: 21")
|
screen.addstr(7, 5, "R. Manwanthakrishnan\t - XII - C - Roll no: 22", curses.A_BOLD)
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
9,
|
9,
|
||||||
5,
|
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(
|
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(
|
screen.addstr(11, 5, "a famous generation algorithm named Depth First Search (DFS).")
|
||||||
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(
|
screen.addstr(
|
||||||
13,
|
13,
|
||||||
5,
|
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(
|
screen.addstr(
|
||||||
14,
|
14,
|
||||||
5,
|
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(
|
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(17, 5, "This project has been an absolute blast to make.")
|
||||||
screen.addstr(21, 5, "The Labyrinth")
|
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.addstr(y - 2, x - 31, "Press Esc to exit this screen.")
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -216,8 +216,8 @@ def coords(node):
|
||||||
|
|
||||||
|
|
||||||
def construction_demo(maze, screen):
|
def construction_demo(maze, screen):
|
||||||
head = (".", curses.color_pair(3))
|
head = (".", curses.color_pair(5) | curses.A_BOLD)
|
||||||
trail = (".", curses.color_pair(2))
|
trail = (".", curses.color_pair(2) | curses.A_BOLD)
|
||||||
draw_path(
|
draw_path(
|
||||||
maze.track(), screen, delay=0.01, head=head, trail=trail, skip_first=False
|
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]:
|
elif current_coords[0] == won_coords[0] and current_coords[1] == won_coords[1]:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
screen.border()
|
||||||
|
winmsg = """
|
||||||
|
\t\t\t██ ██ ██████ ██ ██ ██ ██ ██████ ███ ██ ██
|
||||||
|
\t\t\t ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
|
||||||
|
\t\t\t ████ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
\t\t\t ██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
|
||||||
|
\t\t\t ██ ██████ ██████ ███ ███ ██████ ██ ████ ██"""
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
0,
|
maxy // 2 - 5,
|
||||||
0,
|
maxx // 2 - 31,
|
||||||
"""
|
winmsg,
|
||||||
|
curses.color_pair(5)
|
||||||
██ ██ ██████ ██ ██ ██ ██ ██████ ███ ██ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ██ ██
|
|
||||||
████ ██ ██ ██ ██ ██ █ ██ ██ ██ ██ ██ ██ ██
|
|
||||||
██ ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██
|
|
||||||
██ ██████ ██████ ███ ███ ██████ ██ ████ ██
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
""",
|
|
||||||
)
|
)
|
||||||
|
screen.border()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
global WON
|
global WON
|
||||||
WON = WON + 1
|
WON = WON + 1
|
||||||
|
@ -317,7 +316,7 @@ def pathfinding_demo(
|
||||||
# if state & curses.BUTTON3_PRESSED:
|
# if state & curses.BUTTON3_PRESSED:
|
||||||
# reset(finish, cell, curses.color_pair(2))
|
# reset(finish, cell, curses.color_pair(2))
|
||||||
# elif state & curses.BUTTON1_PRESSED:
|
# elif state & curses.BUTTON1_PRESSED:
|
||||||
# reset(start, cell, curses.color_pair(3))
|
# reset(start, cell, curses.color_pair(1))
|
||||||
|
|
||||||
elif key == curses.KEY_UP:
|
elif key == curses.KEY_UP:
|
||||||
if (
|
if (
|
||||||
|
@ -410,64 +409,6 @@ def pathfinding_demo(
|
||||||
# print(screen.instr(current_coords[0],current_coords[1]+1,1).decode("utf-8"), "RSIDE PRESS")
|
# 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(
|
def play(
|
||||||
screen,
|
screen,
|
||||||
loadedmaze=None,
|
loadedmaze=None,
|
||||||
|
@ -484,16 +425,18 @@ def play(
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
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)
|
res = database.Update_score(int(score), game)
|
||||||
if res == "guest":
|
if res == "guest":
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
height - 1,
|
height - 1,
|
||||||
5,
|
31,
|
||||||
"You are not signed in. You will lose your score if you proceed.",
|
"You are not signed in. You will lose your score if you proceed.",
|
||||||
|
curses.color_pair(1) | curses.A_BOLD
|
||||||
)
|
)
|
||||||
screen.addstr(
|
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:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
|
@ -551,37 +494,16 @@ def play(
|
||||||
score = 0
|
score = 0
|
||||||
|
|
||||||
guestswitch(score, game="maze")
|
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):
|
def main(screen):
|
||||||
screen.nodelay(True)
|
screen.nodelay(True)
|
||||||
curses.curs_set(False)
|
curses.curs_set(False)
|
||||||
curses.mousemask(curses.ALL_MOUSE_EVENTS)
|
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(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.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import os
|
import os
|
||||||
import pickle
|
import pickle
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
import curses
|
||||||
|
|
||||||
import maze.menu as m
|
import maze.menu as m
|
||||||
|
|
||||||
|
@ -50,19 +51,21 @@ def load(screen):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
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")
|
mazes = os.listdir("saves")
|
||||||
sy = 4
|
sy = 5
|
||||||
for i in range(len(mazes)):
|
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(
|
screen.addstr(
|
||||||
sy,
|
sy,
|
||||||
10,
|
x // 2 - len(msg) // 2,
|
||||||
f"{str(i + 1)}. Maze {((mazes[i].replace('.maze', '')).split('_'))[1]} - {((mazes[i].replace('.maze', '')).split('_'))[2]}",
|
msg
|
||||||
)
|
)
|
||||||
sy += 1
|
sy += 1
|
||||||
while True:
|
while True:
|
||||||
screen.addstr(y // 2 + 5, 0, "Enter preferred maze number: ")
|
screen.addstr(y // 2 + 5, x // 2 - 15, "Enter preferred maze number: ")
|
||||||
num = input(y // 2 + 5, 30, screen)
|
num = input(y // 2 + 5, x // 2 + 14, screen)
|
||||||
if num and type(int(num)) == type(0):
|
if num and type(int(num)) == type(0):
|
||||||
num = int(num) - 1
|
num = int(num) - 1
|
||||||
else:
|
else:
|
||||||
|
@ -73,7 +76,7 @@ def load(screen):
|
||||||
if num < len(mazes):
|
if num < len(mazes):
|
||||||
break
|
break
|
||||||
else:
|
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:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
if key == 10:
|
if key == 10:
|
||||||
|
|
2
pong.py
2
pong.py
|
@ -206,3 +206,5 @@ def main(screen):
|
||||||
player_thread.run()
|
player_thread.run()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
m1.play(screen, executeguest=True, outerscore=score.score, outergame="pong")
|
m1.play(screen, executeguest=True, outerscore=score.score, outergame="pong")
|
||||||
|
maze.menu.menu(stdscr)
|
||||||
|
return
|
||||||
|
|
16
snake.py
16
snake.py
|
@ -33,9 +33,14 @@ def main(stdscr):
|
||||||
# initial settings
|
# initial settings
|
||||||
curses.curs_set(0)
|
curses.curs_set(0)
|
||||||
stdscr.nodelay(1)
|
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.timeout(100)
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
|
|
||||||
# create a game box
|
# create a game box
|
||||||
sh, sw = stdscr.getmaxyx()
|
sh, sw = stdscr.getmaxyx()
|
||||||
box = [[3, 3], [sh - 3, sw - 3]] # [[ul_y, ul_x], [dr_y, dr_x]]
|
box = [[3, 3], [sh - 3, sw - 3]] # [[ul_y, ul_x], [dr_y, dr_x]]
|
||||||
|
@ -47,11 +52,11 @@ def main(stdscr):
|
||||||
|
|
||||||
# draw snake
|
# draw snake
|
||||||
for y, x in snake:
|
for y, x in snake:
|
||||||
stdscr.addstr(y, x, "#")
|
stdscr.addstr(y, x, "█", curses.color_pair(3) | curses.A_BOLD)
|
||||||
|
|
||||||
# create food
|
# create food
|
||||||
food = create_food(snake, box)
|
food = create_food(snake, box)
|
||||||
stdscr.addstr(food[0], food[1], "*")
|
stdscr.addstr(food[0], food[1], "🍎")
|
||||||
|
|
||||||
# print score
|
# print score
|
||||||
score = 0
|
score = 0
|
||||||
|
@ -84,7 +89,7 @@ def main(stdscr):
|
||||||
new_head = [head[0] - 1, head[1]]
|
new_head = [head[0] - 1, head[1]]
|
||||||
|
|
||||||
# insert and print new head
|
# 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)
|
snake.insert(0, new_head)
|
||||||
|
|
||||||
# if sanke head is on food
|
# if sanke head is on food
|
||||||
|
@ -96,7 +101,7 @@ def main(stdscr):
|
||||||
|
|
||||||
# create new food
|
# create new food
|
||||||
food = create_food(snake, box)
|
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
|
# increase speed of game
|
||||||
stdscr.timeout(100 - (len(snake) // 3) % 90)
|
stdscr.timeout(100 - (len(snake) // 3) % 90)
|
||||||
|
@ -112,7 +117,8 @@ def main(stdscr):
|
||||||
or snake[0] in snake[1:]
|
or snake[0] in snake[1:]
|
||||||
):
|
):
|
||||||
msg = "Game Over!"
|
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:
|
while stdscr.getch() == -1:
|
||||||
pass
|
pass
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
|
@ -49,7 +49,6 @@ if len(sys.argv) == 1:
|
||||||
bruh()
|
bruh()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
finally:
|
|
||||||
player.sql.close()
|
player.sql.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import curses
|
|
||||||
import requests
|
import requests
|
||||||
import json
|
|
||||||
|
|
||||||
app_id = "4a8fca56"
|
app_id = "4a8fca56"
|
||||||
app_key = "85885b5929e5b14402e75fcb4898d7f5"
|
app_key = "85885b5929e5b14402e75fcb4898d7f5"
|
||||||
|
@ -23,7 +21,7 @@ def defnsyn(w):
|
||||||
baseindex = s1[lexicalCategories.index("verb")]['entries'][0]['senses'][0]
|
baseindex = s1[lexicalCategories.index("verb")]['entries'][0]['senses'][0]
|
||||||
defn = (baseindex['shortDefinitions'][0])
|
defn = (baseindex['shortDefinitions'][0])
|
||||||
if "synonyms" in baseindex:
|
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:
|
while no:
|
||||||
synonyms.append(baseindex["synonyms"][no]["text"])
|
synonyms.append(baseindex["synonyms"][no]["text"])
|
||||||
no -= 1
|
no -= 1
|
|
@ -1,4 +1,4 @@
|
||||||
words = open("words.txt").read().split()
|
words = open("wordle\\words.txt").read().split()
|
||||||
|
|
||||||
guesslist = []
|
guesslist = []
|
||||||
maxguesses = 6
|
maxguesses = 6
|
|
@ -1,9 +1,12 @@
|
||||||
# A slightly more readable version of wordle-curses
|
# A slightly more readable version of wordle-curses
|
||||||
|
|
||||||
import curses, random, time
|
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}
|
colorPairBindings = {"c": 2, "w": 3, "n": 7, "u": 6}
|
||||||
completionMessages = [
|
completionMessages = [
|
||||||
"",
|
"",
|
||||||
|
@ -80,7 +83,9 @@ def getWord(s, y):
|
||||||
if k == 8: # backspace
|
if k == 8: # backspace
|
||||||
word = word[:-1]
|
word = word[:-1]
|
||||||
elif k == 27: # esc
|
elif k == 27: # esc
|
||||||
exit()
|
global quitwordle
|
||||||
|
quitwordle = True
|
||||||
|
return "hello"
|
||||||
elif chr(k) == "\n" and len(word) == 5:
|
elif chr(k) == "\n" and len(word) == 5:
|
||||||
return word
|
return word
|
||||||
elif chr(k).isalpha() and len(word) < 5:
|
elif chr(k).isalpha() and len(word) < 5:
|
||||||
|
@ -90,13 +95,16 @@ def getWord(s, y):
|
||||||
def run(s):
|
def run(s):
|
||||||
s.clear()
|
s.clear()
|
||||||
word = random.choice(words) #chosen word
|
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)
|
defn, synonyms = defnsyn(word)
|
||||||
guesses = [] # stores each guess and its result
|
guesses = [] # stores each guess and its result
|
||||||
alphabet = ["u"] * 26 # current status of each letter whether used or not
|
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
|
# c = correct positon, w = correct letter but not position, n = wrong letter, u = not used
|
||||||
# "ccccc" means all letters are in correct spot
|
# "ccccc" means all letters are in correct spot
|
||||||
while not (len(guesses)) or (guesses[-1][1] != "ccccc" and len(guesses) < 6):
|
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
|
render(s, guesses, alphabet) # Update current state of board from start
|
||||||
guess = getWord(s, len(guesses) * 2 + 7).lower()
|
guess = getWord(s, len(guesses) * 2 + 7).lower()
|
||||||
if not (guess in words): # Check if given word is valid
|
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 + 9, 8, defn)
|
||||||
s.addstr(len(guesses) * 2 + 10, 0, "Some synonyms: ", curses.color_pair(2))
|
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 + 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
|
# Main function
|
||||||
def main(s):
|
def main(s):
|
||||||
# Initialize colors
|
# Initialize colors
|
||||||
|
global quitwordle
|
||||||
|
quitwordle = False
|
||||||
for p in [
|
for p in [
|
||||||
(1, curses.COLOR_RED),
|
(1, curses.COLOR_RED),
|
||||||
(2, curses.COLOR_GREEN),
|
(2, curses.COLOR_GREEN),
|
||||||
|
@ -138,10 +163,11 @@ def main(s):
|
||||||
]:
|
]:
|
||||||
curses.init_pair(p[0], p[1], curses.COLOR_BLACK)
|
curses.init_pair(p[0], p[1], curses.COLOR_BLACK)
|
||||||
# Run game
|
# Run game
|
||||||
while True:
|
finalscore = run(s)
|
||||||
run(s)
|
with open("log.txt", "a") as f:
|
||||||
if s.getch() == 27: # esc
|
f.write(str(finalscore)+"\n")
|
||||||
break
|
while s.getch() == -1:
|
||||||
|
pass
|
||||||
if __name__ == "__main__":
|
m1.play(s, executeguest=True, outerscore=finalscore, outergame="wordle")
|
||||||
curses.wrapper(main)
|
maze.menu.menu(s)
|
||||||
|
return
|
Loading…
Reference in a new issue