-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (51 loc) · 1.37 KB
/
main.py
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
import os
import random
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
RESET = '\033[0m'
archivo = open("palabras.txt", "r")
a = archivo.read().split("\n")
word_split = list(a[random.randint(0,len(a) - 1)])
print(word_split)
historial = []
for trys in range(5):
os.system("clear")
print("Intentos restantes: {}".format(5 - trys))
for i in historial:
for j in i:
print(j, end="")
print()
input_word = list(input(RESET))
correct_positions = []
bad_positions = []
used = word_split.copy()
repetet = []
for i in range(5):
if word_split[i] == input_word[i]:
correct_positions.append(i)
used.remove(word_split[i])
for i in range(5):
if input_word[i] in word_split and i not in correct_positions and input_word[i] in used:
bad_positions.append(i)
used.remove(input_word[i])
colored_result = []
for i in range(5):
if i in correct_positions:
colored_result.append("{}{}".format(GREEN, input_word[i]))
elif i in bad_positions:
colored_result.append("{}{}".format(YELLOW, input_word[i]))
else:
colored_result.append("{}{}".format(RED, input_word[i]))
historial.append(colored_result)
if input_word == word_split:
break
if input_word == word_split:
os.system("clear")
print("Has acertado")
for i in historial:
for j in i:
print(j, end="")
print()
else:
print("Has perdido, la palabra era '{}'".format("".join(word_split)))