Extremely less key jank, bordered all windows, tidying up, dynamic win detection logic

This commit is contained in:
adithyagenie 2022-11-05 00:52:19 +05:30
parent 4ba7cab763
commit e05ea8cdaa
4 changed files with 117 additions and 75 deletions

View file

@ -39,14 +39,14 @@ def post(
def databaseinit(): # Creates database if it doesn't exist def databaseinit(): # Creates database if it doesn't exist
try: try:
tempsql = mysql.connector.connect(host="localhost", user="root", passwd="") tempsql = mysql.connector.connect(host="localhost", user="root", passwd="root")
tempcon = tempsql.cursor() tempcon = tempsql.cursor()
tempcon.execute("CREATE DATABASE IF NOT EXISTS labyrinth") tempcon.execute("CREATE DATABASE IF NOT EXISTS labyrinth")
tempsql.commit() tempsql.commit()
global sql, con global sql, con
sql = mysql.connector.connect( sql = mysql.connector.connect(
host="localhost", user="root", passwd="", database="labyrinth" host="localhost", user="root", passwd="root", database="labyrinth"
) )
con = sql.cursor() con = sql.cursor()
return True return True
@ -103,6 +103,7 @@ def screenhandler(screen): # MAIN MENU
else: else:
screen.addstr(h // 2 + 2, w // 2 - 3, "6. Logout") screen.addstr(h // 2 + 2, w // 2 - 3, "6. Logout")
screen.addstr(h // 2 + 3, w // 2 - 3, "esc. Quit") screen.addstr(h // 2 + 3, w // 2 - 3, "esc. Quit")
screen.border()
screen.refresh() screen.refresh()
while True: while True:
key = screen.getch() key = screen.getch()
@ -111,11 +112,11 @@ def screenhandler(screen): # MAIN MENU
elif key == ord("2"): elif key == ord("2"):
new_add(screen) new_add(screen)
elif key == ord("3"): elif key == ord("3"):
Mod_account(screen) modify_account(screen)
elif key == ord("4"): elif key == ord("4"):
view_account(screen) view_account(screen)
elif key == ord("5"): elif key == ord("5"):
Delete(screen) delete(screen)
elif key == ord("6"): elif key == ord("6"):
if not loggedin: if not loggedin:
forgotpassword(screen) forgotpassword(screen)
@ -135,10 +136,11 @@ def screenwipe(screen, sx, sy): # Failed password and stuff reset from screen
for j in range(0, x - 1): for j in range(0, x - 1):
if screen.instr(i, j, 1) != " ": if screen.instr(i, j, 1) != " ":
screen.addstr(i, j, " ") screen.addstr(i, j, " ")
screen.border()
screen.refresh() screen.refresh()
def Input( def input(
y, x, screen, ispassword=False y, x, screen, ispassword=False
): # Function to get type-able inputs, with delete, esc and other keys ): # Function to get type-able inputs, with delete, esc and other keys
inputted = "" inputted = ""
@ -180,22 +182,24 @@ def login(screen, calledby=False): # Function to log in
global quitting, U, gamerid, loggedin global quitting, U, gamerid, loggedin
screen.clear() screen.clear()
screen.refresh() screen.refresh()
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")
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)
if quitting: if quitting:
screen.addstr("Going back to account settings...") screen.addstr("Going back to account settings...")
sleep(3) sleep(3)
quitting = False quitting = False
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screenhandler(screen)
return return
if inputU not in usernamelist: if inputU not in usernamelist:
screen.addstr( screen.addstr(
y // 2, 0, "Username does not exist. Do you want to create one? (y/n)" y // 2, 5, "Username does not exist. Do you want to create one? (y/n)"
) )
while True: while True:
key = screen.getch() key = screen.getch()
@ -220,9 +224,9 @@ def login(screen, calledby=False): # Function to log in
actualpass = (b64decode(res[0][0].encode("ascii"))).decode("ascii") actualpass = (b64decode(res[0][0].encode("ascii"))).decode("ascii")
screen.addstr(y // 2, x // 2 - 7, "Password: ") screen.addstr(y // 2, x // 2 - 7, "Password: ")
while True: while True:
inputP = Input(y // 2, x // 2 + 3, screen, ispassword=True) inputP = input(y // 2, x // 2 + 3, screen, ispassword=True)
if quitting: if quitting:
screen.addstr("Going back to account settings...") screen.addstr(y // 2 + 3, 5, "Going back to account settings...")
sleep(3) sleep(3)
screen.clear() screen.clear()
screen.refresh() screen.refresh()
@ -266,14 +270,14 @@ def user(
userlist = list_getter("username") userlist = list_getter("username")
screen.addstr(sy, sx, optionaltxt) screen.addstr(sy, sx, optionaltxt)
while True: while True:
Name = Input(sy, sx + len(optionaltxt), screen) Name = input(sy, sx + len(optionaltxt), screen)
if quitting: if quitting:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
return return
if Name in userlist: if Name in userlist:
screen.addstr( screen.addstr(
sy + 1, 0, "Username already exists, please choose a different one" sy + 1, 5, "Username already exists, please choose a different one"
) )
while True: while True:
key = screen.getch() key = screen.getch()
@ -297,7 +301,7 @@ def password(screen, sy, sx, optionaltxt="Enter Password: "):
screen.refresh() screen.refresh()
while True: while True:
screen.addstr(sy, sx, optionaltxt) screen.addstr(sy, sx, optionaltxt)
Password = Input(sy, sx + len(optionaltxt), screen, ispassword=True) Password = input(sy, sx + len(optionaltxt), screen, ispassword=True)
if quitting: if quitting:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
@ -327,7 +331,7 @@ def password(screen, sy, sx, optionaltxt="Enter Password: "):
return encoded_pass return encoded_pass
def Email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept email id def email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept email id
if quitting: if quitting:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
@ -338,7 +342,7 @@ def Email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept em
screen.refresh() screen.refresh()
while True: while True:
screen.addstr(sy, sx, optionaltxt) screen.addstr(sy, sx, optionaltxt)
email = Input(sy, sx + len(optionaltxt), screen) email = input(sy, sx + len(optionaltxt), screen)
if quitting: if quitting:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
@ -372,6 +376,7 @@ def Email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept em
def new_add(screen, calledby=False): def new_add(screen, calledby=False):
screen.clear() screen.clear()
screen.refresh() screen.refresh()
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")
@ -379,7 +384,7 @@ def new_add(screen, calledby=False):
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
add_password = password(screen, y // 2 - 2, x // 2 - 10) add_password = password(screen, y // 2 - 2, x // 2 - 10)
add_email = Email(screen, y // 2, x // 2 - 10) add_email = email(screen, y // 2, x // 2 - 10)
add_gamerid = "".join( add_gamerid = "".join(
random.choices(string.ascii_uppercase + string.digits, k=4) random.choices(string.ascii_uppercase + string.digits, k=4)
) # Generates random 4 character alphanumeric ) # Generates random 4 character alphanumeric
@ -387,7 +392,7 @@ def new_add(screen, calledby=False):
if add_name == None or add_password == None or add_email == None: if add_name == None or add_password == None or add_email == None:
screen.refresh() screen.refresh()
screen.addstr( screen.addstr(
y // 2 + 2, 0, "Cancelling account creation. Returning to account menu..." y // 2 + 2, 5, "Cancelling account creation. Returning to account menu..."
) )
sleep(3) sleep(3)
screen.clear() screen.clear()
@ -409,31 +414,31 @@ def new_add(screen, calledby=False):
screen.refresh() screen.refresh()
if calledby: if calledby:
screen.addstr( screen.addstr(
y // 2 + 2, 0, "Account has been created. Returning to login..." y // 2 + 2, 5, "Account has been created. Returning to login..."
) )
screen.refresh() screen.refresh()
sleep(3) sleep(3)
login(screen, calledby=calledby) login(screen, calledby=calledby)
else: else:
screen.addstr( screen.addstr(
y // 2 + 2, 0, "Account has been created. Returning to account menu..." y // 2 + 2, 5, "Account has been created. Returning to account menu..."
) )
screen.refresh() screen.refresh()
sleep(3) sleep(3)
screenhandler(screen) screenhandler(screen)
def Mod_account(screen): def modify_account(screen):
Userlist = list_getter("username")
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.border()
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
global loggedin, quitting global loggedin, quitting, U
screen.addstr(1, x // 2 - 8, "MODIFY ACCOUNT SETTINGS") screen.addstr(1, x // 2 - 8, "MODIFY ACCOUNT SETTINGS")
if loggedin == False: if loggedin == False:
screen.addstr( screen.addstr(
y // 2, y // 2,
0, 5,
"Please log in to you account... Redirecting you to the login menu", "Please log in to you account... Redirecting you to the login menu",
) )
screen.refresh() screen.refresh()
@ -464,11 +469,13 @@ def Mod_account(screen):
SET username = '{newuser}'\ SET username = '{newuser}'\
WHERE gamerid = '{gamerid}' " WHERE gamerid = '{gamerid}' "
) )
U = newuser
break
elif key == ord("2"): elif key == ord("2"):
screenwipe(screen, 0, 2) screenwipe(screen, 0, 2)
screen.refresh() screen.refresh()
newemail = Email( newemail = email(
screen, y // 2, x // 2 - 10, optionaltxt="Enter new email: " screen, y // 2, x // 2 - 10, optionaltxt="Enter new email: "
) )
post( post(
@ -476,6 +483,7 @@ def Mod_account(screen):
SET email = '{newemail}'\ SET email = '{newemail}'\
WHERE gamerid = '{gamerid}' " WHERE gamerid = '{gamerid}' "
) )
break
screenwipe(screen, 0, 2) screenwipe(screen, 0, 2)
screen.refresh() screen.refresh()
@ -485,6 +493,7 @@ def Mod_account(screen):
screen.refresh() screen.refresh()
sleep(3) sleep(3)
screenhandler(screen) screenhandler(screen)
return
def view_account(screen): def view_account(screen):
@ -492,11 +501,12 @@ def view_account(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.border()
screen.addstr(1, x // 2 - 6, "VIEW ACCOUNT DETAILS") screen.addstr(1, x // 2 - 6, "VIEW ACCOUNT DETAILS")
if not loggedin: if not loggedin:
screen.addstr( screen.addstr(
y // 2, y // 2,
0, 5,
"Please log in to you account... Redirecting you to the login menu", "Please log in to you account... Redirecting you to the login menu",
) )
screen.refresh() screen.refresh()
@ -518,7 +528,7 @@ def view_account(screen):
screen.addstr(y // 2 + 4, x // 2 - 5, "Last Played: " + str(score_details[0][2])) screen.addstr(y // 2 + 4, x // 2 - 5, "Last Played: " + str(score_details[0][2]))
screen.addstr(y // 2 + 6, x // 2 - 5, "Times Played: " + str(score_details[0][3])) screen.addstr(y // 2 + 6, x // 2 - 5, "Times Played: " + str(score_details[0][3]))
screen.addstr(y - 1, 0, "Press esc to return to main menu.") screen.addstr(y - 1, 5, "Press esc to return to main menu.")
while True: while True:
key = screen.getch() key = screen.getch()
if key == 27: if key == 27:
@ -528,27 +538,45 @@ def view_account(screen):
return return
def Delete(screen): def delete(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
global loggedin, gamerid, U global loggedin, gamerid, U
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.border()
if loggedin == False: if loggedin == False:
screen.addstr( screen.addstr(
y // 2, y // 2,
0, 5,
"Please log in to you account... Redirecting you to the login menu", "Please log in to you account... Redirecting you to the login menu",
) )
screen.refresh() screen.refresh()
sleep(3) sleep(3)
login(screen) login(screen)
return return
screen.addstr(y // 2 - 3, 10, "Do you really want to delete your account?")
screen.addstr(y // 2 - 2, 10, "Press y to delete or n to return to account menu.")
while True:
key = screen.getch()
if key == ord("y"):
break
elif key == ord("n"):
screen.addstr(y // 2, 5, "Returning to the account menu")
sleep(3)
screenhandler(screen)
return
post( post(
f"DELETE FROM player_details\ f"DELETE FROM player_details\
WHERE gamerid = '{gamerid}'" WHERE gamerid = '{gamerid}'"
) )
curses.ungetch(" ")
screen.addstr(y // 2, 10, "Account has been deleted. Returning to account menu...")
screen.refresh()
loggedin = False loggedin = False
gamerid = U = None gamerid = U = None
sleep(3)
screenhandler(screen)
return
def Update_score(Score): def Update_score(Score):
@ -590,7 +618,7 @@ def forgotpassword(screen):
tries = 0 tries = 0
screen.addstr(y // 2 - 2, x // 2 - 7, "Username: ") screen.addstr(y // 2 - 2, x // 2 - 7, "Username: ")
while True: while True:
input_u = Input(y // 2 - 2, x // 2 + 3, screen) input_u = input(y // 2 - 2, x // 2 + 3, screen)
if quitting: if quitting:
screen.addstr("Going back to account settings...") screen.addstr("Going back to account settings...")
sleep(3) sleep(3)
@ -603,7 +631,7 @@ def forgotpassword(screen):
if input_u not in usernamelist: if input_u not in usernamelist:
screen.addstr( screen.addstr(
y // 2 - 1, y // 2 - 1,
0, 5,
"Username does not exist. Press Enter/Space to continue...", "Username does not exist. Press Enter/Space to continue...",
) )
while True: while True:
@ -621,10 +649,10 @@ def forgotpassword(screen):
) )
email = res[0][0] email = res[0][0]
otp = sender(input_u, email) otp = sender(input_u, email)
screen.addstr(y // 2 + 1, 0, "Enter OTP recieved in registered mail address:") screen.addstr(y // 2 + 1, 5, "Enter OTP recieved in registered mail address:")
while True: while True:
screen.refresh() screen.refresh()
enter_otp = Input(y // 2 + 1, 47, screen) enter_otp = input(y // 2 + 1, 47, screen)
if quitting: if quitting:
screen.addstr("Going back to account settings...") screen.addstr("Going back to account settings...")
sleep(3) sleep(3)
@ -649,7 +677,7 @@ def forgotpassword(screen):
else: else:
screen.addstr( screen.addstr(
y // 2 + 3, y // 2 + 3,
0, 5,
"Passwords do not match. Press Enter to try again.", "Passwords do not match. Press Enter to try again.",
) )
while True: while True:
@ -661,7 +689,7 @@ def forgotpassword(screen):
if tries < 10: if tries < 10:
screen.addstr( screen.addstr(
y // 2 + 3, y // 2 + 3,
0, 5,
"Entered OTP is wrong. Press esc to exit or Enter to try again.", "Entered OTP is wrong. Press esc to exit or Enter to try again.",
) )
while True: while True:
@ -681,7 +709,7 @@ def forgotpassword(screen):
else: else:
screen.addstr( screen.addstr(
y // 2 + 3, y // 2 + 3,
0, 5,
"Entered OTP is wrong. Maximum tries exceeded. Returning to account menu...", "Entered OTP is wrong. Maximum tries exceeded. Returning to account menu...",
) )
sleep(5) sleep(5)
@ -723,7 +751,8 @@ def logout(screen):
def leaderboard(screen): def leaderboard(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() screen.clear()
screen.addstr(1, y // 2 - 5, "Leaderboard") screen.border()
screen.addstr(1, x // 2 - 5, "LEADERBOARD")
screen.refresh() screen.refresh()
res = get( res = get(
"SELECT p.gamerid,\ "SELECT p.gamerid,\
@ -751,7 +780,7 @@ def leaderboard(screen):
screen.addstr(sy, 50, str(i[2])) screen.addstr(sy, 50, str(i[2]))
screen.addstr(sy, 70, str(i[3])) screen.addstr(sy, 70, str(i[3]))
sy += 1 sy += 1
screen.addstr(y - 1, 0, "Press esc to return to main menu.") screen.addstr(y - 1, x - 35, "Press esc to return to main menu.")
while True: while True:
key = screen.getch() key = screen.getch()
if key == 27: if key == 27:

View file

@ -5,6 +5,7 @@ def about(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.border()
screen.addstr(1, x // 2 - 2, "ABOUT US") screen.addstr(1, x // 2 - 2, "ABOUT US")
screen.addstr( screen.addstr(
3, 3,
@ -12,7 +13,7 @@ def about(screen):
"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 - XII - C - Roll no: 3") screen.addstr(5, 5, "B. Adithya - XII - C - Roll no: 3")
screen.addstr(6, 5, "V. Kirthivaasan - XII - C - Roll no: ") screen.addstr(6, 5, "V. Kirthivaasan - XII - C - Roll no: 17")
screen.addstr(7, 5, "Manwanthakrishnan - XII - C - Roll no: 21") screen.addstr(7, 5, "Manwanthakrishnan - XII - C - Roll no: 21")
screen.addstr( screen.addstr(
9, 9,
@ -41,7 +42,7 @@ def about(screen):
) )
screen.addstr(19, 5, "Signing off,") screen.addstr(19, 5, "Signing off,")
screen.addstr(20, 5, "The Labyrinth") screen.addstr(20, 5, "The Labyrinth")
screen.addstr(y - 2, x - 32, "Press Enter to exit this screen.") screen.addstr(y - 2, x - 33, "Press Enter to exit this screen.")
screen.refresh() screen.refresh()
while True: while True:
key = screen.getch() key = screen.getch()

View file

@ -135,11 +135,13 @@ class Maze:
buffer[2 * self.height][0] = CONNECTED["N"] | CONNECTED["E"] buffer[2 * self.height][0] = CONNECTED["N"] | CONNECTED["E"]
buffer[2 * self.height][2 * self.width] = CONNECTED["N"] | CONNECTED["W"] buffer[2 * self.height][2 * self.width] = CONNECTED["N"] | CONNECTED["W"]
finalstr = "\n".join(["".join(WALL[cell] for cell in row) for row in buffer]) finalstr = "\n".join(["".join(WALL[cell] for cell in row) for row in buffer])
broken = list(finalstr)
broken[len(broken) - 2 - (2 * self.width + 1)] = " "
finalstr = "".join(broken)
return finalstr return finalstr
def path(maze, start, finish): def path(maze, start, finish): # Not used
heuristic = lambda node: abs(node[0] - finish[0]) + abs(node[1] - finish[1]) heuristic = lambda node: abs(node[0] - finish[0]) + abs(node[1] - finish[1])
nodes_to_explore = [start] nodes_to_explore = [start]
explored_nodes = set() explored_nodes = set()
@ -181,7 +183,7 @@ def draw_path(path, screen, delay=0.15, head=None, trail=None, skip_first=True):
old_cell = current_cell old_cell = current_cell
for idx, next_cell in enumerate(path): for idx, next_cell in enumerate(path):
first = (not idx) and skip_first first = (not idx) and skip_first
if screen.getch() == ord("q"): if screen.getch() == ord(" "):
break break
screen.refresh() screen.refresh()
for last, cell in enumerate( for last, cell in enumerate(
@ -217,10 +219,9 @@ def construction_demo(maze, screen):
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
) )
screen.nodelay(False) screen.nodelay(False)
screen.getch()
def pathfinding_demo(maze, screen, start_ts): def pathfinding_demo(maze, screen, start_ts, won_coords):
start = [] start = []
finish = [] finish = []
solution = None solution = None
@ -243,6 +244,7 @@ def pathfinding_demo(maze, screen, start_ts):
screen.addstr(current_coords[0], current_coords[1], "", curses.color_pair(2)) screen.addstr(current_coords[0], current_coords[1], "", curses.color_pair(2))
WALL = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""] WALL = ["", "", "", "", "", "", "", "", "", "", "", "", "", "", ""]
pause_elapsed = 0 pause_elapsed = 0
while True: while True:
global PAUSED global PAUSED
if PAUSED: if PAUSED:
@ -269,7 +271,7 @@ def pathfinding_demo(maze, screen, start_ts):
continue continue
elif key == ord("m"): elif key == ord("m"):
sl.save(screen, maze, current_coords) sl.save(screen, maze, current_coords)
elif current_coords[0] == maxy - 4 and current_coords[1] == maxx - 24: elif current_coords[0] == won_coords[0] and current_coords[1] == won_coords[1]:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.addstr( screen.addstr(
@ -395,24 +397,23 @@ def pathfinding_demo(maze, screen, start_ts):
def menu(screen): def menu(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() screen.clear()
text = """
"""
screen.addstr(1, 3, str(text))
screen.refresh() 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(10, x // 2 - 2, "MENU")
screen.addstr(13, 0, "space - Play") screen.addstr(13, 1, "space - Play")
screen.addstr(14, 0, "f - Load game from file") screen.addstr(14, 1, "f - Load game from file")
screen.addstr(15, 0, "a - Account Settings") screen.addstr(15, 1, "a - Account Settings")
screen.addstr(16, 0, "l - Leaderboard") screen.addstr(16, 1, "l - Leaderboard")
screen.addstr(17, 0, "x - About") screen.addstr(17, 1, "x - About")
screen.addstr(18, 0, "esc - Quit") screen.addstr(18, 1, "esc - Quit")
screen.border()
while True: while True:
key = screen.getch() key = screen.getch()
if key == ord(" "): if key == ord(" "):
@ -420,6 +421,12 @@ def menu(screen):
elif key == 27: elif key == 27:
screen.clear() screen.clear()
screen.refresh() 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() sys.exit()
elif key == ord("a"): elif key == ord("a"):
database.screenhandler(screen) database.screenhandler(screen)
@ -435,11 +442,13 @@ def menu(screen):
play(screen, maze[0]) play(screen, maze[0])
return return
else: else:
screen.addstr(20, 0, "No saved mazes present.") screen.addstr(
20, 5, "No saved mazes present. Press enter to continue..."
)
while True: while True:
key2 = screen.getch() key2 = screen.getch()
if key2 == 10: if key2 == 10:
screen.addstr(20, 0, " " * 23) screen.addstr(20, 5, " " * (x - 10))
break break
@ -447,11 +456,16 @@ def play(screen, loadedmaze=None):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
height, width = int((y - 2) / 2), int((x - 2) / 2) height, width = int((y - 2) / 2), int((x - 2) / 2)
screen.clear() screen.clear()
screen.refresh()
if not loadedmaze: if not loadedmaze:
maze = Maze(height, width) maze = Maze(height, width)
else: else:
maze = loadedmaze maze = loadedmaze
screen.addstr(0, 0, str(maze)) screen.addstr(0, 0, str(maze))
won_coords = screen.getyx()
won_coords = list(won_coords)
won_coords[0] = won_coords[0] - 1
won_coords = tuple(won_coords)
screen.refresh() screen.refresh()
sx = x - 22 # x - 23 sx = x - 22 # x - 23
screen.addstr(0, sx, "LABYRINTH") screen.addstr(0, sx, "LABYRINTH")
@ -466,17 +480,14 @@ def play(screen, loadedmaze=None):
screen.addstr(15, sx, "m - save") screen.addstr(15, sx, "m - save")
screen.refresh() screen.refresh()
start_ts = time.time() start_ts = time.time()
pathfinding_demo(maze, screen, start_ts) pathfinding_demo(maze, screen, start_ts, won_coords)
end_ts = time.time() end_ts = time.time()
came_out = 1 came_out = 1
while True: while True:
key = screen.getch()
if key == ord("q"):
break
if came_out != 0: if came_out != 0:
screen.clear() screen.clear()
screen.refresh() screen.refresh()
screen.erase()
global WON global WON
if WON != 0: if WON != 0:
tt = (start_ts - end_ts) / 300 tt = (start_ts - end_ts) / 300
@ -486,7 +497,7 @@ def play(screen, loadedmaze=None):
else: else:
score = 0 score = 0
screen.addstr( screen.addstr(
height - 3, width - 4, str("Your score is: " + str(int(score))) y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score)))
) )
res = database.Update_score(int(score)) res = database.Update_score(int(score))
if res == "guest": if res == "guest":
@ -505,11 +516,11 @@ def play(screen, loadedmaze=None):
break break
elif key == ord("n"): elif key == ord("n"):
break break
screen.refresh()
time.sleep(3)
screen.clear() screen.clear()
menu(screen) screen.refresh()
came_out = 0 came_out = 0
menu(screen)
return
def main(screen): def main(screen):
@ -520,6 +531,7 @@ def main(screen):
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_RED, curses.COLOR_BLACK)
screen.clear() screen.clear()
screen.refresh()
height, width = screen.getmaxyx() height, width = screen.getmaxyx()
height, width = int((height - 2) / 2), int((width - 2) / 2) height, width = int((height - 2) / 2), int((width - 2) / 2)
database.databaseinit() database.databaseinit()

View file

@ -4,7 +4,7 @@ from time import sleep
import maze.modules.maze as m import maze.modules.maze as m
from .PlayerBase_func import Input, screenwipe from .PlayerBase_func import input, screenwipe
def save(screen, maze, coords): def save(screen, maze, coords):
@ -13,7 +13,7 @@ def save(screen, maze, coords):
os.mkdir("saves") os.mkdir("saves")
names = os.listdir("saves") names = os.listdir("saves")
screen.addstr(17, x - 17, "Enter filename: ") screen.addstr(17, x - 17, "Enter filename: ")
name = Input(18, x - 17, screen) name = input(18, x - 17, screen)
if names: if names:
num = int(((names[-1].replace(".maze", "")).split("_"))[1]) + 1 num = int(((names[-1].replace(".maze", "")).split("_"))[1]) + 1
if not name: if not name:
@ -55,7 +55,7 @@ def load(screen):
sy += 1 sy += 1
while True: while True:
screen.addstr(y // 2 + 5, 0, "Enter preferred maze number: ") screen.addstr(y // 2 + 5, 0, "Enter preferred maze number: ")
num = Input(y // 2 + 5, 30, screen) num = input(y // 2 + 5, 30, 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: