endgame.py 1.78 KB
Newer Older
Antoine Lima's avatar
Antoine Lima committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 18 18:34:40 2018

@author: Antoine Lima, Leo Reynaert, Domitille Jehenne
"""

import logging

from PyQt5 import QtWidgets
from PyQt5.QtGui import QRegion
from PyQt5.QtCore import QTime, QTimer, QRect, Qt

15
from player import Side
Antoine Lima's avatar
Antoine Lima committed
16
17
18
19
20
21
22
23
from module import Module
import modules
from ui.endgame_ui import Ui_Form as GameWidget

class EndGameModule(Module):
	def __init__(self, parent=None):
		super().__init__(parent, GameWidget())
		self.screenTimeout = QTimer()
24
		self.screenTimeout.timeout.connect(self.handleQuit)
Antoine Lima's avatar
Antoine Lima committed
25
26
27
28
29
		self.screenTimeout.setSingleShot(True)

	def load(self):
		logging.debug('Loading EndGameModule')
		
30
31
32
33
34
35
36
37
38
39
		if len(self.players[self.winSide])>1:
			self.ui.lblP2_2.setText('{} Side'.format(self.winSide.name))
		
		for side in [Side.Left, Side.Right]:
			for player in self.players[side]:
				player.victories    += 1 if side==self.winSide else 0
				player.goals_scored += self.scores[side]
				player.time_played  += self.time
				player.games_played += 1
				player.save()
Antoine Lima's avatar
Antoine Lima committed
40
41
		
		# Quit the screen after 5 seconds if the user doesn't do it before
42
		#self.screenTimeout.start(5000)
Antoine Lima's avatar
Antoine Lima committed
43
44
45
46

	def unload(self):
		logging.debug('Unloading EndGameModule')
		self.screenTimeout.stop()
47
48
		del self.players
		del self.winSide
Antoine Lima's avatar
Antoine Lima committed
49
50
51
52
	
	def other(self, **kwargs):
		logging.debug('Other EndGameModule')
		
53
54
55
56
57
58
59
60
61
62
63
		for key, val in kwargs.items():
			if key=='players':
				self.players = val
			elif key=='winSide':
				self.winSide = val
			elif key=='scores':
				self.scores = val
			elif key=='time':
				self.time = val
		#else:
		#	raise ValueError('Unknown message identifier {}'.format(kwargs)
Antoine Lima's avatar
Antoine Lima committed
64
65
66
		
	def keyPressEvent(self, e):
		if e.key() == Qt.Key_Escape or e.key() == Qt.Key_Return:
67
			self.handleQuit()
Antoine Lima's avatar
Antoine Lima committed
68
	
69
	def handleQuit(self):
Antoine Lima's avatar
Antoine Lima committed
70
		self.switchModule(modules.MenuModule)