forked from chrys-elrak/words-mini-game
-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.py
119 lines (109 loc) · 4.44 KB
/
launch.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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# coding:utf-8
import random
import os
import termcolor
from functions import *
# 22740 words
"""
* Author : Chrys Rakotonimanana
* Date : Tue Oct 15 2019, 1:30 PM
* Version : 1.0.0
* Title : 22740 words
* Description : Je me suis inspiré du jeux Word Charm, nottament sur mobile. Je voulais crée un jeux similaires, mais sur le terminal donc sans GUI.
"""
data = get_lang()
player_name = input(termcolor.colored('Entrer votre nom: ', 'yellow')).lower().strip()
continuer = None
score = get_score(player_name)
# main program
while True:
x_word_list, x_word_str = choose_and_shuffle(
data) # choose one and shuffle data
# get all possible words with the main words choosen before
res, text = find_like(str(x_word_list), data)
# variables
to_find, w_finded, b_finded, n = [], [], [], random.randrange(2, 5)
# choose random words to find
# all others will be a bonus words
while len(to_find) < n:
random.shuffle(res)
choosen = random.choice(res)
if choosen not in to_find:
to_find.append(choosen)
res.remove(choosen)
# while user doesn't find all words
clear()
while len(to_find) > 0:
txt = ' · '.join(x_word_list)
# -------------------------------------------------
print('-' * os.get_terminal_size().columns, end='')
print(
f"{termcolor.colored('MOT MELANGER', 'yellow', attrs=['underline'])} : {termcolor.colored((txt).upper(), 'cyan',)}")
print(
f"{termcolor.colored('SCORE', 'yellow', attrs=['underline'])} : {score}")
print(
f"{termcolor.colored('NOMBRE DE MOT A TROUVER', 'yellow', attrs=['underline'])} : {len(to_find)}")
if len(b_finded):
print(
f"{termcolor.colored('BONUS TROUVER', 'yellow', attrs=['underline'])} : {b_finded}")
if len(w_finded):
print(
f"{termcolor.colored('MOT TROUVER', 'yellow', attrs=['underline'])} : {termcolor.colored(w_finded, attrs=['bold'])}")
print('-' * os.get_terminal_size().columns, end='\n')
# -------------------------------------------------
print(
f'''Entrer le mot qui vous vient à l'ésprit, Tapez :\n{termcolor.colored("*", 'red')} pour actualiser\n{termcolor.colored("?", 'yellow')} pour passer\n{termcolor.colored("!", 'green')} pour quitter'''
)
user_res = ((input('> ')).lower()).strip()
clear()
if user_res == '':
print('Veuillez au moins entrer quelque chose !')
# SHUFFLE
elif user_res == '*':
print(termcolor.colored('Acualisation ...', 'cyan'))
random.shuffle(x_word_list)
# QUIT
elif user_res == '!':
print('Fermeture du programme ...')
continuer = 'non'
break
# HELP
elif user_res == '?':
if (score - 1) > 0:
print(f'{termcolor.colored("?", "yellow")} Vous ête perdu')
show = random.choice(to_find)
w_finded.append(show)
to_find.remove(show)
score -= 1
print(f"VOILA : {termcolor.colored(show, attrs=['bold'])}")
else:
print(
'Désolé, Je ne peux pas vous aider, vous n\'avez pas assez de score :( ')
# BONUS
elif user_res in res and user_res not in to_find and user_res not in b_finded:
b_finded.append(user_res)
res.remove(user_res)
score += .5
print(termcolor.colored('BONUS', 'green'))
# TRUTH
elif user_res in to_find and user_res not in w_finded:
w_finded.append(user_res)
to_find.remove(user_res)
score += round(len(user_res) / 2)
print(termcolor.colored('VRAIE', 'green'))
# WRONG
else:
if user_res in w_finded or user_res in b_finded:
print(termcolor.colored('Déjà tapez', 'magenta'))
else:
print(termcolor.colored('FAUX', 'red'))
if continuer is None:
continuer = input(
'Voulez vous continuer ? (Oui / Non) : ').lower().strip()
if continuer == 'non':
break
else:
continuer = None
else:
break
save_prompt(score, player_name)