Added function comments
This commit is contained in:
parent
8f8e951153
commit
937e6dbac4
10 changed files with 56 additions and 6 deletions
|
@ -12,6 +12,7 @@ from maze.modules.about import about
|
||||||
|
|
||||||
|
|
||||||
def menu(screen):
|
def menu(screen):
|
||||||
|
"""The Main menu of the entire game"""
|
||||||
exit = False
|
exit = False
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
@ -70,7 +71,7 @@ def menu(screen):
|
||||||
while True:
|
while True:
|
||||||
breakkey = screen.getch()
|
breakkey = screen.getch()
|
||||||
if breakkey:
|
if breakkey:
|
||||||
time.sleep(1)
|
time.sleep(5)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
elif key == ord("a"):
|
elif key == ord("a"):
|
||||||
database.screenhandler(screen)
|
database.screenhandler(screen)
|
||||||
|
|
|
@ -48,7 +48,8 @@ def post(
|
||||||
print("ERROR OCCURED COMMITTING CHANGES")
|
print("ERROR OCCURED COMMITTING CHANGES")
|
||||||
|
|
||||||
|
|
||||||
def databaseinit(): # Creates database if it doesn't exist
|
def databaseinit():
|
||||||
|
"""Creates database if it doesn't exist"""
|
||||||
try:
|
try:
|
||||||
tempsql = mysql.connector.connect(
|
tempsql = mysql.connector.connect(
|
||||||
host="localhost", user=MYSQL_USERNAME, passwd=MYSQL_PASSWORD
|
host="localhost", user=MYSQL_USERNAME, passwd=MYSQL_PASSWORD
|
||||||
|
@ -75,6 +76,7 @@ def databaseinit(): # Creates database if it doesn't exist
|
||||||
|
|
||||||
|
|
||||||
def tableinit():
|
def tableinit():
|
||||||
|
"""Creates table if it doesn't exist"""
|
||||||
try:
|
try:
|
||||||
post(
|
post(
|
||||||
"CREATE TABLE IF NOT EXISTS player_details\
|
"CREATE TABLE IF NOT EXISTS player_details\
|
||||||
|
@ -101,7 +103,8 @@ def tableinit():
|
||||||
print("ERROR: Creating Table(s)")
|
print("ERROR: Creating Table(s)")
|
||||||
|
|
||||||
|
|
||||||
def screenhandler(screen): # MAIN MENU
|
def screenhandler(screen):
|
||||||
|
"""MAIN MENU"""
|
||||||
h, w = screen.getmaxyx()
|
h, w = screen.getmaxyx()
|
||||||
global loggedin, U, gamerid
|
global loggedin, U, gamerid
|
||||||
screen.clear()
|
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
|
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
|
global quitting, U, gamerid, loggedin
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
@ -324,7 +328,9 @@ def user(
|
||||||
return Name
|
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:
|
if quitting:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
@ -363,7 +369,9 @@ 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 valid email id
|
||||||
if quitting:
|
if quitting:
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
@ -406,6 +414,7 @@ def email(screen, sy, sx, optionaltxt="Enter Email: "): # Function to accept em
|
||||||
|
|
||||||
|
|
||||||
def new_add(screen, calledby=None):
|
def new_add(screen, calledby=None):
|
||||||
|
"""Creation of a new account with random GamerID"""
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
screen.border()
|
||||||
|
@ -463,6 +472,7 @@ def new_add(screen, calledby=None):
|
||||||
|
|
||||||
|
|
||||||
def modify_account(screen):
|
def modify_account(screen):
|
||||||
|
"""Modifies account details"""
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
screen.border()
|
||||||
|
@ -533,6 +543,7 @@ def modify_account(screen):
|
||||||
|
|
||||||
|
|
||||||
def view_account(screen):
|
def view_account(screen):
|
||||||
|
"""Views account details and scores"""
|
||||||
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
||||||
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
curses.init_pair(2, curses.COLOR_GREEN, curses.COLOR_BLACK)
|
||||||
global loggedin, U, gamerid
|
global loggedin, U, gamerid
|
||||||
|
@ -599,6 +610,7 @@ def view_account(screen):
|
||||||
|
|
||||||
|
|
||||||
def delete(screen):
|
def delete(screen):
|
||||||
|
"""Deletes account"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
global loggedin, gamerid, U
|
global loggedin, gamerid, U
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
@ -641,6 +653,7 @@ def delete(screen):
|
||||||
|
|
||||||
|
|
||||||
def Update_score(score, game):
|
def Update_score(score, game):
|
||||||
|
"""Updates score of game given in args"""
|
||||||
tablename = game + "_scores"
|
tablename = game + "_scores"
|
||||||
global U, gamerid, loggedin
|
global U, gamerid, loggedin
|
||||||
if not loggedin:
|
if not loggedin:
|
||||||
|
@ -669,6 +682,7 @@ def Update_score(score, game):
|
||||||
|
|
||||||
|
|
||||||
def Update_lp_tp(tablename):
|
def Update_lp_tp(tablename):
|
||||||
|
"""Updates last played and times played"""
|
||||||
global U, gamerid, loggedin
|
global U, gamerid, loggedin
|
||||||
if not loggedin:
|
if not loggedin:
|
||||||
return "guest"
|
return "guest"
|
||||||
|
@ -681,6 +695,7 @@ def Update_lp_tp(tablename):
|
||||||
|
|
||||||
|
|
||||||
def forgotpassword(screen):
|
def forgotpassword(screen):
|
||||||
|
"""Forgot password screen + new password"""
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
|
@ -807,6 +822,7 @@ def forgotpassword(screen):
|
||||||
|
|
||||||
|
|
||||||
def logout(screen):
|
def logout(screen):
|
||||||
|
"""Logout"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
@ -825,6 +841,7 @@ def logout(screen):
|
||||||
|
|
||||||
|
|
||||||
def leaderboard(screen):
|
def leaderboard(screen):
|
||||||
|
"""Leaderboard"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
|
||||||
curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)
|
||||||
|
|
|
@ -5,6 +5,7 @@ from maze.modules.maze import main
|
||||||
|
|
||||||
|
|
||||||
def bruh():
|
def bruh():
|
||||||
|
"""Initialising the screen"""
|
||||||
try:
|
try:
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
|
|
|
@ -4,6 +4,7 @@ import maze.menu
|
||||||
|
|
||||||
|
|
||||||
def about(screen):
|
def about(screen):
|
||||||
|
"""Displays the about screen"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
|
@ -40,6 +40,8 @@ VISITED = 16
|
||||||
|
|
||||||
|
|
||||||
class Maze:
|
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)):
|
def __init__(self, height, width, start=(0, 0)):
|
||||||
self.height = height
|
self.height = height
|
||||||
self.width = width - 11
|
self.width = width - 11
|
||||||
|
@ -142,6 +144,7 @@ class Maze:
|
||||||
|
|
||||||
|
|
||||||
def path(maze, start, finish):
|
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])
|
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()
|
||||||
|
@ -177,6 +180,7 @@ def path(maze, start, finish):
|
||||||
def draw_path(
|
def draw_path(
|
||||||
path, screen, delay=0, head=None, trail=None, skip_first=True, calledby=None
|
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:
|
if not head:
|
||||||
head = ("█", curses.color_pair(2))
|
head = ("█", curses.color_pair(2))
|
||||||
if not trail:
|
if not trail:
|
||||||
|
@ -215,6 +219,7 @@ def coords(node):
|
||||||
|
|
||||||
|
|
||||||
def construction_demo(maze, screen):
|
def construction_demo(maze, screen):
|
||||||
|
"""Loading screen"""
|
||||||
head = (".", curses.color_pair(5) | curses.A_BOLD)
|
head = (".", curses.color_pair(5) | curses.A_BOLD)
|
||||||
trail = (".", curses.color_pair(2) | curses.A_BOLD)
|
trail = (".", curses.color_pair(2) | curses.A_BOLD)
|
||||||
draw_path(
|
draw_path(
|
||||||
|
@ -226,6 +231,8 @@ def construction_demo(maze, screen):
|
||||||
def pathfinding_demo(
|
def pathfinding_demo(
|
||||||
maze, screen, start_ts, won_coords, loadedcoords=None, loadedtime=0
|
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 = []
|
start = []
|
||||||
finish = []
|
finish = []
|
||||||
solution = None
|
solution = None
|
||||||
|
@ -412,10 +419,14 @@ def play(
|
||||||
outerscore=0,
|
outerscore=0,
|
||||||
outergame=False,
|
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()
|
y, x = screen.getmaxyx()
|
||||||
height, width = int((y - 2) / 2), int((x - 2) / 2)
|
height, width = int((y - 2) / 2), int((x - 2) / 2)
|
||||||
|
|
||||||
def guestswitch(score, game):
|
def guestswitch(score, game):
|
||||||
|
"""For checking if guest, else updating score"""
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.border()
|
screen.border()
|
||||||
|
@ -498,6 +509,7 @@ def play(
|
||||||
|
|
||||||
|
|
||||||
def main(screen):
|
def main(screen):
|
||||||
|
"""Main function initialising screen settings, display loading screen and creates a maze"""
|
||||||
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)
|
||||||
|
|
|
@ -9,6 +9,7 @@ from .PlayerBase_func import input, screenwipe
|
||||||
|
|
||||||
|
|
||||||
def save(screen, maze, coords, elapsed):
|
def save(screen, maze, coords, elapsed):
|
||||||
|
"""Saves the maze to a binary file"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
if "saves" not in os.listdir():
|
if "saves" not in os.listdir():
|
||||||
os.mkdir("saves")
|
os.mkdir("saves")
|
||||||
|
@ -48,6 +49,7 @@ def check():
|
||||||
|
|
||||||
|
|
||||||
def load(screen):
|
def load(screen):
|
||||||
|
"""Loads a maze and returns maze, coords and time"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
|
|
|
@ -6,6 +6,7 @@ from random import choice
|
||||||
|
|
||||||
|
|
||||||
def sender(userid, receiver_address):
|
def sender(userid, receiver_address):
|
||||||
|
"""Sends forgot password email"""
|
||||||
try:
|
try:
|
||||||
with open("credentials.pickle", "rb") as f:
|
with open("credentials.pickle", "rb") as f:
|
||||||
d = pickle.load(f)
|
d = pickle.load(f)
|
||||||
|
|
9
pong.py
9
pong.py
|
@ -10,6 +10,8 @@ quit = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
class Scores:
|
class Scores:
|
||||||
|
"""Class object to take care of score"""
|
||||||
|
|
||||||
def __init__(self, screen):
|
def __init__(self, screen):
|
||||||
self.score = 0
|
self.score = 0
|
||||||
self.screen = screen
|
self.screen = screen
|
||||||
|
@ -30,6 +32,8 @@ class Scores:
|
||||||
|
|
||||||
|
|
||||||
class Ball:
|
class Ball:
|
||||||
|
"""Class object to store ball coordinates, predict ball movement, detect collision"""
|
||||||
|
|
||||||
def __init__(self, y, x, screen):
|
def __init__(self, y, x, screen):
|
||||||
self.ball_dx = 1
|
self.ball_dx = 1
|
||||||
self.ball_dy = 1
|
self.ball_dy = 1
|
||||||
|
@ -106,6 +110,8 @@ class Ball:
|
||||||
|
|
||||||
|
|
||||||
class Player:
|
class Player:
|
||||||
|
"""Class object of the paddle"""
|
||||||
|
|
||||||
def __init__(self, y, x):
|
def __init__(self, y, x):
|
||||||
self.y = y
|
self.y = y
|
||||||
self.x = x
|
self.x = x
|
||||||
|
@ -122,6 +128,7 @@ class Player:
|
||||||
|
|
||||||
|
|
||||||
def player_movement(screen, player):
|
def player_movement(screen, player):
|
||||||
|
"""Function to control player movement"""
|
||||||
global quit
|
global quit
|
||||||
screen.keypad(True)
|
screen.keypad(True)
|
||||||
while 1:
|
while 1:
|
||||||
|
@ -142,6 +149,7 @@ def player_movement(screen, player):
|
||||||
|
|
||||||
|
|
||||||
def ball_movement(screen, ball, score):
|
def ball_movement(screen, ball, score):
|
||||||
|
"""Function to control ball movement and detect end of game"""
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
while 1:
|
while 1:
|
||||||
# f.write("ball running\n")
|
# f.write("ball running\n")
|
||||||
|
@ -179,6 +187,7 @@ def ball_movement(screen, ball, score):
|
||||||
|
|
||||||
|
|
||||||
def main(screen):
|
def main(screen):
|
||||||
|
"""Initialises color pairs, spins up two seperate threads for ball and player"""
|
||||||
global quit
|
global quit
|
||||||
quit.clear()
|
quit.clear()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
|
|
|
@ -8,6 +8,7 @@ from maze.modules import bruh
|
||||||
|
|
||||||
user = password = None
|
user = password = None
|
||||||
|
|
||||||
|
"""Gets mysql pass and username"""
|
||||||
with open("credentials.pickle", "rb") as f:
|
with open("credentials.pickle", "rb") as f:
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -21,6 +22,7 @@ with open("credentials.pickle", "rb") as f:
|
||||||
|
|
||||||
|
|
||||||
def getcreds():
|
def getcreds():
|
||||||
|
"""Checks mysql creds"""
|
||||||
if user:
|
if user:
|
||||||
return user, password
|
return user, password
|
||||||
else:
|
else:
|
||||||
|
@ -44,6 +46,7 @@ Run 'python starter.py initsql' to initialise credentials of your choice. """
|
||||||
|
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
|
"""Called with no arguments"""
|
||||||
getcreds()
|
getcreds()
|
||||||
try:
|
try:
|
||||||
bruh()
|
bruh()
|
||||||
|
@ -53,6 +56,7 @@ if len(sys.argv) == 1:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
if sys.argv[1] == "dumpsample":
|
if sys.argv[1] == "dumpsample":
|
||||||
|
"""dumps sample database"""
|
||||||
getcreds()
|
getcreds()
|
||||||
player.databaseinit()
|
player.databaseinit()
|
||||||
subprocess.call(
|
subprocess.call(
|
||||||
|
@ -64,6 +68,7 @@ else:
|
||||||
print("Successfully dumped sample data")
|
print("Successfully dumped sample data")
|
||||||
|
|
||||||
elif sys.argv[1] == "initsql":
|
elif sys.argv[1] == "initsql":
|
||||||
|
"""Stores mysql creds"""
|
||||||
user = input("Enter MySQL username: ")
|
user = input("Enter MySQL username: ")
|
||||||
password = input("Enter MySQL password: ")
|
password = input("Enter MySQL password: ")
|
||||||
with open("credentials.pickle", "rb+") as f:
|
with open("credentials.pickle", "rb+") as f:
|
||||||
|
|
|
@ -16,6 +16,7 @@ language = "en-us"
|
||||||
|
|
||||||
|
|
||||||
def defnsyn(w):
|
def defnsyn(w):
|
||||||
|
"""Returns definition and synonym of said word"""
|
||||||
url = (
|
url = (
|
||||||
r"https://od-api.oxforddictionaries.com:443/api/v2/entries/"
|
r"https://od-api.oxforddictionaries.com:443/api/v2/entries/"
|
||||||
+ language
|
+ language
|
||||||
|
|
Loading…
Reference in a new issue