From 94aff5e347a9f220283407dde8ca21c335c6c33f Mon Sep 17 00:00:00 2001 From: Abbi Honeycutt Date: Thu, 11 Nov 2010 08:33:19 +0000 Subject: Added random question generation support for addition, subtraction and division --- 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): -- cgit v0.9.1