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 curses
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
import maze.modules.maze as m1
|
import maze.modules.maze as m1
|
||||||
import maze.modules.maze_saveandload as sl
|
import maze.modules.maze_saveandload as sl
|
||||||
import maze.modules.PlayerBase_func as database
|
import maze.modules.PlayerBase_func as database
|
||||||
from maze.modules.about import about
|
import pong
|
||||||
import time
|
|
||||||
import sys
|
|
||||||
import snake
|
import snake
|
||||||
|
from maze.modules.about import about
|
||||||
|
|
||||||
|
|
||||||
def menu(screen):
|
def menu(screen):
|
||||||
|
@ -48,7 +50,7 @@ def menu(screen):
|
||||||
if key2 == ord("1"):
|
if key2 == ord("1"):
|
||||||
m1.play(screen)
|
m1.play(screen)
|
||||||
elif key2 == ord("2"):
|
elif key2 == ord("2"):
|
||||||
pass
|
pong.main(screen)
|
||||||
elif key2 == ord("3"):
|
elif key2 == ord("3"):
|
||||||
snake.main(screen)
|
snake.main(screen)
|
||||||
elif key2 == ord("4"):
|
elif key2 == ord("4"):
|
||||||
|
@ -88,4 +90,3 @@ def menu(screen):
|
||||||
if key2 == 10:
|
if key2 == 10:
|
||||||
screen.addstr(20, 5, " " * (x - 10))
|
screen.addstr(20, 5, " " * (x - 10))
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
|
@ -253,8 +253,8 @@ def pathfinding_demo(
|
||||||
reset(finish, cell, curses.color_pair(2))
|
reset(finish, cell, curses.color_pair(2))
|
||||||
reset(start, (0, 0), curses.color_pair(2))
|
reset(start, (0, 0), curses.color_pair(2))
|
||||||
else:
|
else:
|
||||||
current_coords = [maxy - 5, maxx - 27]
|
current_coords = [maxy - 5, maxx - 27]
|
||||||
#current_coords = [1, 1]
|
# current_coords = [1, 1]
|
||||||
screen.addstr(current_coords[0], current_coords[1], "█", curses.color_pair(2))
|
screen.addstr(current_coords[0], current_coords[1], "█", curses.color_pair(2))
|
||||||
WALL = ["═", "║", "╗", "╚", "╝", "╔", "╠", "╣", "╦", "╩", "╬", "═", "═", "║", "║"]
|
WALL = ["═", "║", "╗", "╚", "╝", "╔", "╠", "╣", "╦", "╩", "╬", "═", "═", "║", "║"]
|
||||||
pause_elapsed = 0
|
pause_elapsed = 0
|
||||||
|
@ -467,15 +467,23 @@ def pathfinding_demo(
|
||||||
# screen.addstr(20, 5, " " * (x - 10))
|
# screen.addstr(20, 5, " " * (x - 10))
|
||||||
# break
|
# 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()
|
y, x = screen.getmaxyx()
|
||||||
height, width = int((y - 2) / 2), int((x - 2) / 2)
|
height, width = int((y - 2) / 2), int((x - 2) / 2)
|
||||||
|
|
||||||
def guestswitch(score):
|
def guestswitch(score):
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.addstr(
|
screen.border()
|
||||||
y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score)))
|
screen.addstr(y // 2 - 5, x // 2 - 8, str("Your score is: " + str(int(score))))
|
||||||
)
|
|
||||||
res = database.Update_score(int(score))
|
res = database.Update_score(int(score))
|
||||||
if res == "guest":
|
if res == "guest":
|
||||||
screen.addstr(
|
screen.addstr(
|
||||||
|
@ -497,6 +505,7 @@ def play(screen, loadedmaze=None, loadedcoords=None, loadedtime=0, executeguest
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
menu(screen)
|
menu(screen)
|
||||||
return
|
return
|
||||||
|
|
||||||
if executeguest:
|
if executeguest:
|
||||||
guestswitch(outerscore)
|
guestswitch(outerscore)
|
||||||
return
|
return
|
||||||
|
|
21
pong.py
21
pong.py
|
@ -4,6 +4,8 @@ import threading
|
||||||
import time
|
import time
|
||||||
from math import fabs
|
from math import fabs
|
||||||
|
|
||||||
|
import maze.modules.maze as m1
|
||||||
|
|
||||||
quit = threading.Event()
|
quit = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,7 +25,7 @@ class Scores:
|
||||||
return self.speed_multiplier
|
return self.speed_multiplier
|
||||||
|
|
||||||
def scoreupdater(self):
|
def scoreupdater(self):
|
||||||
y,x = self.screen.getmaxyx()
|
y, x = self.screen.getmaxyx()
|
||||||
self.screen.addstr(0, x - 5, str(self.score))
|
self.screen.addstr(0, x - 5, str(self.score))
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,8 +157,8 @@ def ball_movement(screen, ball, score):
|
||||||
finalscore = score.score
|
finalscore = score.score
|
||||||
screen.addstr(y // 2 - 1, x // 2 - 4, "GAME OVER!")
|
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, x // 2 - 5, "The Score is: " + str(finalscore))
|
||||||
time.sleep(5)
|
|
||||||
quit.set()
|
quit.set()
|
||||||
|
time.sleep(1)
|
||||||
break
|
break
|
||||||
elif collision == "collision":
|
elif collision == "collision":
|
||||||
score.scoreupdate()
|
score.scoreupdate()
|
||||||
|
@ -166,16 +168,19 @@ def ball_movement(screen, ball, score):
|
||||||
|
|
||||||
|
|
||||||
def main(screen):
|
def main(screen):
|
||||||
|
global quit
|
||||||
|
quit.clear()
|
||||||
screen.clear()
|
screen.clear()
|
||||||
screen.refresh()
|
screen.refresh()
|
||||||
screen.nodelay(True)
|
screen.nodelay(True)
|
||||||
curses.curs_set(False)
|
curses.curs_set(False)
|
||||||
screen.keypad(True)
|
screen.keypad(True)
|
||||||
y, x = screen.getmaxyx()
|
y, x = screen.getmaxyx()
|
||||||
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)
|
||||||
player = Player(y, x)
|
player = Player(y, x)
|
||||||
|
ball_thread = None
|
||||||
ball_thread = threading.Thread(
|
ball_thread = threading.Thread(
|
||||||
target=ball_movement,
|
target=ball_movement,
|
||||||
args=(
|
args=(
|
||||||
|
@ -184,6 +189,7 @@ def main(screen):
|
||||||
score,
|
score,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
player_thread = None
|
||||||
player_thread = threading.Thread(
|
player_thread = threading.Thread(
|
||||||
target=player_movement,
|
target=player_movement,
|
||||||
args=(
|
args=(
|
||||||
|
@ -195,10 +201,5 @@ def main(screen):
|
||||||
screen.addstr(0, x - 12, "Score: 0")
|
screen.addstr(0, x - 12, "Score: 0")
|
||||||
ball_thread.start()
|
ball_thread.start()
|
||||||
player_thread.run()
|
player_thread.run()
|
||||||
|
time.sleep(1)
|
||||||
# player_movement(screen, player)
|
m1.play(screen, executeguest=True, outerscore=score.score)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
curses.wrapper(main)
|
|
||||||
|
|
||||||
|
|
3
snake.py
3
snake.py
|
@ -2,6 +2,7 @@ import curses
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
from curses import textpad
|
from curses import textpad
|
||||||
|
|
||||||
import maze.menu
|
import maze.menu
|
||||||
import maze.modules.maze as m
|
import maze.modules.maze as m
|
||||||
|
|
||||||
|
@ -116,7 +117,7 @@ def main(stdscr):
|
||||||
pass
|
pass
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
m.play(stdscr, executeguest=True, outerscore=score)
|
m.play(stdscr, executeguest=True, outerscore=score)
|
||||||
#Call play with guestcheck to update scores
|
# Call play with guestcheck to update scores
|
||||||
stdscr.clear()
|
stdscr.clear()
|
||||||
stdscr.refresh()
|
stdscr.refresh()
|
||||||
maze.menu.menu(stdscr)
|
maze.menu.menu(stdscr)
|
||||||
|
|
Loading…
Reference in a new issue