Pong integrated with main menu

This commit is contained in:
adithyagenie 2022-11-24 17:43:45 +05:30
parent 9f2b0fde42
commit 96c158be79
4 changed files with 34 additions and 22 deletions

View file

@ -1,11 +1,13 @@
import curses
import sys
import time
import maze.modules.maze as m1
import maze.modules.maze_saveandload as sl
import maze.modules.PlayerBase_func as database
from maze.modules.about import about
import time
import sys
import pong
import snake
from maze.modules.about import about
def menu(screen):
@ -48,7 +50,7 @@ def menu(screen):
if key2 == ord("1"):
m1.play(screen)
elif key2 == ord("2"):
pass
pong.main(screen)
elif key2 == ord("3"):
snake.main(screen)
elif key2 == ord("4"):
@ -88,4 +90,3 @@ def menu(screen):
if key2 == 10:
screen.addstr(20, 5, " " * (x - 10))
break

View file

@ -467,15 +467,23 @@ def pathfinding_demo(
# screen.addstr(20, 5, " " * (x - 10))
# break
def play(screen, loadedmaze=None, loadedcoords=None, loadedtime=0, executeguest = False, outerscore = 0):
def play(
screen,
loadedmaze=None,
loadedcoords=None,
loadedtime=0,
executeguest=False,
outerscore=0,
):
y, x = screen.getmaxyx()
height, width = int((y - 2) / 2), int((x - 2) / 2)
def guestswitch(score):
screen.clear()
screen.refresh()
screen.addstr(
y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score)))
)
screen.border()
screen.addstr(y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score))))
res = database.Update_score(int(score))
if res == "guest":
screen.addstr(
@ -497,6 +505,7 @@ def play(screen, loadedmaze=None, loadedcoords=None, loadedtime=0, executeguest
screen.refresh()
menu(screen)
return
if executeguest:
guestswitch(outerscore)
return

17
pong.py
View file

@ -4,6 +4,8 @@ import threading
import time
from math import fabs
import maze.modules.maze as m1
quit = threading.Event()
@ -155,8 +157,8 @@ def ball_movement(screen, ball, score):
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))
time.sleep(5)
quit.set()
time.sleep(1)
break
elif collision == "collision":
score.scoreupdate()
@ -166,6 +168,8 @@ def ball_movement(screen, ball, score):
def main(screen):
global quit
quit.clear()
screen.clear()
screen.refresh()
screen.nodelay(True)
@ -176,6 +180,7 @@ def main(screen):
ball = Ball(y, x, screen)
score = Scores(screen)
player = Player(y, x)
ball_thread = None
ball_thread = threading.Thread(
target=ball_movement,
args=(
@ -184,6 +189,7 @@ def main(screen):
score,
),
)
player_thread = None
player_thread = threading.Thread(
target=player_movement,
args=(
@ -195,10 +201,5 @@ def main(screen):
screen.addstr(0, x - 12, "Score: 0")
ball_thread.start()
player_thread.run()
# player_movement(screen, player)
if __name__ == "__main__":
curses.wrapper(main)
time.sleep(1)
m1.play(screen, executeguest=True, outerscore=score.score)

View file

@ -2,6 +2,7 @@ import curses
import random
import time
from curses import textpad
import maze.menu
import maze.modules.maze as m