-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
49 lines (38 loc) · 1.25 KB
/
game.py
File metadata and controls
49 lines (38 loc) · 1.25 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
from datetime import date, timedelta
import random
from sessions import Sessions
from word import Word
from wordRepository import WordRepository
class Game:
wordRepository = WordRepository()
sessions = Sessions()
maxTries = 6
def getWordById(self, id):
return self.wordRepository.getWordById(id)
def checkValidWord(self, word):
return self.wordRepository.checkValidWord(word)
def writeWords(self, words):
return self.wordRepository.writeWords(words)
def getRandomWord(self):
return self.wordRepository.getRandomWord()
@staticmethod
def checkWord(word, input):
out = ["⬛", "⬛", "⬛", "⬛", "⬛"]
placeholder = "_"
won = word == input
input = list(input)
word = list(word)
for k, char in enumerate(input):
if char == word[k]:
out[k] = "🟩"
input[k] = placeholder
word[k] = placeholder
for k, char in enumerate(input):
if char == placeholder:
continue
if char in word:
word[word.index(char)] = placeholder
out[k] = "🟨"
return won, "".join(out)
def getMaxTries(self):
return self.maxTries