77lets you run a simple game yourself, with questions and
88answers provided by you.
99
10+ NOTE: very much a work in progress!
11+
1012This code is in the public domain
1113
12141315
1416"""
1517
16-
1718import wx
1819
20+
1921class Question (object ):
2022 """
2123 A class to hold each question, and data about it.
@@ -182,7 +184,6 @@ def Draw(self, dc):
182184 # dc.DrawLine(x0, y0 + d*i, x0 + d*3, y0 + d*i)
183185 # dc.DrawLine(x0 + d*i, y0, x0 + d*i, y0 + d*3)
184186
185-
186187 def OnPaint (self , event ):
187188 dc = wx .BufferedPaintDC (self , self .buffer )
188189
@@ -191,7 +192,7 @@ def OnLeftDown(self, e):
191192 grid = self .grid
192193 x , y = e .GetPositionTuple ()
193194 i = x / grid .box_w
194- j = y / grid .box_h
195+ j = y / grid .box_h - 1 # compensate for header
195196 if i >= 0 and i < grid .num_cat and j >= 0 and j < grid .num_ques :
196197 self .game .questions [i ][j ].answered = not self .game .questions [i ][j ].answered
197198 self .DrawNow ()
@@ -378,92 +379,69 @@ def wrap_to_width(self):
378379# self.BoxHeight = BoxHeight
379380# self.CalcBoundingBox()
380381
382+ # def draw(self, DC):
383+ # for word in question:
384+ # pass
381385
382- def draw (self , DC ):
383- for word in question :
384- pass
385-
386-
387- # class TestFrame(wx.Frame):
388- # def __init__(self, *args, **kwargs):
389- # wx.Frame.__init__(self, *args, **kwargs)
390-
391- # self.Bind(wx.EVT_PAINT, self.OnPaint)
392- # #self.header = Header("This is a pretty long question that will need to wrap")
393-
394- # #header.wrap_to_width
395- # #print header.question_lines
396-
397- # def OnPaint(self, evt):
398- # dc = wx.PaintDC(self)
399- # #if self.header is not None:
400- # # self.header.draw(dc)
401-
402-
403- # if __name__ == '__main__':
404- # A = wx.App()
405- # F = TestFrame(None, title="test frame")
406- # F.Show()
407- # A.MainLoop()
408386
409387if __name__ == '__main__' :
410388
411389 catagories = [None for i in range (6 )]
412- questions = [ [None for i in range (5 )] for j in range (6 ) ]
413- ## test data:
390+ questions = [[None for i in range (5 )] for j in range (6 )]
391+
392+ # test data:
414393
415394 catagories [0 ] = "Household Pets"
416- questions [0 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
417- questions [0 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
418- questions [0 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
419- questions [0 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
420- questions [0 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
395+ questions [0 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
396+ questions [0 ][1 ] = Question ("cute and fuzzy" , "what is a cat?" , 200 )
397+ questions [0 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
398+ questions [0 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
399+ questions [0 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
400+ "what is a turtle?" , 500 )
421401
422- ## test data:
423402 catagories [1 ] = "Household Pets"
424- questions [1 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
425- questions [1 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
426- questions [1 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
427- questions [1 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
428- questions [1 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
403+ questions [1 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
404+ questions [1 ][1 ] = Question ("cute an fuzzy" , "what is a cat?" , 200 )
405+ questions [1 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
406+ questions [1 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
407+ questions [1 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
408+ "what is a turtle?" , 500 )
429409
430- ## test data:
431410 catagories [2 ] = "Household Pets"
432- questions [2 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
433- questions [2 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
434- questions [2 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
435- questions [2 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
436- questions [2 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
411+ questions [2 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
412+ questions [2 ][1 ] = Question ("cute an fuzzy" , "what is a cat?" , 200 )
413+ questions [2 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
414+ questions [2 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
415+ questions [2 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
416+ "what is a turtle?" , 500 )
437417
438- ## test data:
439418 catagories [3 ] = "Household Pets"
440- questions [3 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
441- questions [3 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
442- questions [3 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
443- questions [3 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
444- questions [3 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
445- ## test data:
419+ questions [3 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
420+ questions [3 ][1 ] = Question ("cute an fuzzy" , "what is a cat?" , 200 )
421+ questions [3 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
422+ questions [3 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
423+ questions [3 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
424+ "what is a turtle?" , 500 )
446425 catagories [4 ] = "Household Pets"
447- questions [4 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
448- questions [4 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
449- questions [4 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
450- questions [4 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
451- questions [4 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
426+ questions [4 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
427+ questions [4 ][1 ] = Question ("cute an fuzzy" , "what is a cat?" , 200 )
428+ questions [4 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
429+ questions [4 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
430+ questions [4 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
431+ "what is a turtle?" , 500 )
452432
453- ## test data:
454433 catagories [5 ] = "Household Pets"
455- questions [5 ][0 ] = Question ("slobbery" ,"what is a dog?" , 100 )
456- questions [5 ][1 ] = Question ("cute an fuzzy" ,"what is a cat?" , 200 )
457- questions [5 ][2 ] = Question ("long and slithery" ,"what is a snake?" , 300 )
458- questions [5 ][3 ] = Question ("sometimes lives in a sewer" ,"what is a rat?" , 400 )
459- questions [5 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,"what is a turtle?" , 500 )
460-
461-
462- #set a few as answered
434+ questions [5 ][0 ] = Question ("slobbery" , "what is a dog?" , 100 )
435+ questions [5 ][1 ] = Question ("cute an fuzzy" , "what is a cat?" , 200 )
436+ questions [5 ][2 ] = Question ("long and slithery" , "what is a snake?" , 300 )
437+ questions [5 ][3 ] = Question ("sometimes lives in a sewer" , "what is a rat?" , 400 )
438+ questions [5 ][4 ] = Question ("a reptile often mistaken for an amphibian" ,
439+ "what is a turtle?" , 500 )
440+
441+ # set a few as answered
463442 questions [3 ][3 ].answered = True
464443 questions [2 ][4 ].answered = True
465444
466-
467445 app = wx .App (0 )
468446 game = Game (catagories , questions )
469447 frame = MainFrame (None , game )
0 commit comments