-
Notifications
You must be signed in to change notification settings - Fork 0
/
view_players.py
105 lines (98 loc) · 3.48 KB
/
view_players.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# vim:ts=4:sw=4:expandtab
import pygame
import pprint
from cb import *
from timer import *
from textobj import *
from wiimote import *
from questions import *
from view_question import *
from pygame.locals import *
STATE_IDLE = 0
STATE_PLAYER1 = 1
STATE_PLAYER2 = 2
STATE_PLAYER3 = 3
STATE_PLAYER4 = 4
STATE_DONE = 5
class ViewPlayers:
def __init__(self, screen):
print "initiating view"
font = pygame.font.Font(None, 72)
self.font = font
self.res = None
self.headline = TextObj(screen, font, "Spieler einstellen", "center", 50)
font = pygame.font.Font(None, 36)
self.sfont = font
self.state = STATE_IDLE
self.player_desc = [
TextObj(screen, font, "Spieler 1:", 100, 200),
TextObj(screen, font, "Spieler 2:", 100, 300),
TextObj(screen, font, "Spieler 3:", 100, 400),
TextObj(screen, font, "Spieler 4:", 100, 500)
]
self.player_names = [
TextObj(screen, font, "", 250, 200),
TextObj(screen, font, "", 250, 300),
TextObj(screen, font, "", 250, 400),
TextObj(screen, font, "", 250, 500)
]
self.screen = screen
def handle_key(self, key):
print "handling key"
if key == K_DOWN:
print "user pressed down"
def handle_key_u(self, key):
if key == u'1':
self.state = STATE_PLAYER1
elif key == u'2':
self.state = STATE_PLAYER2
elif key == u'3':
self.state = STATE_PLAYER3
elif key == u'4':
self.state = STATE_PLAYER4
elif key == u'0':
self.state = STATE_IDLE
else:
n = self.player_names[self.state - 1]
if self.state < STATE_PLAYER1 or self.state > STATE_PLAYER4:
if key == u'\r':
print "done with player setup"
q = questions.next_question(self.screen)
self.res = ViewQuestion(self.screen, q, 1)
for c in range(0, 4):
if len(self.player_names[c].get_text()) > 0:
players.add_player(self.player_names[c].get_text())
players.dump()
return
print "printable char %s entered" % key
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(key)
# Handle backspace
if key == u'\x08':
n.set_text(n.get_text()[0:-1])
elif key == u'\r':
w = None
c = 0
while w == None:
TextObj(self.screen, self.font, u"Jetzt 1+2 drücken! (" + str(c) + ")", "center", "center").render()
pygame.display.flip()
try:
w = Wiimote(n.get_text(), None)
w.set_cb(CB.get_cb())
except:
w = None
c += 1
self.state = STATE_IDLE
print "done"
else:
n.set_text(n.get_text() + key)
def render(self, screen):
screen.fill((0, 0, 0))
self.headline.render()
for t in self.player_desc + self.player_names:
t.render()
if self.state >= STATE_PLAYER1 and self.state <= STATE_PLAYER4:
TextObj(self.screen, self.sfont, ">", 50, 200 + ((self.state - 1) * 100)).render()
return self.res