From 96c158be79e5dc06011fa8b69adc24f86ed3e193 Mon Sep 17 00:00:00 2001 From: adithyagenie Date: Thu, 24 Nov 2022 17:43:45 +0530 Subject: [PATCH] Pong integrated with main menu --- maze/menu.py | 11 ++++++----- maze/modules/maze.py | 21 +++++++++++++++------ pong.py | 21 +++++++++++---------- snake.py | 3 ++- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/maze/menu.py b/maze/menu.py index 5d890d7..232efed 100644 --- a/maze/menu.py +++ b/maze/menu.py @@ -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 - diff --git a/maze/modules/maze.py b/maze/modules/maze.py index e81939b..becc5cf 100644 --- a/maze/modules/maze.py +++ b/maze/modules/maze.py @@ -253,8 +253,8 @@ def pathfinding_demo( reset(finish, cell, curses.color_pair(2)) reset(start, (0, 0), curses.color_pair(2)) else: - current_coords = [maxy - 5, maxx - 27] - #current_coords = [1, 1] + current_coords = [maxy - 5, maxx - 27] + # current_coords = [1, 1] screen.addstr(current_coords[0], current_coords[1], "█", curses.color_pair(2)) WALL = ["═", "║", "╗", "╚", "╝", "╔", "╠", "╣", "╦", "╩", "╬", "═", "═", "║", "║"] pause_elapsed = 0 @@ -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 diff --git a/pong.py b/pong.py index 579e1dc..28a55d2 100644 --- a/pong.py +++ b/pong.py @@ -4,6 +4,8 @@ import threading import time from math import fabs +import maze.modules.maze as m1 + quit = threading.Event() @@ -23,7 +25,7 @@ class Scores: return self.speed_multiplier def scoreupdater(self): - y,x = self.screen.getmaxyx() + y, x = self.screen.getmaxyx() self.screen.addstr(0, x - 5, str(self.score)) @@ -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,16 +168,19 @@ def ball_movement(screen, ball, score): def main(screen): + global quit + quit.clear() screen.clear() screen.refresh() screen.nodelay(True) curses.curs_set(False) screen.keypad(True) y, x = screen.getmaxyx() - screen.border(0,0,0," ",0,0," ", " ") + screen.border(0, 0, 0, " ", 0, 0, " ", " ") 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) - \ No newline at end of file + time.sleep(1) + m1.play(screen, executeguest=True, outerscore=score.score) diff --git a/snake.py b/snake.py index 0ed5a2a..0a7df88 100644 --- a/snake.py +++ b/snake.py @@ -2,6 +2,7 @@ import curses import random import time from curses import textpad + import maze.menu import maze.modules.maze as m @@ -116,7 +117,7 @@ def main(stdscr): pass time.sleep(2) m.play(stdscr, executeguest=True, outerscore=score) - #Call play with guestcheck to update scores + # Call play with guestcheck to update scores stdscr.clear() stdscr.refresh() maze.menu.menu(stdscr)