Pong integrated with main menu
This commit is contained in:
parent
9f2b0fde42
commit
96c158be79
4 changed files with 34 additions and 22 deletions
11
maze/menu.py
11
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
21
pong.py
21
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)
|
||||
|
||||
time.sleep(1)
|
||||
m1.play(screen, executeguest=True, outerscore=score.score)
|
||||
|
|
3
snake.py
3
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)
|
||||
|
|
Loading…
Reference in a new issue