RE project - trivia game

2007-12-04 Thread Shawn Minisall

Sorry, 4got to send it in html for the bold parts.

thx

def drawMainMenu(win):
   #define and draw the buttons
   mainMenuList = []
   mainMenuList.append (CreateRect(4,6,7,8,grey,win))
   mainMenuList.append (CreateRect(3.5,6.5,5,6,grey,win))
   mainMenuList.append (CreateRect(3.5,6.5,3,4,grey,win))
   mainMenuList.append (CreateRect(3.1,7,1,2,grey,win))
   mainMenuList.append (CreateRect(8,10,0,1,grey,win))

   #define and draw the main menu
   mainMenuList.append (CreateText(5,9.5,MAIN MENU,times roman, 30, 
normal, red,win))
   mainMenuList.append (CreateText(2,8.5,Please pick a subject from 
below: ,times roman, 14, normal, purple,win))
   mainMenuList.append (CreateText(5,7.5,MATH,times roman, 28, 
italic, blue,win))
   mainMenuList.append (CreateText(5,5.5,SCIENCE,times roman, 28, 
italic, yellow,win))
   mainMenuList.append (CreateText(5,3.5,HISTORY,times roman, 28, 
italic, pink,win))
   mainMenuList.append (CreateText(5,1.5,GEOGRAPHY,times roman, 28, 
italic, green,win))
   mainMenuList.append (CreateText(9,.5,Quit,times roman, 20, 
italic, black,win))


   return(mainMenuList)
  
def UndrawMenu (menulist):

   for i in range(len(menulist)):
   menulist[i].undraw()

 
def CreateText(x,y,myString,myFace,mySize, myStyle, myColor,win):

   myText = Text(Point(x,y), myString)
   myText.setFace(myFace)
   myText.setSize(mySize)
   myText.setStyle(myStyle)
   myText.setTextColor(myColor)
   myText.draw(win)
   return myText

def CreateRect(x1,x2,y1,y2,myFill,win):
   myRect = Rectangle(Point(x1,y1,), Point(x2,y2))
   myRect.setFill(myFill)
   myRect.draw(win)
   return myRect

def isValidClick(x1,x2, y1, y2, p1, win):
   if p1.getX()=x1 and p1.getY()=y1 and p1.getX()=x2 and p1.getY()=y2:
   return True
   else:
   return False

def drawQuestion (subject, question, answers, win):
   menuList = []

   #define and draw the entry boxes
   entchoice = Entry(Point(6.4,6.5), 1)
   entchoice.setText(A)
   entchoice.setTextColor (blue)
   entchoice.draw(win)
  
   menuList.append(entchoice)
   menuList.append(CreateText(5,9.5,question,times roman, 18, 
normal, red,win))
   menuList.append(CreateText(2,8.5,A.  + answers[0],times roman, 
16, normal, purple,win))
   menuList.append(CreateText(7.5,8.5,B.  + answers[1],times roman, 
16, normal, purple,win))
   menuList.append(CreateText(2,7.5,C.  + answers[2],times roman, 
16, normal, purple,win))
   menuList.append(CreateText(7.5,7.5,D.  + answers[3],times roman, 
16, normal, purple,win))
   menuList.append(CreateText(4.7,6.5,Please enter your 
choice:,times roman, 16, normal, purple,win))


   #draw answer box and text
   answerButton = Rectangle(Point(7,5.5), Point(3,4))
   answerButton.setFill(grey)
   answerButton.draw(win)
   answerButton = Text(Point(5,4.8),Answer)
   answerButton.setTextColor(black)
   answerButton.setSize(22)
   answerButton.draw(win)
   menuList.append(answerButton)

   return(menuList)  



