<s> from pyjamas . ui . VerticalPanel import VerticalPanel <EOL> from pyjamas . ui . HorizontalPanel import HorizontalPanel <EOL> from pyjamas . ui . Composite import Composite <EOL> from pyjamas . ui . Button import Button <EOL> from pyjamas . ui . HTML import HTML <EOL> from pyjamas . ui . RadioButton import RadioButton <EOL> from pyjamas . Canvas . GWTCanvas import GWTCanvas <EOL> from pyjamas import Window <EOL> import math <EOL> import random <EOL> import string <EOL> import Wordlist_20 <EOL> import Wordlist_15 <EOL> import Wordlist_10 <EOL> import Wordlist_5 <EOL> class HangManWidget ( Composite ) : <EOL> def __init__ ( self ) : <EOL> Composite . __init__ ( self ) <EOL> self . guesses = <NUM_LIT:0> <EOL> self . score = <NUM_LIT:0> <EOL> self . level = <NUM_LIT:5> <EOL> self . answer = '<STR_LIT>' <EOL> self . blanks = '<STR_LIT>' <EOL> self . vp_main = VerticalPanel ( ) <EOL> self . vp_main . setSpacing ( <NUM_LIT:4> ) <EOL> self . hangdude = HangDude ( ) <EOL> self . cmdNew = Button ( "<STR_LIT>" , self ) <EOL> self . radLevel5 = RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . radLevel5 . setChecked ( True ) <EOL> self . radLevel10 = RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . radLevel15 = RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . radLevel20 = RadioButton ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . radLevel5 . addClickListener ( self . onRadioSelect ) <EOL> self . radLevel10 . addClickListener ( self . onRadioSelect ) <EOL> self . radLevel15 . addClickListener ( self . onRadioSelect ) <EOL> self . radLevel20 . addClickListener ( self . onRadioSelect ) <EOL> self . rad_hp = HorizontalPanel ( ) <EOL> self . rad_hp . setSpacing ( <NUM_LIT:4> ) <EOL> self . rad_hp . add ( self . radLevel5 ) <EOL> self . rad_hp . add ( self . radLevel10 ) <EOL> self . rad_hp . add ( self . radLevel15 ) <EOL> self . rad_hp . add ( self . radLevel20 ) <EOL> self . rad_hp . add ( self . cmdNew ) <EOL> self . puzzlestring = HTML ( ) <EOL> self . key_widgets = [ ] <EOL> for i in range ( len ( string . uppercase ) ) : <EOL> self . key_widgets . append ( Button ( string . uppercase [ i : i + <NUM_LIT:1> ] , self ) ) <EOL> self . toprow = HorizontalPanel ( ) <EOL> self . midrow = HorizontalPanel ( ) <EOL> self . botrow = HorizontalPanel ( ) <EOL> for i in range ( len ( self . key_widgets ) ) : <EOL> if i <= <NUM_LIT:7> : <EOL> self . toprow . add ( self . key_widgets [ i ] ) <EOL> elif i <= <NUM_LIT:16> : <EOL> self . midrow . add ( self . key_widgets [ i ] ) <EOL> else : <EOL> self . botrow . add ( self . key_widgets [ i ] ) <EOL> self . vp_main . add ( self . hangdude ) <EOL> self . vp_main . add ( self . puzzlestring ) <EOL> self . vp_main . add ( self . toprow ) <EOL> self . vp_main . add ( self . midrow ) <EOL> self . vp_main . add ( self . botrow ) <EOL> self . vp_main . add ( self . rad_hp ) <EOL> for i in range ( <NUM_LIT:1> , <NUM_LIT:12> ) : <EOL> self . hangdude . draw ( i ) <EOL> self . setWidget ( self . vp_main ) <EOL> def onClick ( self , sender ) : <EOL> found = False <EOL> if sender == self . cmdNew : <EOL> self . blanks = '<STR_LIT>' <EOL> self . hangdude . clear ( ) <EOL> self . guesses = <NUM_LIT:0> <EOL> self . score = <NUM_LIT:0> <EOL> for i in range ( len ( self . key_widgets ) ) : <EOL> self . key_widgets [ i ] . setEnabled ( True ) <EOL> if self . level == <NUM_LIT:5> : <EOL> words = Wordlist_5 . words <EOL> elif self . level == <NUM_LIT:10> : <EOL> words = Wordlist_10 . words <EOL> elif self . level == <NUM_LIT:15> : <EOL> words = Wordlist_15 . words <EOL> elif self . level == <NUM_LIT:20> : <EOL> words = Wordlist_20 . words <EOL> g = random . Random ( ) <EOL> r = int ( g . random ( ) * len ( words ) ) <EOL> self . answer = words [ r ] . upper ( ) <EOL> for i in range ( len ( self . answer ) ) : <EOL> if self . answer [ i ] == '<STR_LIT:U+0020>' : <EOL> self . blanks += '<STR_LIT:U+0020>' <EOL> else : <EOL> self . blanks += '<STR_LIT>' <EOL> self . puzzlestring . setHTML ( self . blanks ) <EOL> else : <EOL> guess_letter = sender . getText ( ) <EOL> sender . setEnabled ( False ) <EOL> for i in range ( len ( self . answer ) ) : <EOL> if self . answer [ i : i + <NUM_LIT:1> ] == guess_letter : <EOL> j = i + <NUM_LIT:1> <EOL> self . blanks = self . blanks [ <NUM_LIT:0> : ( j * <NUM_LIT:2> ) - <NUM_LIT:2> ] + guess_letter + '<STR_LIT:U+0020>' + self . blanks [ j * <NUM_LIT:2> : ] <EOL> found = True <EOL> self . score += <NUM_LIT:1> <EOL> self . puzzlestring . setHTML ( self . blanks ) <EOL> if not found : <EOL> self . guesses += <NUM_LIT:1> <EOL> self . hangdude . draw ( self . guesses ) <EOL> if self . guesses >= <NUM_LIT:11> : <EOL> Window . alert ( "<STR_LIT>" + self . answer ) <EOL> else : <EOL> if self . score >= len ( self . answer ) : <EOL> Window . alert ( "<STR_LIT>" ) <EOL> def onRadioSelect ( self , sender , keyCode = None , modifiers = None ) : <EOL> if sender == self . radLevel5 : <EOL> self . level = <NUM_LIT:5> <EOL> elif sender == self . radLevel10 : <EOL> self . level = <NUM_LIT:10> <EOL> elif sender == self . radLevel15 : <EOL> self . level = <NUM_LIT:15> <EOL> elif sender == self . radLevel20 : <EOL> self . level = <NUM_LIT:20> <EOL> class HangDude ( HorizontalPanel ) : <EOL> def __init__ ( self ) : <EOL> HorizontalPanel . __init__ ( self ) <EOL> self . context = GWTCanvas ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) <EOL> self . context . addStyleName ( "<STR_LIT>" ) <EOL> self . add ( self . context ) <EOL> def clear ( self ) : <EOL> self . context . clear ( ) <EOL> def draw ( self , guesses ) : <EOL> self . context . fillStyle = '<STR_LIT>' <EOL> self . context . lineWidth = <NUM_LIT:2> <EOL> if guesses == <NUM_LIT:1> : <EOL> self . context . fillRect ( <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:200> , <NUM_LIT:10> ) <EOL> elif guesses == <NUM_LIT:2> : <EOL> self . context . fillRect ( <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:10> , <NUM_LIT> ) <EOL> elif guesses == <NUM_LIT:3> : <EOL> self . context . fillRect ( <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:10> ) <EOL> elif guesses == <NUM_LIT:4> : <EOL> self . context . saveContext ( ) <EOL> self . context . translate ( <NUM_LIT> , <NUM_LIT:30> ) <EOL> self . context . rotate ( <NUM_LIT> * math . pi / <NUM_LIT> ) <EOL> self . context . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:50> , <NUM_LIT:10> ) <EOL> self . context . restoreContext ( ) <EOL> elif guesses == <NUM_LIT:5> : <EOL> self . context . fillRect ( <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:10> , <NUM_LIT:50> ) <EOL> elif guesses == <NUM_LIT:6> : <EOL> self . context . beginPath ( ) <EOL> self . context . arc ( <NUM_LIT> , <NUM_LIT:100> , <NUM_LIT:30> , <NUM_LIT:0> , math . pi * <NUM_LIT:2> , True ) <EOL> self . context . closePath ( ) <EOL> self . context . stroke ( ) <EOL> elif guesses == <NUM_LIT:7> : <EOL> self . context . fillRect ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) <EOL> elif guesses == <NUM_LIT:8> : <EOL> self . context . saveContext ( ) <EOL> self . context . translate ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . context . rotate ( <NUM_LIT> * math . pi / <NUM_LIT> ) <EOL> self . context . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:50> , <NUM_LIT:2> ) <EOL> self . context . restoreContext ( ) <EOL> elif guesses == <NUM_LIT:9> : <EOL> self . context . saveContext ( ) <EOL> self . context . translate ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . context . rotate ( <NUM_LIT> * math . pi / <NUM_LIT> ) <EOL> self . context . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:50> , <NUM_LIT:2> ) <EOL> self . context . restoreContext ( ) <EOL> elif guesses == <NUM_LIT:10> : <EOL> self . context . saveContext ( ) <EOL> self . context . translate ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . context . rotate ( <NUM_LIT> * math . pi / <NUM_LIT> ) <EOL> self . context . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) <EOL> self . context . restoreContext ( ) <EOL> elif guesses == <NUM_LIT:11> : <EOL> self . context . saveContext ( ) <EOL> self . context . translate ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . context . rotate ( <NUM_LIT> * math . pi / <NUM_LIT> ) <EOL> self . context . fillRect ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) <EOL> self . context . restoreContext ( ) <EOL> self . context . restoreContext ( ) </s>
