-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
105 lines (90 loc) · 3.1 KB
/
hangman.py
File metadata and controls
105 lines (90 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import sys
import random
def wordfile():
path = '/home/acrooxy/Desktop/Project2/wordsHangman.txt'
refi = open(path, 'r')
a = []
a = refi.read().split('\n')
word = a[random.randrange(len(a))]
print(a)
refi.close()
return word
# wordfile()
def difficulty():
print("Choose level difficulty:\n1. Easy (5 mistakes)\n2. Midium (3 mistakes)\n3. Hard (1 mistake)")
level = int(input())
if level == 1:
return 5
elif level == 2:
return 3
elif level == 3:
return 1
else:
print("You choosen wrong number.")
difficulty()
used_letters = []
user_words = []
def find_indexes(word, letter): # self indexes moze pomoze
indexes = [] # zresetowac indexes?
for index, letter_in_word in enumerate(word):
if letter == letter_in_word:
indexes.append(index)
## if runned secound time restart function, but how ?
# k a m i l a # Działa to w ten sposob
# 0 1 2 3 4 5
return indexes
def show_state_of_game():
print()
print(user_words)
print("Used Letters:", used_letters)
print()
def word_init():
word = wordfile()
for _ in word:
user_words.append("_")
class main_hangman():
no_of_tries = difficulty()
word = wordfile()
word_init()
print(word)
while no_of_tries != 0:
print("Tries remaining:", no_of_tries)
letter = input("Choose a letter: ")
used_letters.append(letter)
found_indexes = find_indexes(word, letter)
if len(found_indexes) == 0:
print("Unfortunatelly that letter does not exist in the word.")
no_of_tries -= 1
print(word)
if no_of_tries == 0:
print("Game Over!")
# sys.exit(0)
else:
for index in found_indexes:
user_words[index] = letter
if "".join(user_words) == word: # Zamienia obraz listy na string
print("YEA, This is that word!")
if input("Do you want to play again? yes/no: ") == 'yes':
user_words.clear()
used_letters.clear()
# used_letters =[]
no_of_tries = difficulty()
word_init()
find_indexes.
# find_indexes(word, letter)
# letter =
# find_indexes.__init__()# zresetowac indexes?
# continue
else:
print("See you next time!")
exit()
show_state_of_game()
# main_hangman()
### Gra wyłącza sie na koniec
# Własciwa walidacja, co podaje uzytkownik, czy litera, czy nie kilka liter na raz, badz cyfry ( try:)
# Nie mozna pozwolic uzytkownikowi wpisywac drugi raz tej samej litery
## Lista słow do odgadniecia zamiast zmiennej words
## slowa z zewnetrznego API lub pliku
# jesli slowo bylo w grze nie pozwalamy aby ponownie sie wybralo
### restart gry po wylaczeniu czy chcesz zagrac jeszcze raz
### sztywna liczba szans, poziomy trudnosci z 3/5 i 1 szansa