def main():

   #Declare and initialize variables



   #make math question list
   mathlist = []
   question = [An equilateral triangle has how many sides?, 3, 4 
, 1, 5]

   mathlist.append(question)
   question = [How many inches are in a foot?, 12, 6, 3, 9]
   mathlist.append(question)
   question = [One Kilogram equals how many grams?, 1000, 230, 
450, 100]

   mathlist.append(question)
   question = [Which means nine hundred sixty three thousandths?, 
.963, .0963, .0.0963, 9.63]

   mathlist.append(question)
   question = [A fathom is a unit of measurement for which of the 
following?, depth, space, time, distance]

   mathlist.append(question)
   question = [What is 111, plus 112, plus 113?, 336, 332, 331, 
333]

   mathlist.append(question)
  
   #show the rules of the game window

   win = GraphWin(RULES OF THE GAME,600,600)
   win.setBackground(orange)
   win.setCoords(0.0,0.0,10.0,10.0)

   txtrules1 = CreateText(5,9.5,The rules of the game are as 
follows:,times roman, 16, normal, red,win)
   txtrules2 = CreateText(5,8.5,The game will be made up of 10 
questions, 2 from each grade 1-5.,times roman, 12, normal, black,win)
   txtrules3 = CreateText(5,7.5,You will be able to pick 2 subjects 
you want to answer for each grade.,times roman, 12, normal, 
black,win)
   txtrules4 = CreateText(5,6.5,The subjects you can pick from are 
Math, Science, History and Geography.,times roman, 12, normal, 
black,win)
   txtrules5 = CreateText(5,5.5,No more then 3 questions can be 
answered from each subject.,times roman, 12, normal, black,win)
   txtrules6 = CreateText(5,2.5,HAVE FUN AND GOOD LUCK!,times 
roman, 26, normal, yellow,win)



   #define window and set coords
   win =GraphWin(Are You Smarter Then a Fifth Grader???,800,800)
   win.setBackground(orange)
   win.setCoords(0.0,0.0,10.0,10.0)
   mainMenuList = drawMainMenu(win)



   #getMouse
   p1 = win.getMouse()
   while(isValidClick(8,10,0,1,p1,win)==False):
   if (isValidClick(4,6,7,8,p1,win)==True):
   currentList = mathlist
   subject = Math

   elif 

Re: project - trivia game

2007-12-04 Thread Ramsey Nasser
Shawn,

First of all, next time try and isolate the problem yourself and send
a short snippet of code demonstrating the behavior you're having
trouble with. This makes it easier for other people to understand what
is going on and help you in a more focused way.

On Dec 5, 2007 2:43 AM, Shawn Minisall [EMAIL PROTECTED] wrote:
 For my final project, I'm trying to do a GUI based game similar to are

which GUI toolkit are you using?

 you smarter then a 5th grader.  I've been working on it and am stuck
 with some code someone helped me with to randomize the A,B,C,D letters
 that the correct answer is assigned too.  The code that does this is
 highlighted in bold and the code that assigns it to a variable is also
 in bold so I can test it in the console window.  Problem is, it's always
 stuck at letter A and doesn't always give the correct answer.  The
 correct answer is always position 1 in my make math question list.
 Could someone please help?

Your randomization code works. There are two issues that are causing
your problem, though.

1. You provide no mechanism to keep track of what answers are
correct. In the whole program, there is no notion of whether an
answer is right or wrong. So you can't expect to get the correct
answer to a question without telling the machine which one it is.
Although it may start out at position 1, this is lost after
randomization.

2. Your program is hardcoded to always pick letter A

pResult = (currentScreen[0].getText())
print pResult

cResult = (currentScreen[2].getText())
print cResult

Following the definition of drawQuestion, currentScreen[0] will
contain entchoice which has text 'A', and currentScreen[2] will always
contain answer A and the first answer in the list, regardless of
whether or not it is correct (again, the machine has no way of
knowing). I'm not completely sure what you're trying to do here
(pResult, cResult...problemResult, correctResult?), so some more
explanation would help.

Also, some general comments:

#Picks random question
qNum = randrange(0, len(currentList))
qList = currentList[qNum]

can be replaced with

qList = choice(currentList)

(you would have to replace currentList.pop(qNum) with
currentList.remove(qList) )

aList = []
tmpList = qList[1:5]

#Randomizes answers
while(len(tmpList)  0):
   rNum = randrange(0, len(tmpList))
   aList.append(tmpList[rNum])
   tmpList.pop(rNum)

can be replaced with

aList = qList[1:5]
shuffle(aList)

 thanks

 BTW, to whoever asked me why I don't use functions b4, I'm using them
 now that I've learned how to... :P ;)

Probably a good idea :)

Good luck with everything
-- 
nasser
-- 
http://mail.python.org/mailman/listinfo/python-list