Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTuukka Hastrup <Tuukka.Hastrup@iki.fi>2010-03-19 22:15:29 (GMT)
committer Tuukka Hastrup <Tuukka.Hastrup@iki.fi>2010-03-19 22:15:29 (GMT)
commit7a0c594b306009c277fe585dd95f28a0a068dcb4 (patch)
treef80b952dc0c7b18cb93154fdb602b0f334715dd9
parent49ef4e9d8b5fc30d7d3a37ba5a0d1b672ed95388 (diff)
show random choices, not all choices
-rwxr-xr-xtoisto-proto.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/toisto-proto.py b/toisto-proto.py
index 7121948..b4c8512 100755
--- a/toisto-proto.py
+++ b/toisto-proto.py
@@ -61,6 +61,7 @@ class Game(object):
self.score = 0
self.time0 = None
self.selected = None
+ self.choices = None
def stats(self):
gametime = time.time() - self.time0
@@ -84,7 +85,11 @@ class Game(object):
# s.fill((0, 0, 0), (0, 0, DISPLAY_W, DISPLAY_H))
pygame.display.update()
- self.letter, self.sound, self.sample = random.choice(entries)
+ choices = random.sample(entries, 4)
+ self.letter, self.sound, self.sample = random.choice(choices)
+
+ self.choices = [letter for letter, sound, sample
+ in choices]
print self.sound
play_blocking(self.sample)
@@ -102,16 +107,16 @@ class Game(object):
pass
def draw_choices(self, reveal_answer=False):
- for x, text in enumerate(letters):
+ for x, text in enumerate(self.choices):
if reveal_answer:
- if letters[x] != self.letter:
+ if self.choices[x] != self.letter:
color = (0, 0, 0)
else:
color = (0, 255, 0) if x == self.selected else (127,0,0)
else:
color = (255, 255, 255) if x == self.selected else (127,127,127)
- x_coord = (DISPLAY_W-len(letters)*S*2)/2+x*S*2+S
+ x_coord = (DISPLAY_W-len(self.choices)*S*2)/2+x*S*2+S
y_coord = DISPLAY_H/2
for degree in range(0, 360, 60):
pygame.draw.circle(s, color, (x_coord+math.cos(degree/180.0*math.pi)*S*0.55, y_coord+S/2+math.sin(degree/180.0*math.pi)*S*0.55), int(S*0.38))
@@ -146,12 +151,12 @@ class Game(object):
# keys below this line don't work while paused
# game keys:
elif e.key in (pygame.K_LEFT, OLPC_LEFT):
- self.selected = (self.selected - 1) % len(entries)
+ self.selected = (self.selected - 1) % len(self.choices)
elif e.key in (pygame.K_RIGHT, OLPC_RIGHT):
- self.selected = (self.selected + 1) % len(entries)
+ self.selected = (self.selected + 1) % len(self.choices)
elif e.key in [pygame.K_SPACE, pygame.K_RETURN,
OLPC_CIRCLE, OLPC_CROSS, OLPC_SQUARE, OLPC_CHECK]:
- if letters[self.selected] == self.letter:
+ if self.choices[self.selected] == self.letter:
self.score += 1
s.fill((0,0,0), (0, 0, DISPLAY_W, DISPLAY_H))
self.draw_choices(reveal_answer=True)