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

View file

@ -1,10 +1,15 @@
import curses
import sys
from maze.modules.maze import main
def bruh():
try:
curses.wrapper(main)
curses.nocbreak()
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]
if collision == "OVER":
finalscore = score.score
screen.addstr(y // 2 - 1, x // 2 - 4, "GAME OVER!")
screen.addstr(y // 2, x // 2 - 5, "The Score is: " + str(finalscore))
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), curses.color_pair(3) | curses.A_BOLD)
time.sleep(0.25)
quit.set()
time.sleep(1)
time.sleep(1.75)
break
elif collision == "collision":
score.scoreupdate()
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()
@ -177,6 +178,7 @@ def main(screen):
screen.keypad(True)
y, x = screen.getmaxyx()
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, " ", " ")
ball = Ball(y, x, screen)
score = Scores(screen)

View file

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