-
Notifications
You must be signed in to change notification settings - Fork 3
/
game.py
executable file
·73 lines (49 loc) · 1.76 KB
/
game.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
#!/usr/bin/env python
class Game(object):
def __init__(self):
pass
def play(self):
pass
class GameState(object):
"""Store the game state visible publicly. Eg. timers, points etc."""
def __init__(self):
pass
def __repr__(self):
return "GameState()"
class Player(object):
def __init__(self, name):
self.name = name
def __unicode__(self):
return self.name
def __str__(self):
return self.name
def __repr__(self):
return 'Player(' + repr(self.name) + ')'
def play(self, game_state):
return None
class HumanPlayer(Player):
def __init__(self, name, input_stream, output_stream, prompts=True):
Player.__init__(self, name)
self.input = input_stream
self.output = output_stream
self.prompts = prompts
def __repr__(self):
return 'HumanPlayer(' + repr(self.name) + ')'
def play(self, state):
if self.prompts:
self.output.write("Game State: %s\n%s> " % (state, self))
self.output.flush()
for line in self.input: # TODO: Fix needed. Lines are not read in one by one...
if line != "":
value, suit = line.split(' ', 2)
return Card(value, suit)
else:
if self.prompts:
self.output.write("%s> " % self)
class CourtPiece(object):
def __init__(self, players):
self.players = players
self.game_state = GameState()
def play(self):
for player in self.players:
print "Player (%s) played %s" % (player, player.play(self.game_state))