Introduced logout, fixed a problem in gen logic + blacked
This commit is contained in:
parent
1022ba6f23
commit
e29d3dda65
5 changed files with 95 additions and 35 deletions
|
@ -36,14 +36,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="root")
|
tempsql = mysql.connector.connect(host="localhost", user="root", passwd="")
|
||||||
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="root", database="labyrinth"
|
host="localhost", user="root", passwd="", database="labyrinth"
|
||||||
)
|
)
|
||||||
con = sql.cursor()
|
con = sql.cursor()
|
||||||
return True
|
return True
|
||||||
|
@ -94,8 +94,12 @@ def screenhandler(screen): # MAIN MENU
|
||||||
screen.addstr(h // 2 - 1, w // 2 - 12, "3. Modify account details")
|
screen.addstr(h // 2 - 1, w // 2 - 12, "3. Modify account details")
|
||||||
screen.addstr(h // 2 - 0, w // 2 - 12, "4. View account details")
|
screen.addstr(h // 2 - 0, w // 2 - 12, "4. View account details")
|
||||||
screen.addstr(h // 2 + 1, w // 2 - 8, "5. Delete Account")
|
screen.addstr(h // 2 + 1, w // 2 - 8, "5. Delete Account")
|
||||||
screen.addstr(h // 2 + 2, w // 2 - 9, "6. Forgot Password?")
|
if not loggedin:
|
||||||
screen.addstr(h // 2 + 3, w // 2 - 3, "esc. Quit")
|
screen.addstr(h // 2 + 2, w // 2 - 9, "6. Forgot Password?")
|
||||||
|
screen.addstr(h // 2 + 3, w // 2 - 3, "esc. Quit")
|
||||||
|
else:
|
||||||
|
screen.addstr(h // 2 + 2, w // 2 - 3, "6. Logout")
|
||||||
|
screen.addstr(h // 2 + 3, w // 2 - 3, "esc. Quit")
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
while True:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
|
@ -110,7 +114,10 @@ def screenhandler(screen): # MAIN MENU
|
||||||
elif key == ord("5"):
|
elif key == ord("5"):
|
||||||
Delete(screen)
|
Delete(screen)
|
||||||
elif key == ord("6"):
|
elif key == ord("6"):
|
||||||
forgotpassword(screen)
|
if not loggedin:
|
||||||
|
forgotpassword(screen)
|
||||||
|
elif loggedin:
|
||||||
|
logout(screen)
|
||||||
elif key == 27:
|
elif key == 27:
|
||||||
maze.modules.maze.menu(screen)
|
maze.modules.maze.menu(screen)
|
||||||
break
|
break
|
||||||
|
@ -182,7 +189,7 @@ def login(screen, calledby=False): # Function to log in
|
||||||
quitting = False
|
quitting = False
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screenhandler(screen)
|
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, 0, "Username does not exist. Do you want to create one? (y/n)"
|
||||||
|
@ -693,6 +700,23 @@ def forgotpassword(screen):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def logout(screen):
|
||||||
|
y, x = screen.getmaxyx()
|
||||||
|
screen.clear()
|
||||||
|
screen.refresh()
|
||||||
|
screen.addstr(1, x // 2 - 2, "LOGOUT")
|
||||||
|
screen.addstr(y // 2, 5, "Logging out of your account...")
|
||||||
|
global loggedin, U, gamerid
|
||||||
|
loggedin = False
|
||||||
|
U = gamerid = None
|
||||||
|
screen.refresh()
|
||||||
|
sleep(5)
|
||||||
|
screen.clear()
|
||||||
|
screen.refresh()
|
||||||
|
screenhandler(screen)
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
def leaderboard(screen):
|
def leaderboard(screen):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
|
|
@ -1,21 +1,44 @@
|
||||||
import maze.modules.maze
|
import maze.modules.maze
|
||||||
|
|
||||||
|
|
||||||
def about(screen):
|
def about(screen):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.addstr(1, x//2 - 2, "ABOUT US")
|
screen.addstr(1, x // 2 - 2, "ABOUT US")
|
||||||
screen.addstr(3, 5, "This game which you have played was developed as a Computer Science Project by")
|
screen.addstr(
|
||||||
|
3,
|
||||||
|
5,
|
||||||
|
"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: ")
|
||||||
screen.addstr(7, 5, "Manwanthakrishnan - XII - C - Roll no: 21")
|
screen.addstr(7, 5, "Manwanthakrishnan - XII - C - Roll no: 21")
|
||||||
screen.addstr(9, 5, "This game aims at generating a maze which always has a path towards the right bottom corner")
|
screen.addstr(
|
||||||
screen.addstr(10, 5, "by using a famous generation algorithm named Depth First Search (DFS).")
|
9,
|
||||||
screen.addstr(11, 5, "This game makes use of the 'curses' module which runs on any operating system")
|
5,
|
||||||
screen.addstr(12, 5, "in the native terminal without use of any other external modules.")
|
"This game aims at generating a maze which always has a path towards the right bottom corner",
|
||||||
screen.addstr(13, 5, "It makes use of SQL tables to store login details and maintain a leaderboard.")
|
)
|
||||||
|
screen.addstr(
|
||||||
|
10, 5, "by using a famous generation algorithm named Depth First Search (DFS)."
|
||||||
|
)
|
||||||
|
screen.addstr(
|
||||||
|
11,
|
||||||
|
5,
|
||||||
|
"This game makes use of the 'curses' module which runs on any operating system",
|
||||||
|
)
|
||||||
|
screen.addstr(
|
||||||
|
12, 5, "in the native terminal without use of any other external modules."
|
||||||
|
)
|
||||||
|
screen.addstr(
|
||||||
|
13,
|
||||||
|
5,
|
||||||
|
"It makes use of SQL tables to store login details and maintain a leaderboard.",
|
||||||
|
)
|
||||||
screen.addstr(15, 5, "This project has been an absolute blast to make.")
|
screen.addstr(15, 5, "This project has been an absolute blast to make.")
|
||||||
screen.addstr(16, 5, "We thank you for playing this! Hope you liked it as much as we did!")
|
screen.addstr(
|
||||||
|
16, 5, "We thank you for playing this! Hope you liked it as much as we did!"
|
||||||
|
)
|
||||||
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 - 32, "Press Enter to exit this screen.")
|
||||||
|
|
|
@ -7,12 +7,14 @@ from itertools import tee
|
||||||
import maze.modules.PlayerBase_func as database
|
import maze.modules.PlayerBase_func as database
|
||||||
from .about import about
|
from .about import about
|
||||||
import maze.modules.maze_saveandload as sl
|
import maze.modules.maze_saveandload as sl
|
||||||
|
import sys
|
||||||
|
|
||||||
WON = 0
|
WON = 0
|
||||||
PAUSED = False
|
PAUSED = False
|
||||||
CONNECTED = {"N": 1, "S": 2, "E": 4, "W": 8}
|
CONNECTED = {"N": 1, "S": 2, "E": 4, "W": 8}
|
||||||
DIRECTIONS = {"N": (-1, 0), "S": (1, 0), "E": (0, 1), "W": (0, -1)}
|
DIRECTIONS = {"N": (-1, 0), "S": (1, 0), "E": (0, 1), "W": (0, -1)}
|
||||||
ANTIPODES = {"N": "S", "S": "N", "W": "E", "E": "W"}
|
ANTIPODES = {"N": "S", "S": "N", "W": "E", "E": "W"}
|
||||||
|
|
||||||
WALL = {
|
WALL = {
|
||||||
12: "═",
|
12: "═",
|
||||||
3: "║",
|
3: "║",
|
||||||
|
@ -31,15 +33,16 @@ WALL = {
|
||||||
1: "║",
|
1: "║",
|
||||||
2: "║",
|
2: "║",
|
||||||
}
|
}
|
||||||
|
|
||||||
VISITED = 16
|
VISITED = 16
|
||||||
|
|
||||||
|
|
||||||
class Maze:
|
class Maze:
|
||||||
def __init__(self, height, width, start=(0, 0)):
|
def __init__(self, height, width, start=(0, 0)):
|
||||||
self.height = height
|
self.height = height
|
||||||
self.width = width - 12
|
self.width = width - 11
|
||||||
self.stack = []
|
self.stack = []
|
||||||
self.cells = {(y, x): 0 for y in range(height) for x in range(width)}
|
self.cells = {(y, x): 0 for y in range(self.height) for x in range(self.width)}
|
||||||
self.build(start)
|
self.build(start)
|
||||||
|
|
||||||
def eligible_neighbours(self, y, x):
|
def eligible_neighbours(self, y, x):
|
||||||
|
@ -233,7 +236,8 @@ def pathfinding_demo(maze, screen, start_ts):
|
||||||
solution, old_solution = tee(path(maze, start[0], finish[0]))
|
solution, old_solution = tee(path(maze, start[0], finish[0]))
|
||||||
draw_path(solution, screen) """
|
draw_path(solution, screen) """
|
||||||
maxy, maxx = screen.getmaxyx()
|
maxy, maxx = screen.getmaxyx()
|
||||||
current_coords = [maxy - 5, maxx - 35]
|
current_coords = [maxy - 5, maxx - 27]
|
||||||
|
# current_coords = [1, 1]
|
||||||
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
|
||||||
|
@ -251,7 +255,7 @@ def pathfinding_demo(maze, screen, start_ts):
|
||||||
PAUSED = False
|
PAUSED = False
|
||||||
break
|
break
|
||||||
pause_elapsed = int(end_paused_ts - start_paused_ts)
|
pause_elapsed = int(end_paused_ts - start_paused_ts)
|
||||||
actual_elapsed = str(int(time.time()-start_ts) - pause_elapsed)
|
actual_elapsed = str(int(time.time() - start_ts) - pause_elapsed)
|
||||||
screen.addstr(5, maxx - 17, actual_elapsed + " sec")
|
screen.addstr(5, maxx - 17, actual_elapsed + " sec")
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
|
@ -263,7 +267,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 - 3 and current_coords[1] == maxx - 27:
|
elif current_coords[0] == maxy - 4 and current_coords[1] == maxx - 24:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
|
@ -414,7 +418,7 @@ def menu(screen):
|
||||||
elif key == 27:
|
elif key == 27:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
break
|
sys.exit()
|
||||||
elif key == ord("a"):
|
elif key == ord("a"):
|
||||||
database.screenhandler(screen)
|
database.screenhandler(screen)
|
||||||
elif key == ord("l"):
|
elif key == ord("l"):
|
||||||
|
@ -436,7 +440,8 @@ def menu(screen):
|
||||||
screen.addstr(20, 0, " " * 23)
|
screen.addstr(20, 0, " " * 23)
|
||||||
break
|
break
|
||||||
|
|
||||||
def play(screen, loadedmaze = None):
|
|
||||||
|
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()
|
||||||
|
@ -446,16 +451,17 @@ def play(screen, loadedmaze = None):
|
||||||
maze = loadedmaze
|
maze = loadedmaze
|
||||||
screen.addstr(0, 0, str(maze))
|
screen.addstr(0, 0, str(maze))
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.addstr(0, x - 23, "LABYRINTH")
|
sx = x - 22 # x - 23
|
||||||
screen.addstr(5, x - 23, "Time:")
|
screen.addstr(0, sx, "LABYRINTH")
|
||||||
screen.addstr(8, x - 23, "esc - Quit")
|
screen.addstr(5, sx, "Time:")
|
||||||
screen.addstr(9, x - 23, "Up - Move up")
|
screen.addstr(8, sx, "esc - Quit")
|
||||||
screen.addstr(10, x - 23, "Down - Move down")
|
screen.addstr(9, sx, "Up - Move up")
|
||||||
screen.addstr(11, x - 23, "Left - Move left")
|
screen.addstr(10, sx, "Down - Move down")
|
||||||
screen.addstr(12, x - 23, "Right - Move right")
|
screen.addstr(11, sx, "Left - Move left")
|
||||||
screen.addstr(13, x - 23, "p - Pause")
|
screen.addstr(12, sx, "Right - Move right")
|
||||||
screen.addstr(14, x - 23, "r - Resume")
|
screen.addstr(13, sx, "p - Pause")
|
||||||
screen.addstr(15, x - 23, "m - save")
|
screen.addstr(14, sx, "r - Resume")
|
||||||
|
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)
|
||||||
|
|
|
@ -4,6 +4,7 @@ from .PlayerBase_func import Input, screenwipe
|
||||||
import maze.modules.maze as m
|
import maze.modules.maze as m
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
def save(screen, maze, coords):
|
def save(screen, maze, coords):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
if "saves" not in os.listdir():
|
if "saves" not in os.listdir():
|
||||||
|
@ -12,7 +13,7 @@ def save(screen, maze, coords):
|
||||||
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:
|
||||||
name = "default"
|
name = "default"
|
||||||
filename = f"maze_{str(num)}_{name}.maze"
|
filename = f"maze_{str(num)}_{name}.maze"
|
||||||
|
@ -30,10 +31,12 @@ def save(screen, maze, coords):
|
||||||
screen.addstr(19, x - 17, " " * 12)
|
screen.addstr(19, x - 17, " " * 12)
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
||||||
|
|
||||||
def check():
|
def check():
|
||||||
if len(os.listdir("saves")):
|
if len(os.listdir("saves")):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def load(screen):
|
def load(screen):
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
@ -42,7 +45,11 @@ def load(screen):
|
||||||
mazes = os.listdir("saves")
|
mazes = os.listdir("saves")
|
||||||
sy = 4
|
sy = 4
|
||||||
for i in range(len(mazes)):
|
for i in range(len(mazes)):
|
||||||
screen.addstr(sy, 10, 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]}",
|
||||||
|
)
|
||||||
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: ")
|
||||||
|
@ -66,7 +73,7 @@ def load(screen):
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
break
|
break
|
||||||
continue
|
continue
|
||||||
f = open("saves//"+mazes[num], "rb")
|
f = open("saves//" + mazes[num], "rb")
|
||||||
maze = pickle.load(f)
|
maze = pickle.load(f)
|
||||||
coords = pickle.load(f)
|
coords = pickle.load(f)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
from maze.modules import bruh
|
from maze.modules import bruh
|
||||||
|
|
||||||
bruh()
|
bruh()
|
||||||
|
|
Loading…
Reference in a new issue