Implemented multiple screen scoreboard

This commit is contained in:
adithyagenie 2022-11-27 23:29:24 +05:30
parent 25a87ae61c
commit dea8f183be
4 changed files with 69 additions and 44 deletions

View file

@ -769,6 +769,7 @@ def logout(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() screen.clear()
screen.refresh() screen.refresh()
scree.border()
screen.addstr(1, x // 2 - 2, "LOGOUT") screen.addstr(1, x // 2 - 2, "LOGOUT")
screen.addstr(y // 2, 5, "Logging out of your account...") screen.addstr(y // 2, 5, "Logging out of your account...")
global loggedin, U, gamerid global loggedin, U, gamerid
@ -784,41 +785,54 @@ def logout(screen):
def leaderboard(screen): def leaderboard(screen):
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
screen.clear() curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
screen.border() curses.init_pair(6, curses.COLOR_CYAN, curses.COLOR_BLACK)
screen.addstr(1, x // 2 - 5, "LEADERBOARD") screen.keypad(True)
screen.refresh() leaderboardquit = True
res = get( tables = {0:"maze_scores", 1:"pong_scores", 2:"snake_scores", 3:"wordle_scores"}
"SELECT p.gamerid,\ current_page = 0
p.username,\ while leaderboardquit:
s.highscore,\ screen.clear()
s.lastplayed\ screen.border()
FROM player_details p,\ screen.refresh()
scores s\ screen.addstr(1, x // 2 - 5, "LEADERBOARD", curses.A_BOLD)
WHERE p.gamerid = s.gamerid " screen.addstr(3, x // 2 - 2, f"{tables[current_page].split('_')[0].upper()}", curses.color_pair(6) | curses.A_BOLD)
) res = get(
f"SELECT p.gamerid,\
p.username,\
s.highscore \
FROM player_details p,\
{tables[current_page]} s\
WHERE p.gamerid = s.gamerid "
)
for i in range(len(res) - 1): for i in range(len(res) - 1): # Sorting
for j in range(len(res) - 1 - i): for j in range(len(res) - 1 - i):
if res[j][2] < res[j + 1][2]: if res[j][2] < res[j + 1][2]:
res[j], res[j + 1] = res[j + 1], res[j] res[j], res[j + 1] = res[j + 1], res[j]
screen.addstr(3, 13, "GamerID") screen.addstr(5, 13, "Gamer ID", curses.color_pair(3))
screen.addstr(3, 30, "Username") screen.addstr(5, 30, "Username", curses.color_pair(3))
screen.addstr(3, 50, "High Score") screen.addstr(5, 50, "High Score", curses.color_pair(3))
screen.addstr(3, 70, "Last Played") sy = 7
sy = 5 for i in res:
for i in res: screen.addstr(sy, 13, str(i[0]))
screen.addstr(sy, 13, str(i[0])) screen.addstr(sy, 30, str(i[1]))
screen.addstr(sy, 30, str(i[1])) screen.addstr(sy, 50, str(i[2]), curses.color_pair(2) | curses.A_BOLD)
screen.addstr(sy, 50, str(i[2])) sy += 1
screen.addstr(sy, 70, str(i[3])) screen.addstr(y - 2, 2, "Use arrow keys for different pages.", curses.A_DIM)
sy += 1 screen.addstr(y - 2, x - 36, "Press [esc] to return to main menu.", curses.A_DIM)
screen.addstr(y - 2, 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: leaderboardquit = False
break break
elif key == curses.KEY_LEFT and current_page > 0:
current_page -= 1
break
elif key == curses.KEY_RIGHT and current_page < 3:
current_page += 1
break
screen.refresh() screen.refresh()
maze.menu.menu(screen) maze.menu.menu(screen)
return return

View file

@ -1,10 +1,15 @@
import curses import curses
import sys
from maze.modules.maze import main from maze.modules.maze import main
def bruh(): def bruh():
curses.wrapper(main) try:
curses.nocbreak() curses.wrapper(main)
curses.echo() curses.nocbreak()
curses.endwin() curses.echo()
curses.endwin()
except KeyboardInterrupt:
print("\n\n\nTerminating...")
sys.exit()

10
pong.py
View file

@ -155,15 +155,16 @@ def ball_movement(screen, ball, score):
collision = ball_coords[2] collision = ball_coords[2]
if collision == "OVER": if collision == "OVER":
finalscore = score.score finalscore = score.score
screen.addstr(y // 2 - 1, x // 2 - 4, "GAME OVER!") screen.addstr(y // 2 - 1, x // 2 - 3, "GAME OVER!", curses.color_pair(1) | curses.A_BOLD)
screen.addstr(y // 2, x // 2 - 5, "The Score is: " + str(finalscore)) screen.addstr(y // 2, x // 2 - 5, "The Score is: " + str(finalscore), curses.color_pair(3) | curses.A_BOLD)
time.sleep(0.25)
quit.set() quit.set()
time.sleep(1) time.sleep(1.75)
break break
elif collision == "collision": elif collision == "collision":
score.scoreupdate() score.scoreupdate()
screen.addch(old_ball_posy, old_ball_posx, " ") screen.addch(old_ball_posy, old_ball_posx, " ")
screen.addch(ball_posy, ball_posx, "", curses.color_pair(1)) screen.addch(ball_posy, ball_posx, "", curses.color_pair(1) | curses.A_BOLD)
screen.refresh() screen.refresh()
@ -177,6 +178,7 @@ def main(screen):
screen.keypad(True) screen.keypad(True)
y, x = screen.getmaxyx() y, x = screen.getmaxyx()
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK) curses.init_pair(1, curses.COLOR_RED, curses.COLOR_BLACK)
curses.init_pair(3, curses.COLOR_YELLOW, curses.COLOR_BLACK)
screen.border(0, 0, 0, " ", 0, 0, " ", " ") screen.border(0, 0, 0, " ", 0, 0, " ", " ")
ball = Ball(y, x, screen) ball = Ball(y, x, screen)
score = Scores(screen) score = Scores(screen)

View file

@ -45,9 +45,13 @@ Run 'python starter.py initsql' to initialise credentials of your choice. """
if len(sys.argv) == 1: if len(sys.argv) == 1:
getcreds() getcreds()
bruh() try:
player.sql.close() bruh()
sys.exit() except KeyboardInterrupt:
pass
finally:
player.sql.close()
sys.exit()
else: else:
if sys.argv[1] == "dumpsample": if sys.argv[1] == "dumpsample":
getcreds() getcreds()