[cairo-commit] cairo-demo/python ChangeLog,1.3,1.4 hangman.py,1.3,1.4

Kevin Worth commit at pdx.freedesktop.org
Mon Aug 15 11:12:59 PDT 2005


Committed by: kevin

Update of /cvs/cairo/cairo-demo/python
In directory pdx:/tmp/cvs-serv23360

Modified Files:
	ChangeLog hangman.py 
Log Message:
added dictionary list, 1st attempt to show secret word(not working), imported randint in order to randomly choose secret word.

Index: ChangeLog
===================================================================
RCS file: /cvs/cairo/cairo-demo/python/ChangeLog,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** ChangeLog	14 Feb 2004 22:32:38 -0000	1.3
--- ChangeLog	14 Feb 2004 22:44:45 -0000	1.4
***************
*** 1,2 ****
--- 1,6 ----
+ 2004-02-14  Kevin  <kevin at ender>
+ 
+ 	* hangman.py: added dictionary list, 1st attempt to show secret word(not working), imported randint in order to randomly pick work.
+ 
  2004-02-14  Carl Worth  <cworth at isi.edu>
  

Index: hangman.py
===================================================================
RCS file: /cvs/cairo/cairo-demo/python/hangman.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** hangman.py	14 Feb 2004 22:32:38 -0000	1.3
--- hangman.py	14 Feb 2004 22:44:45 -0000	1.4
***************
*** 30,38 ****
  import cairo.gtk
  from math import pi
  
  letters_guessed = ""
  letters_guessed_right = ""
  letters_guessed_wrong = ""
! word_chosen = "House"
  
  def guess_letter(widget, event):
--- 30,46 ----
  import cairo.gtk
  from math import pi
+ from whrandom import randint
  
  letters_guessed = ""
  letters_guessed_right = ""
  letters_guessed_wrong = ""
! 
! body_parts = 6
! words = ['cairo', 'graphics', 'pencil', 'keyboard', 'science', 'ricochet', 'flood', 'president', 'sanity']
! 
! idxRandom = randint(0, len(words) -1) 
! word_chosen = words[idxRandom]
! 
! 
  
  def guess_letter(widget, event):
***************
*** 63,70 ****
      cr.scale(size / 150.0, size / 160.0)
  
      # Draw Letters Guessed
  
      cr.scale_font(10)
!     cr.move_to(0, 150)
      cr.set_rgb_color(0, 0, 0)
      cr.show_text(letters_guessed)
--- 71,96 ----
      cr.scale(size / 150.0, size / 160.0)
  
+     def man_hung():
+         if len(letters_guessed_wrong) == body_parts:
+             return True
+         else:
+             return False
+ 
+     for idxLetter in range(len(__main__.word_chosen)):
+         if __main__.word_chosen[idxLetter].lower() in letters_guessed_right or man_hung():
+             if idxLetter == 0:
+                 cr.move_to(0, 150)
+                 cr.show_text(__main__.word_chosen[idxLetter].upper())
+             else:
+                 cr.move_to(idxLetter * 15, 150)
+                 cr.show_text(__main__.word_chosen[idxLetter].lower())
+         else:
+             cr.move_to(idxLetter * 15, 150)
+             cr.show_text('_')
+             
      # Draw Letters Guessed
  
      cr.scale_font(10)
!     cr.move_to(0, 160)
      cr.set_rgb_color(0, 0, 0)
      cr.show_text(letters_guessed)





More information about the cairo-commit mailing list