Added function comments

This commit is contained in:
adithyagenie 2022-11-30 21:27:28 +05:30
parent 8f8e951153
commit 937e6dbac4
10 changed files with 56 additions and 6 deletions

View file

@ -12,6 +12,7 @@ from maze.modules.about import about
def menu(screen):
"""The Main menu of the entire game"""
exit = False
y, x = screen.getmaxyx()
screen.clear()
@ -70,7 +71,7 @@ def menu(screen):
while True:
breakkey = screen.getch()
if breakkey:
time.sleep(1)
time.sleep(5)
sys.exit()
elif key == ord("a"):
database.screenhandler(screen)

View file

@ -48,7 +48,8 @@ def post(
print("ERROR OCCURED COMMITTING CHANGES")
def databaseinit(): # Creates database if it doesn't exist
def databaseinit():
"""Creates database if it doesn't exist"""
try:
tempsql = mysql.connector.connect(
host="localhost", user=MYSQL_USERNAME, passwd=MYSQL_PASSWORD
@ -75,6 +76,7 @@ def databaseinit(): # Creates database if it doesn't exist
def tableinit():
"""Creates table if it doesn't exist"""
try:
post(
"CREATE TABLE IF NOT EXISTS player_details\
@ -101,7 +103,8 @@ def tableinit():
print("ERROR: Creating Table(s)")
def screenhandler(screen): # MAIN MENU
def screenhandler(screen):
"""MAIN MENU"""
h, w = screen.getmaxyx()
global loggedin, U, gamerid
screen.clear()
@ -200,7 +203,8 @@ def list_getter(field): # Feed in the field name you want, get all records of i
return return_list
def login(screen, calledby=None): # Function to log in
def login(screen, calledby=None):
"""Function to log in. calledby argument handles updation of score after playing a game."""
global quitting, U, gamerid, loggedin
screen.clear()
screen.refresh()
@ -324,7 +328,9 @@ def user(
return Name
def password(screen, sy, sx, optionaltxt="Enter Password: "):
def password(
screen, sy, sx, optionaltxt="Enter Password: "
): # Function to get new password and encrypt for account creation
if quitting:
screen.clear()
screen.refresh()
@ -363,7 +369,9 @@ def password(screen, sy, sx, optionaltxt="Enter Password: "):
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 valid email id
if quitting:
screen.clear()
screen.refresh()
@ -406,6 +414,7 @@ def email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept em
def new_add(screen, calledby=None):
"""Creation of a new account with random GamerID"""
screen.clear()
screen.refresh()
screen.border()
@ -463,6 +472,7 @@ def new_add(screen, calledby=None):
def modify_account(screen):
"""Modifies account details"""
screen.clear()
screen.refresh()
screen.border()
@ -533,6 +543,7 @@ def modify_account(screen):
def view_account(screen):
"""Views account details and scores"""
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
global loggedin, U, gamerid
@ -599,6 +610,7 @@ def view_account(screen):
def delete(screen):
"""Deletes account"""
y, x = screen.getmaxyx()
global loggedin, gamerid, U
screen.clear()
@ -641,6 +653,7 @@ def delete(screen):
def Update_score(score, game):
"""Updates score of game given in args"""
tablename = game + "_scores"
global U, gamerid, loggedin
if not loggedin:
@ -669,6 +682,7 @@ def Update_score(score, game):
def Update_lp_tp(tablename):
"""Updates last played and times played"""
global U, gamerid, loggedin
if not loggedin:
return "guest"
@ -681,6 +695,7 @@ def Update_lp_tp(tablename):
def forgotpassword(screen):
"""Forgot password screen + new password"""
screen.clear()
screen.refresh()
y, x = screen.getmaxyx()
@ -807,6 +822,7 @@ def forgotpassword(screen):
def logout(screen):
"""Logout"""
y, x = screen.getmaxyx()
screen.clear()
screen.refresh()
@ -825,6 +841,7 @@ def logout(screen):
def leaderboard(screen):
"""Leaderboard"""
y, x = screen.getmaxyx()
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)

View file

@ -5,6 +5,7 @@ from maze.modules.maze import main
def bruh():
"""Initialising the screen"""
try:
curses.wrapper(main)
curses.nocbreak()

View file

@ -4,6 +4,7 @@ import maze.menu
def about(screen):
"""Displays the about screen"""
y, x = screen.getmaxyx()
screen.clear()
screen.refresh()

View file

@ -40,6 +40,8 @@ VISITED = 16
class Maze:
"""This class handles the entirety of maze generation and returns the maze as a string"""
def __init__(self, height, width, start=(0, 0)):
self.height = height
self.width = width - 11
@ -142,6 +144,7 @@ class Maze:
def path(maze, start, finish):
"""This is a pathfinding logic used in loading of a stored maze"""
heuristic = lambda node: abs(node[0] - finish[0]) + abs(node[1] - finish[1])
nodes_to_explore = [start]
explored_nodes = set()
@ -177,6 +180,7 @@ def path(maze, start, finish):
def draw_path(
path, screen, delay=0, head=None, trail=None, skip_first=True, calledby=None
):
"""This is a pathfinding logic used in loading of a stored maze"""
if not head:
head = ("", curses.color_pair(2))
if not trail:
@ -215,6 +219,7 @@ def coords(node):
def construction_demo(maze, screen):
"""Loading screen"""
head = (".", curses.color_pair(5) | curses.A_BOLD)
trail = (".", curses.color_pair(2) | curses.A_BOLD)
draw_path(
@ -226,6 +231,8 @@ def construction_demo(maze, screen):
def pathfinding_demo(
maze, screen, start_ts, won_coords, loadedcoords=None, loadedtime=0
):
"""Movement controls and win detection. Handles pausing, time for score
loadedcoords and loadedtime are optional args which handles loading saved maze"""
start = []
finish = []
solution = None
@ -412,10 +419,14 @@ def play(
outerscore=0,
outergame=False,
):
"""Displays side menu, handles win, lose of maze
loadedmaze, loadedcoords and loadedtime are used for loading saved maze
executeguest, outerscore and outergame are for calling the bounded func guestswitch()"""
y, x = screen.getmaxyx()
height, width = int((y - 2) / 2), int((x - 2) / 2)
def guestswitch(score, game):
"""For checking if guest, else updating score"""
screen.clear()
screen.refresh()
screen.border()
@ -498,6 +509,7 @@ def play(
def main(screen):
"""Main function initialising screen settings, display loading screen and creates a maze"""
screen.nodelay(True)
curses.curs_set(False)
curses.mousemask(curses.ALL_MOUSE_EVENTS)

View file

@ -9,6 +9,7 @@ from .PlayerBase_func import input, screenwipe
def save(screen, maze, coords, elapsed):
"""Saves the maze to a binary file"""
y, x = screen.getmaxyx()
if "saves" not in os.listdir():
os.mkdir("saves")
@ -48,6 +49,7 @@ def check():
def load(screen):
"""Loads a maze and returns maze, coords and time"""
y, x = screen.getmaxyx()
screen.clear()
screen.refresh()

View file

@ -6,6 +6,7 @@ from random import choice
def sender(userid, receiver_address):
"""Sends forgot password email"""
try:
with open("credentials.pickle", "rb") as f:
d = pickle.load(f)

View file

@ -10,6 +10,8 @@ quit = threading.Event()
class Scores:
"""Class object to take care of score"""
def __init__(self, screen):
self.score = 0
self.screen = screen
@ -30,6 +32,8 @@ class Scores:
class Ball:
"""Class object to store ball coordinates, predict ball movement, detect collision"""
def __init__(self, y, x, screen):
self.ball_dx = 1
self.ball_dy = 1
@ -106,6 +110,8 @@ class Ball:
class Player:
"""Class object of the paddle"""
def __init__(self, y, x):
self.y = y
self.x = x
@ -122,6 +128,7 @@ class Player:
def player_movement(screen, player):
"""Function to control player movement"""
global quit
screen.keypad(True)
while 1:
@ -142,6 +149,7 @@ def player_movement(screen, player):
def ball_movement(screen, ball, score):
"""Function to control ball movement and detect end of game"""
y, x = screen.getmaxyx()
while 1:
# f.write("ball running\n")
@ -179,6 +187,7 @@ def ball_movement(screen, ball, score):
def main(screen):
"""Initialises color pairs, spins up two seperate threads for ball and player"""
global quit
quit.clear()
screen.clear()

View file

@ -8,6 +8,7 @@ from maze.modules import bruh
user = password = None
"""Gets mysql pass and username"""
with open("credentials.pickle", "rb") as f:
try:
while True:
@ -21,6 +22,7 @@ with open("credentials.pickle", "rb") as f:
def getcreds():
"""Checks mysql creds"""
if user:
return user, password
else:
@ -44,6 +46,7 @@ Run 'python starter.py initsql' to initialise credentials of your choice. """
if len(sys.argv) == 1:
"""Called with no arguments"""
getcreds()
try:
bruh()
@ -53,6 +56,7 @@ if len(sys.argv) == 1:
sys.exit()
else:
if sys.argv[1] == "dumpsample":
"""dumps sample database"""
getcreds()
player.databaseinit()
subprocess.call(
@ -64,6 +68,7 @@ else:
print("Successfully dumped sample data")
elif sys.argv[1] == "initsql":
"""Stores mysql creds"""
user = input("Enter MySQL username: ")
password = input("Enter MySQL password: ")
with open("credentials.pickle", "rb+") as f:

View file

@ -16,6 +16,7 @@ language = "en-us"
def defnsyn(w):
"""Returns definition and synonym of said word"""
url = (
r"https://od-api.oxforddictionaries.com:443/api/v2/entries/"
+ language