-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (90 loc) · 3.27 KB
/
main.py
File metadata and controls
107 lines (90 loc) · 3.27 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
106
107
# -*- coding: utf-8 -*-
import copy
import time
from chest_minigame import ChestMinigame
from database import Database
from dictionary_tree import TreeCreator
from game_control import GameControl
from game_state_detector import GameStateDetector
from text_recognition import TextRecognition
class MainMan:
def __init__(self):
self.state = None
self.gsd = GameStateDetector()
self.tr = TextRecognition()
self.d = Database()
self.gc = GameControl()
self.tc = TreeCreator()
self.ch = ChestMinigame()
def main_loop(self):
while True:
print('Detecting states')
self.state = self.gsd.get_game_state()
print(self.state)
self.monster_battle()
self.shopping_time()
self.chest_hangman_minigame()
self.chest_hangman_prize()
time.sleep(3)
def is_current_state(self, state_name):
return self.state is state_name
def chest_hangman_minigame(self):
if not self.is_current_state(self.gsd.STATE_CHEST_MINIGAME):
return
self.ch.determine_word_length()
while True:
if self.gsd.get_game_state() == self.gsd.STATE_CHEST_MINIGAME_PRIZE:
self.chest_hangman_prize()
self.ch.try_input()
def chest_hangman_prize(self):
self.ch.clear_minigame()
if not self.is_current_state(self.gsd.STATE_CHEST_MINIGAME_PRIZE):
return
# TODO add science
self.gc.chest_reward_prize(3)
def shopping_time(self):
if not self.is_current_state(self.gsd.STATE_SHOP):
return
# todo
self.gc.exit_shop()
def monster_battle(self):
if not self.is_current_state(self.gsd.STATE_MONSTER_BATTLE):
return
self.tr.recognize_tiles()
clean_word_map = self.tr.get_letters_map()
word_map = copy.deepcopy(clean_word_map)
# print('Found letters: {}'.format(self.tr.get_letters()))
first_word = self.tc.search(self.tr.get_letters())
print('search finish: {}'.format(first_word))
while True:
try:
word = self.tc.get_next_word()
except KeyError:
print('End of dictionary - no word is correct')
print('Problem with recognising')
print('Activate madman enter mode')
raise Exception('Madman mode required')
# TODO use potion method
# TODO use purify method
if word is None:
print('No word - shuffling')
self.gc.shuffle_tiles()
return
# print(word_map)
for letter in word:
letter_dict = word_map[letter].pop()
self.gc.click_letter(letter_dict)
print('writting letter: {}'.format(letter))
if self.gsd.ms_has_correct_word():
print('correct word')
self.gc.accept_word()
self.gc.animation_break()
return
else:
print('cancelling word')
word_map = copy.deepcopy(clean_word_map)
self.gc.cancel_word()
if __name__ == '__main__':
print('Letter Quest')
mm = MainMan()
mm.main_loop()