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
|
||||
try:
|
||||
tempsql = mysql.connector.connect(host="localhost", user="root", passwd="root")
|
||||
tempsql = mysql.connector.connect(host="localhost", user="root", passwd="")
|
||||
tempcon = tempsql.cursor()
|
||||
tempcon.execute("CREATE DATABASE IF NOT EXISTS labyrinth")
|
||||
tempsql.commit()
|
||||
|
||||
global sql, con
|
||||
sql = mysql.connector.connect(
|
||||
host="localhost", user="root", passwd="root", database="labyrinth"
|
||||
host="localhost", user="root", passwd="", database="labyrinth"
|
||||
)
|
||||
con = sql.cursor()
|
||||
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 - 0, w // 2 - 12, "4. View account details")
|
||||
screen.addstr(h // 2 + 1, w // 2 - 8, "5. Delete Account")
|
||||
if not loggedin:
|
||||
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()
|
||||
while True:
|
||||
key = screen.getch()
|
||||
|
@ -110,7 +114,10 @@ def screenhandler(screen): # MAIN MENU
|
|||
elif key == ord("5"):
|
||||
Delete(screen)
|
||||
elif key == ord("6"):
|
||||
if not loggedin:
|
||||
forgotpassword(screen)
|
||||
elif loggedin:
|
||||
logout(screen)
|
||||
elif key == 27:
|
||||
maze.modules.maze.menu(screen)
|
||||
break
|
||||
|
@ -182,7 +189,7 @@ def login(screen, calledby=False): # Function to log in
|
|||
quitting = False
|
||||
screen.clear()
|
||||
screen.refresh()
|
||||
screenhandler(screen)
|
||||
return
|
||||
if inputU not in usernamelist:
|
||||
screen.addstr(
|
||||
y // 2, 0, "Username does not exist. Do you want to create one? (y/n)"
|
||||
|
@ -693,6 +700,23 @@ def forgotpassword(screen):
|
|||
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):
|
||||
y, x = screen.getmaxyx()
|
||||
screen.clear()
|
||||
|
|
|
@ -1,21 +1,44 @@
|
|||
import maze.modules.maze
|
||||
|
||||
|
||||
def about(screen):
|
||||
y, x = screen.getmaxyx()
|
||||
screen.clear()
|
||||
screen.refresh()
|
||||
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(6, 5, "V. Kirthivaasan - XII - C - Roll no: ")
|
||||
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(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(
|
||||
9,
|
||||
5,
|
||||
"This game aims at generating a maze which always has a path towards the right bottom corner",
|
||||
)
|
||||
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(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(20, 5, "The Labyrinth")
|
||||
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
|
||||
from .about import about
|
||||
import maze.modules.maze_saveandload as sl
|
||||
import sys
|
||||
|
||||
WON = 0
|
||||
PAUSED = False
|
||||
CONNECTED = {"N": 1, "S": 2, "E": 4, "W": 8}
|
||||
DIRECTIONS = {"N": (-1, 0), "S": (1, 0), "E": (0, 1), "W": (0, -1)}
|
||||
ANTIPODES = {"N": "S", "S": "N", "W": "E", "E": "W"}
|
||||
|
||||
WALL = {
|
||||
12: "═",
|
||||
3: "║",
|
||||
|
@ -31,15 +33,16 @@ WALL = {
|
|||
1: "║",
|
||||
2: "║",
|
||||
}
|
||||
|
||||
VISITED = 16
|
||||
|
||||
|
||||
class Maze:
|
||||
def __init__(self, height, width, start=(0, 0)):
|
||||
self.height = height
|
||||
self.width = width - 12
|
||||
self.width = width - 11
|
||||
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)
|
||||
|
||||
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]))
|
||||
draw_path(solution, screen) """
|
||||
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))
|
||||
WALL = ["═", "║", "╗", "╚", "╝", "╔", "╠", "╣", "╦", "╩", "╬", "═", "═", "║", "║"]
|
||||
pause_elapsed = 0
|
||||
|
@ -263,7 +267,7 @@ def pathfinding_demo(maze, screen, start_ts):
|
|||
continue
|
||||
elif key == ord("m"):
|
||||
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.refresh()
|
||||
screen.addstr(
|
||||
|
@ -414,7 +418,7 @@ def menu(screen):
|
|||
elif key == 27:
|
||||
screen.clear()
|
||||
screen.refresh()
|
||||
break
|
||||
sys.exit()
|
||||
elif key == ord("a"):
|
||||
database.screenhandler(screen)
|
||||
elif key == ord("l"):
|
||||
|
@ -436,6 +440,7 @@ def menu(screen):
|
|||
screen.addstr(20, 0, " " * 23)
|
||||
break
|
||||
|
||||
|
||||
def play(screen, loadedmaze=None):
|
||||
y, x = screen.getmaxyx()
|
||||
height, width = int((y - 2) / 2), int((x - 2) / 2)
|
||||
|
@ -446,16 +451,17 @@ def play(screen, loadedmaze = None):
|
|||
maze = loadedmaze
|
||||
screen.addstr(0, 0, str(maze))
|
||||
screen.refresh()
|
||||
screen.addstr(0, x - 23, "LABYRINTH")
|
||||
screen.addstr(5, x - 23, "Time:")
|
||||
screen.addstr(8, x - 23, "esc - Quit")
|
||||
screen.addstr(9, x - 23, "Up - Move up")
|
||||
screen.addstr(10, x - 23, "Down - Move down")
|
||||
screen.addstr(11, x - 23, "Left - Move left")
|
||||
screen.addstr(12, x - 23, "Right - Move right")
|
||||
screen.addstr(13, x - 23, "p - Pause")
|
||||
screen.addstr(14, x - 23, "r - Resume")
|
||||
screen.addstr(15, x - 23, "m - save")
|
||||
sx = x - 22 # x - 23
|
||||
screen.addstr(0, sx, "LABYRINTH")
|
||||
screen.addstr(5, sx, "Time:")
|
||||
screen.addstr(8, sx, "esc - Quit")
|
||||
screen.addstr(9, sx, "Up - Move up")
|
||||
screen.addstr(10, sx, "Down - Move down")
|
||||
screen.addstr(11, sx, "Left - Move left")
|
||||
screen.addstr(12, sx, "Right - Move right")
|
||||
screen.addstr(13, sx, "p - Pause")
|
||||
screen.addstr(14, sx, "r - Resume")
|
||||
screen.addstr(15, sx, "m - save")
|
||||
screen.refresh()
|
||||
start_ts = time.time()
|
||||
pathfinding_demo(maze, screen, start_ts)
|
||||
|
|
|
@ -4,6 +4,7 @@ from .PlayerBase_func import Input, screenwipe
|
|||
import maze.modules.maze as m
|
||||
from time import sleep
|
||||
|
||||
|
||||
def save(screen, maze, coords):
|
||||
y, x = screen.getmaxyx()
|
||||
if "saves" not in os.listdir():
|
||||
|
@ -12,7 +13,7 @@ def save(screen, maze, coords):
|
|||
screen.addstr(17, x - 17, "Enter filename: ")
|
||||
name = Input(18, x - 17, screen)
|
||||
if names:
|
||||
num = int(((names[-1].replace('.maze', '')).split('_'))[1]) + 1
|
||||
num = int(((names[-1].replace(".maze", "")).split("_"))[1]) + 1
|
||||
if not name:
|
||||
name = "default"
|
||||
filename = f"maze_{str(num)}_{name}.maze"
|
||||
|
@ -30,10 +31,12 @@ def save(screen, maze, coords):
|
|||
screen.addstr(19, x - 17, " " * 12)
|
||||
screen.refresh()
|
||||
|
||||
|
||||
def check():
|
||||
if len(os.listdir("saves")):
|
||||
return True
|
||||
|
||||
|
||||
def load(screen):
|
||||
y, x = screen.getmaxyx()
|
||||
screen.clear()
|
||||
|
@ -42,7 +45,11 @@ def load(screen):
|
|||
mazes = os.listdir("saves")
|
||||
sy = 4
|
||||
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
|
||||
while True:
|
||||
screen.addstr(y // 2 + 5, 0, "Enter preferred maze number: ")
|
||||
|
|
Loading…
Reference in a new issue