From 34f83966be7c18100afecae763c03864db3811a1 Mon Sep 17 00:00:00 2001 From: Eveldee Date: Tue, 19 Mar 2019 09:12:52 +0100 Subject: [PATCH] Add end game --- game/fall.py | 2 +- game/osu.py | 6 +++--- game/pong.py | 2 +- game/space.py | 2 +- main.py | 45 ++++++++++++++++++++++++++++++++++++++++----- 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/game/fall.py b/game/fall.py index 08a9798..8052b6c 100644 --- a/game/fall.py +++ b/game/fall.py @@ -5,5 +5,5 @@ def main(canvas: Canvas): pass # Loop -def loop(deltatime: float, difficulty: float): +def loop(deltatime: float, difficulty: float, end): pass diff --git a/game/osu.py b/game/osu.py index 807bf36..010211f 100644 --- a/game/osu.py +++ b/game/osu.py @@ -57,7 +57,7 @@ def main(c: tk.Canvas): circle = create_circle() # Loop -def loop(deltatime: float, difficulty: float): +def loop(deltatime: float, difficulty: float, end): global tick, circle # Step @@ -71,8 +71,8 @@ def loop(deltatime: float, difficulty: float): tick = 0.0 return else: - # TODO, lose - pass + end() + return else: circle.decrement() tick = 0.0 diff --git a/game/pong.py b/game/pong.py index 08a9798..8052b6c 100644 --- a/game/pong.py +++ b/game/pong.py @@ -5,5 +5,5 @@ def main(canvas: Canvas): pass # Loop -def loop(deltatime: float, difficulty: float): +def loop(deltatime: float, difficulty: float, end): pass diff --git a/game/space.py b/game/space.py index 08a9798..8052b6c 100644 --- a/game/space.py +++ b/game/space.py @@ -5,5 +5,5 @@ def main(canvas: Canvas): pass # Loop -def loop(deltatime: float, difficulty: float): +def loop(deltatime: float, difficulty: float, end): pass diff --git a/main.py b/main.py index d3e91f2..2470a20 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,10 @@ import tkinter as tk import datetime as dt import color -from time import sleep from game import fall, osu, pong, space from PIL import Image, ImageTk +from time import sleep +from tkinter import messagebox win = tk.Tk() win['bg'] = color.LEVEL_9 @@ -20,23 +21,32 @@ time = None delta = None tick = 0 score = tk.IntVar(win, 0) + +# Difficulty difficulty = 1.0 MAX_DIFFICULTY = 3.0 DIFFICULTY_STEP = (MAX_DIFFICULTY - difficulty) / 5000 +# End +_end = False + def loop(deltaTime): global time, delta, tick, score, difficulty + # Check end + if (_end): + return + # Start delta = dt.datetime.now() deltatime = (delta - time).microseconds * 1e-6 # Loop if tick > 2: - fall.loop(deltatime, difficulty) - osu.loop(deltatime, difficulty) - pong.loop(deltatime, difficulty) - space.loop(deltatime, difficulty) + fall.loop(deltatime, difficulty, end) + osu.loop(deltatime, difficulty, end) + pong.loop(deltatime, difficulty, end) + space.loop(deltatime, difficulty, end) # Step tick tick += 1 @@ -83,7 +93,32 @@ def main(): time = dt.datetime.now() loop(1000 / 60) +def getMessage(score): + if score < 200: + return 'Vous ferez peut être mieux la prochaine fois...' + elif score < 400: + return 'Un bon début !' + elif score < 600: + return 'Pas mal, mais vous ne pouvez faire quatre choses à la fois???' + elif score < 800: + return 'Bien, la maitrise vient avec le temps' + elif score < 1000: + return 'Bien joué, vous approchez de la difficulté maximum' + elif score < 5000: + return "Splendide, vous n\'avez plus qu'à attendre l'éternité" + else: + return "Ce jeu n'a plus aucun secrets pour vous !" +def end(): + global _end + + _end = True + messagebox.showinfo('Perdu', f'Votre score est de {score.get()} points\n{getMessage(score.get())}') + + # Terminate + win.destroy() + +# Main print('Bienvenue dans le jeu QuadraLudi') main() win.mainloop() \ No newline at end of file