~yacinechaouche/+junk/BZR

« back to all changes in this revision

Viewing changes to CODE/FB/hang.py

  • Committer: yacinechaouche at yahoo
  • Date: 2015-01-14 22:23:03 UTC
  • Revision ID: yacinechaouche@yahoo.com-20150114222303-6gbtqqxii717vyka
Ajout de CODE et PROD. Il faudra ensuite ajouter ce qu'il y avait dan TMP

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import random
 
2
 
 
3
class HangMan(object):
 
4
  def __init__(self, word,lives):
 
5
    self.word = word
 
6
    self.lives = lives
 
7
        
 
8
#The playGame Function 
 
9
def playGame(word,lives):  
 
10
    hm = HangMan(word, lives)
 
11
 
 
12
    while hm.livesLeft()>0 and hm.guessed() != 'successfully guessed':
 
13
        letter = input('Guess a letter: ')
 
14
        if letter.isupper() == True:
 
15
            hm.update(letter)
 
16
        elif letter.isupper() == False :
 
17
            print('Uppercase Only!!!')
 
18
            
 
19
        print(hm.__str__())
 
20
 
 
21
    print(hm.guessed())
 
22
    if hm.guessed() == 'Not Sucessful':
 
23
        print('You have no lives left - you have been hung!\n The word was', word)
 
24
    else: print('Well done - you have guessed the word correctly!!!')
 
25
 
 
26
 
 
27
words = ("animal", "chickens", "hen", "home")
 
28
 
 
29
 
 
30
#store random words as rand
 
31
rand = random.choice(words)
 
32
 
 
33
print('Select an option\n 1. Easy\n 2. Intermediate\n 3. Hard')
 
34
 
 
35
level = int(input('Select level: '))
 
36
 
 
37
if level == 1:
 
38
    lives =  10
 
39
    word = rand
 
40
    playGame(word,lives)
 
41
elif level == 2:
 
42
    lives = 7
 
43
    word = rand
 
44
    playGame(word,lives)
 
45
elif level == 3:
 
46
    lives = 5
 
47
    word = rand
 
48
    playGame(word,lives)
 
49
else:
 
50
    print('Wrong option')
 
51