forked from foprea/Jeopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayerServer.py
83 lines (63 loc) · 2.26 KB
/
PlayerServer.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
PlayerServer interfaces between the PlayerGui and the remotely accessible Player
class.
"""
import sys
from time import sleep
from socket import gethostbyname, gethostname
import Pyro.core
import Pyro.naming
from PyQt4.QtCore import *
from Server import Server
from Player import Player
class PlayerServer(Server):
playerConnected = pyqtSignal()
playerStatusChanged = pyqtSignal(str)
gameStarted = pyqtSignal()
buzzDisabled = pyqtSignal()
buttonClicked = pyqtSignal(int) ####################
"""
***REIMPLEMENTED METHODS FROM BASECLASS***
"""
def __init__(self, gui, name, parent=None):
Server.__init__(self, gui, name)
ns = Pyro.naming.NameServerLocator().getNS()
self.game = Pyro.core.getProxyForURI(ns.resolve('jeopardy'))
# 'PYRONAME://' + 'jeopardy')
self.running = False
self.name = name
#self.ip = gethostbyname(gethostname())
def run(self):
self.running = True
Server.run(self)
def setupSignals(self):
self.serverStarted.connect(self.connect)
self.gameStarted.connect(self.gui.startGame)
def setupGuiSignals(self):
Server.setupGuiSignals(self)
self.playerStatusChanged.connect(self.gui.updateStatus)
self.buzzDisabled.connect(self.gui.disableBuzz)
self.gui.getGrid().buttonClicked.connect(self.pickQuestion)############
def connectDaemon(self):
self.uri = self.daemon.connectPersistent(Player(self), str(hash(self.name))) ######
"""
***GAME FUNCTIONS***
"""
def startGame(self):
self.setupGuiSignals()
# registers with server after having reserved the nickname via the canConnect method
def connect(self):
self.log('Connecting to server')
self.game.connect(self.name)
self.playerConnected.emit()
# sets the player's name; used if the name the user initially selected is taken
def setName(self, name):
if not self.running:
self.name = name
# buzzes the game server (could have been called in the gui, but need name)
def buzz(self):
self.game.buzz(self.name)
###################
def pickQuestion(self, i):
print 'question picked is', i
self.game.acceptQuestion(i)