-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodel.py
67 lines (52 loc) · 1.73 KB
/
model.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
STEVILO_DOVOLJENIH_NAPAK = 10
PRAVILNA_CRKA, PONOVLJENA_CRKA, NAPACNA_CRKA = '+', 'o', '-'
ZMAGA, PORAZ = 'w', 'x'
class Igra:
def __init__(self, geslo, crke=[]):
self.geslo = geslo
self.crke = crke
def napacne_crke(self):
return [c for c in self.crke if c.upper() not in self.geslo.upper()]
def pravilne_crke(self):
return [c for c in self.crke if c.upper() in self.geslo.upper()]
def stevilo_napak(self):
return len(self.napacne_crke())
def poraz(self):
return self.stevilo_napak() > STEVILO_DOVOLJENIH_NAPAK
def zmaga(self):
return not self.poraz() and len(set(self.pravilne_crke())) == len(set(self.geslo))
def pravilni_del_gesla(self):
pravilno = ''
for c in self.geslo.upper():
if c in self.crke:
pravilno += c
else:
pravilno += '_'
return pravilno
# return ''.join([c if c in self.crke else '_' for c in self.geslo.upper()])
def nepravilni_ugibi(self):
return ' '.join(self.napacne_crke())
def ugibaj(self, crka):
crka = crka.upper()
if crka in self.crke:
return PONOVLJENA_CRKA
elif crka in self.geslo.upper():
self.crke.append(crka)
if self.zmaga():
return ZMAGA
else:
return PRAVILNA_CRKA
else:
self.crke.append(crka)
if self.poraz():
return PORAZ
else:
return NAPACNA_CRKA
with open('besede.txt', encoding="utf-8") as f:
bazen_besed = f.read().split()
import random
def nova_igra():
geslo = random.choice(bazen_besed)
return Igra(geslo)
def fdjfdsk():
return(1+2)