Implemented multiple screen scoreboard
This commit is contained in:
parent
25a87ae61c
commit
dea8f183be
4 changed files with 69 additions and 44 deletions
|
@ -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,40 +785,53 @@ def logout(screen):
|
||||||
|
|
||||||
def leaderboard(screen):
|
def leaderboard(screen):
|
||||||
y, x = screen.getmaxyx()
|
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.clear()
|
||||||
screen.border()
|
screen.border()
|
||||||
screen.addstr(1, x // 2 - 5, "LEADERBOARD")
|
|
||||||
screen.refresh()
|
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(
|
res = get(
|
||||||
"SELECT p.gamerid,\
|
f"SELECT p.gamerid,\
|
||||||
p.username,\
|
p.username,\
|
||||||
s.highscore,\
|
s.highscore \
|
||||||
s.lastplayed\
|
|
||||||
FROM player_details p,\
|
FROM player_details p,\
|
||||||
scores s\
|
{tables[current_page]} s\
|
||||||
WHERE p.gamerid = s.gamerid "
|
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]))
|
screen.addstr(sy, 50, str(i[2]), curses.color_pair(2) | curses.A_BOLD)
|
||||||
screen.addstr(sy, 70, str(i[3]))
|
|
||||||
sy += 1
|
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:
|
while True:
|
||||||
key = screen.getch()
|
key = screen.getch()
|
||||||
if key == 27:
|
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
|
break
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
maze.menu.menu(screen)
|
maze.menu.menu(screen)
|
||||||
|
|
|
@ -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():
|
||||||
|
try:
|
||||||
curses.wrapper(main)
|
curses.wrapper(main)
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
curses.echo()
|
curses.echo()
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\n\n\nTerminating...")
|
||||||
|
sys.exit()
|
||||||
|
|
10
pong.py
10
pong.py
|
@ -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)
|
||||||
|
|
|
@ -45,7 +45,11 @@ Run 'python starter.py initsql' to initialise credentials of your choice. """
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
if len(sys.argv) == 1:
|
||||||
getcreds()
|
getcreds()
|
||||||
|
try:
|
||||||
bruh()
|
bruh()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
player.sql.close()
|
player.sql.close()
|
||||||
sys.exit()
|
sys.exit()
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue