-
Notifications
You must be signed in to change notification settings - Fork 0
/
Umpire.py
executable file
·70 lines (53 loc) · 1.85 KB
/
Umpire.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import logging
import time
import ConfigParser
import PongBot
class Umpire():
def __init__(self, configfile):
self._configfile = configfile
config = ConfigParser.ConfigParser()
config.read(configfile)
self._lastgame = config.getint('Umpire', 'lastgame')
self._xmpp = PongBot.PongBot(configfile)
def start(self):
self._resetGame() #Will increment last game
self._xmpp.start()
self._xmpp.resetGame( self._generateScore() )
def leftButton(self):
self._pointLeft = self._pointLeft + 1
self._move = self._move + 1
self._xmpp.pointLeft( self._generateScore() )
def rightButton(self):
self._pointRight = self._pointRight + 1
self._move = self._move + 1
self._xmpp.pointRight(self._generateScore() )
def longPressLeft(self):
self._resetGame()
self._xmpp.resetGame( self._generateScore() )
def longPressRight(self):
self.longPressLeft()
def stop(self):
self._xmpp.disconnect()
def _generateScore(self):
config = ConfigParser.ConfigParser()
config.read(self._configfile)
config.set('Umpire', 'lastgame', self._lastgame)
with open(self._configfile, 'wb') as configfile:
config.write(configfile)
return {'left': self._pointLeft, 'right': self._pointRight, 'game': self._lastgame, 'move': self._move}
def _resetGame(self):
self._lastgame = self._lastgame + 1
self._move = 0
self._pointLeft = 0
self._pointRight = 0
if __name__ == '__main__':
logging.basicConfig(level=5, format='%(levelname)-8s %(message)s')
ump = Umpire('pingpong.ini')
ump.start()
ump.leftButton()
ump.rightButton()
ump.rightButton()
ump.stop()