Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAbbi Honeycutt <amh7732@rit.edu>2010-11-11 08:33:19 (GMT)
committer Abbi Honeycutt <amh7732@rit.edu>2010-11-11 08:33:19 (GMT)
commit94aff5e347a9f220283407dde8ca21c335c6c33f (patch)
tree46b449f054e62960b0d3fc21e1426752ab7ee6da
parent6790bf42aec2158e5588d2f35a1153b289fec302 (diff)
Added random question generation support for addition, subtraction and division
-rw-r--r--dev/pacmath.activity/gameMain.py5
-rw-r--r--dev/pacmath.activity/question.py2
-rw-r--r--dev/pacmath.activity/questionGenerator.py15
3 files changed, 13 insertions, 9 deletions
diff --git a/dev/pacmath.activity/gameMain.py b/dev/pacmath.activity/gameMain.py
index 72ebcff..224c780 100644
--- a/dev/pacmath.activity/gameMain.py
+++ b/dev/pacmath.activity/gameMain.py
@@ -12,6 +12,8 @@ from GhostMovement import ghostMovement
from mazeSetup import mazeSetup
from questionGenerator import questionGenerator
from question import question
+import random
+import string
import pygame
import sys
@@ -35,7 +37,8 @@ class gameMain:
# size = olpcgames.ACTIVITY.game_size
pygame.display.set_caption('PacMath')
self.screen.fill((0,0,0))
- self.questGen = questionGenerator( 'x', 2, 12 )
+ self.operation = random.sample('x+-/', 1)
+ self.questGen = questionGenerator( self.operation, 2, 12 )
self.lives = BASE_LIVES
self.score = 0
diff --git a/dev/pacmath.activity/question.py b/dev/pacmath.activity/question.py
index d8205f7..67eed88 100644
--- a/dev/pacmath.activity/question.py
+++ b/dev/pacmath.activity/question.py
@@ -29,7 +29,7 @@ class question:
# Default
def __init__ (self, screen, quests):
"""
- Randomly selects which questions are goign to be used and draws teh answer
+ Randomly selects which questions are going to be used and draws the answer
@param screen: the screen in which we will draw
@param quests: array a questions with answers
"""
diff --git a/dev/pacmath.activity/questionGenerator.py b/dev/pacmath.activity/questionGenerator.py
index b62453d..c95dac5 100644
--- a/dev/pacmath.activity/questionGenerator.py
+++ b/dev/pacmath.activity/questionGenerator.py
@@ -23,6 +23,8 @@ class questionGenerator:
self.minOp = minOp
self.maxOp = maxOp
self.operation = operation
+
+ print operation
def getQuestion(self):
"""
@@ -31,21 +33,20 @@ class questionGenerator:
@return A tuple contining two strings: ("question", "answer")
"""
op1 = randint(self.minOp, self.maxOp)
- op2 = randint(self.minOp, self.maxOp)
-
- if( self.operation == 'x' or self.operation == '*' or self.operation == 'X' ):
+ op2 = randint(self.minOp, self.maxOp)
+
+ if( self.operation == ['x'] ):
answer = op1*op2
return (str(op1)+" x " + str(op2) + " = ?", str(answer))
- elif( self.operation == '+' ):
+ if( self.operation == ['+'] ):
answer = op1+op2
return (str(op1)+" + "+ str(op2) + " = ?", str(answer))
- elif( self.operation == '-' ):
+ elif( self.operation == ['-'] ):
answer = op1-op2
return (str(op1)+" - "+ str(op2) + " = ?", str(answer))
- elif( self.operation == '/' ):
+ elif( self.operation == ['/'] ):
answer = op1*op2
return (str(answer)+" / "+ str(op1) + " = ?", str(op2))
-
else:
return null
def getQuestionSet(self):