@@ -26,13 +26,13 @@ discard block |
||
26 | 26 | /** @var BuktopuhaBotApi */ |
27 | 27 | private $botApi; |
28 | 28 | |
29 | - private $config; |
|
29 | + private $config; |
|
30 | 30 | |
31 | 31 | public function __construct(BuktopuhaBotApi $telegramBotApi, $config, EntityManagerInterface $entityManager) |
32 | 32 | { |
33 | 33 | $this->em = $entityManager; |
34 | 34 | $this->botApi = $telegramBotApi; |
35 | - $this->config = $config; |
|
35 | + $this->config = $config; |
|
36 | 36 | } |
37 | 37 | |
38 | 38 | |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | } |
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Checks if the answer is correct, and asks next question |
|
105 | - * |
|
106 | - * @param array $message |
|
107 | - */ |
|
103 | + /** |
|
104 | + * Checks if the answer is correct, and asks next question |
|
105 | + * |
|
106 | + * @param array $message |
|
107 | + */ |
|
108 | 108 | public function checkAnswer($message) |
109 | 109 | { |
110 | 110 | $game = $this->findGame($message); |
@@ -140,40 +140,40 @@ discard block |
||
140 | 140 | } else { |
141 | 141 | // Incorrect answer |
142 | 142 | $game->incorrectTries++; |
143 | - $hint = $game->hint; |
|
144 | - |
|
145 | - if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
146 | - //tell hint |
|
147 | - |
|
148 | - for($t = 0; $t< mb_strlen($hint);$t++) { |
|
149 | - if (mb_substr($hint,$t,1,'UTF-8') == '*') { |
|
150 | - if (rand(0,1)==1) { |
|
151 | - $hint = mb_substr($hint,0,$t,'UTF-8') |
|
152 | - .mb_substr($question->a1,$t,1) |
|
153 | - .mb_substr($hint,$t+1); |
|
154 | - break; |
|
155 | - } |
|
156 | - } |
|
157 | - } |
|
158 | - |
|
159 | - $game->hint = $hint; |
|
160 | - |
|
161 | - $this->botApi->sendMessage( |
|
162 | - $game->chatId, |
|
163 | - '<b>Hint</b>: '.$hint, |
|
164 | - 'html' |
|
165 | - ); |
|
166 | - |
|
167 | - } else { |
|
168 | - $this->botApi->sendMessage( |
|
169 | - $game->chatId, |
|
170 | - 'Noone answered, correct answer was: *'.$question->a1.'*', |
|
171 | - 'markdown' |
|
172 | - ); |
|
173 | - $this->em->persist($game); |
|
174 | - $this->em->flush(); |
|
175 | - $this->askQuestion($game); |
|
176 | - } |
|
143 | + $hint = $game->hint; |
|
144 | + |
|
145 | + if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
146 | + //tell hint |
|
147 | + |
|
148 | + for($t = 0; $t< mb_strlen($hint);$t++) { |
|
149 | + if (mb_substr($hint,$t,1,'UTF-8') == '*') { |
|
150 | + if (rand(0,1)==1) { |
|
151 | + $hint = mb_substr($hint,0,$t,'UTF-8') |
|
152 | + .mb_substr($question->a1,$t,1) |
|
153 | + .mb_substr($hint,$t+1); |
|
154 | + break; |
|
155 | + } |
|
156 | + } |
|
157 | + } |
|
158 | + |
|
159 | + $game->hint = $hint; |
|
160 | + |
|
161 | + $this->botApi->sendMessage( |
|
162 | + $game->chatId, |
|
163 | + '<b>Hint</b>: '.$hint, |
|
164 | + 'html' |
|
165 | + ); |
|
166 | + |
|
167 | + } else { |
|
168 | + $this->botApi->sendMessage( |
|
169 | + $game->chatId, |
|
170 | + 'Noone answered, correct answer was: *'.$question->a1.'*', |
|
171 | + 'markdown' |
|
172 | + ); |
|
173 | + $this->em->persist($game); |
|
174 | + $this->em->flush(); |
|
175 | + $this->askQuestion($game); |
|
176 | + } |
|
177 | 177 | |
178 | 178 | } |
179 | 179 | |
@@ -182,33 +182,33 @@ discard block |
||
182 | 182 | } |
183 | 183 | } |
184 | 184 | |
185 | - /** |
|
186 | - * Asks question in the game |
|
187 | - * |
|
188 | - * @param Game $game |
|
189 | - */ |
|
185 | + /** |
|
186 | + * Asks question in the game |
|
187 | + * |
|
188 | + * @param Game $game |
|
189 | + */ |
|
190 | 190 | |
191 | 191 | public function askQuestion(Game $game) |
192 | 192 | { |
193 | - $question = $this->getRandomQuestion(); |
|
193 | + $question = $this->getRandomQuestion(); |
|
194 | 194 | |
195 | - $question->played++; |
|
195 | + $question->played++; |
|
196 | 196 | |
197 | - $game->lastQuestion = $question->getId(); |
|
198 | - $game->lastQuestionTime = new \DateTime('now'); |
|
199 | - $game->incorrectTries = 0; |
|
200 | - $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
197 | + $game->lastQuestion = $question->getId(); |
|
198 | + $game->lastQuestionTime = new \DateTime('now'); |
|
199 | + $game->incorrectTries = 0; |
|
200 | + $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
201 | 201 | |
202 | - $this->em->persist($game); |
|
203 | - $this->em->persist($question); |
|
204 | - $this->em->flush(); |
|
202 | + $this->em->persist($game); |
|
203 | + $this->em->persist($question); |
|
204 | + $this->em->flush(); |
|
205 | 205 | |
206 | 206 | $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown'); |
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
210 | - * Gets random question from database |
|
211 | - * |
|
210 | + * Gets random question from database |
|
211 | + * |
|
212 | 212 | * @return Question |
213 | 213 | * @throws \Doctrine\ORM\NoResultException |
214 | 214 | * @throws \Doctrine\ORM\NonUniqueResultException |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | if (mb_strtoupper($question->a1, 'UTF-8') == mb_strtoupper($message['text'], 'UTF-8')) { |
122 | 122 | // Correct answer! |
123 | 123 | |
124 | - $user->setPoints($user->getPoints()+$question->price); |
|
124 | + $user->setPoints($user->getPoints() + $question->price); |
|
125 | 125 | $this->em->persist($user); |
126 | 126 | |
127 | 127 | $this->botApi->sendMessage( |
@@ -142,15 +142,15 @@ discard block |
||
142 | 142 | $game->incorrectTries++; |
143 | 143 | $hint = $game->hint; |
144 | 144 | |
145 | - if (mb_substr_count($hint,'*','UTF-8') >= mb_strlen($hint,'UTF-8')/2) { |
|
145 | + if (mb_substr_count($hint, '*', 'UTF-8') >= mb_strlen($hint, 'UTF-8') / 2) { |
|
146 | 146 | //tell hint |
147 | 147 | |
148 | - for($t = 0; $t< mb_strlen($hint);$t++) { |
|
149 | - if (mb_substr($hint,$t,1,'UTF-8') == '*') { |
|
150 | - if (rand(0,1)==1) { |
|
151 | - $hint = mb_substr($hint,0,$t,'UTF-8') |
|
152 | - .mb_substr($question->a1,$t,1) |
|
153 | - .mb_substr($hint,$t+1); |
|
148 | + for ($t = 0; $t < mb_strlen($hint); $t++) { |
|
149 | + if (mb_substr($hint, $t, 1, 'UTF-8') == '*') { |
|
150 | + if (rand(0, 1) == 1) { |
|
151 | + $hint = mb_substr($hint, 0, $t, 'UTF-8') |
|
152 | + .mb_substr($question->a1, $t, 1) |
|
153 | + .mb_substr($hint, $t + 1); |
|
154 | 154 | break; |
155 | 155 | } |
156 | 156 | } |
@@ -197,13 +197,13 @@ discard block |
||
197 | 197 | $game->lastQuestion = $question->getId(); |
198 | 198 | $game->lastQuestionTime = new \DateTime('now'); |
199 | 199 | $game->incorrectTries = 0; |
200 | - $game->hint = str_repeat('*',mb_strlen($question->a1,'UTF-8')); |
|
200 | + $game->hint = str_repeat('*', mb_strlen($question->a1, 'UTF-8')); |
|
201 | 201 | |
202 | 202 | $this->em->persist($game); |
203 | 203 | $this->em->persist($question); |
204 | 204 | $this->em->flush(); |
205 | 205 | |
206 | - $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1,'UTF-8').' letters)_', 'markdown'); |
|
206 | + $this->botApi->sendMessage($game->chatId, '*[question]* '.$question->text.' _('.mb_strlen($question->a1, 'UTF-8').' letters)_', 'markdown'); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |