44 */
55
66#include " field.hpp"
7- #include " menu/selectingMenu.hpp"
87
98
109const float Field::cellSide = 100 ;
@@ -63,6 +62,10 @@ GameState Field::getState() const {
6362 return gameState;
6463}
6564
65+ bool Field::isStarted () const {
66+ return count > 0 ;
67+ }
68+
6669const char * Field::getSaveTime () const {
6770 // Get time
6871 SDL_DateTime time;
@@ -132,7 +135,6 @@ bool Field::clickSingle(SDL_Point p) {
132135 if (gameState < GameState::CurrentWin) {
133136 AImove ();
134137 }
135- checkEnd ();
136138 return true ;
137139 }
138140 return false ;
@@ -158,13 +160,8 @@ bool Field::clickTwo(SDL_Point p) {
158160 }
159161 count++;
160162
161- // Making sound
162- sounds.play (Sounds::Turn);
163- music.startFromCurrent (Music::MainCombat);
164-
165163 // Checking for win
166164 gameState = checkWin (p);
167- checkEnd ();
168165 return true ;
169166 }
170167 return false ;
@@ -189,45 +186,33 @@ bool Field::clickMultiplayerCurrent(SDL_Point p) {
189186 }
190187 count++;
191188
192- // Making sound
193- sounds.play (Sounds::Turn);
194- music.startFromCurrent (Music::MainCombat);
195-
196189 // Checking for win
197190 gameState = checkWin (p);
198- checkEnd ();
199191 return true ;
200192 }
201193 return false ;
202194}
203195
204196void Field::clickMultiplayerOpponent (SDL_Point p) {
205- if (gameState == GameState::OpponentPlay) {
206- switch (gameState) {
207- case GameState::CurrentPlay:
208- setCell (p, Cell::Current);
209- gameState = GameState::OpponentPlay;
210- break ;
211-
212- case GameState::OpponentPlay:
213- setCell (p, Cell::Opponent);
214- gameState = GameState::CurrentPlay;
215- break ;
216-
217- default :
218- break ;
219- }
220- count++;
197+ switch (gameState) {
198+ case GameState::CurrentPlay:
199+ setCell (p, Cell::Current);
200+ gameState = GameState::OpponentPlay;
201+ break ;
221202
222- // Making sound
223- sounds.play (Sounds::Turn);
224- music.startFromCurrent (Music::MainCombat);
203+ case GameState::OpponentPlay:
204+ setCell (p, Cell::Opponent);
205+ gameState = GameState::CurrentPlay;
206+ break ;
225207
226- // Checking for win
227- gameState = checkWin (p);
228- checkEnd ();
229- return ;
208+ default :
209+ break ;
230210 }
211+ count++;
212+
213+ // Checking for win
214+ gameState = checkWin (p);
215+ return ;
231216}
232217
233218// Recursivly solve, where cell need to be placed
@@ -320,7 +305,7 @@ GameState Field::checkWin(SDL_Point p) {
320305 }
321306
322307 if (state) {
323- return (GameState)(state+2 );
308+ return (GameState)(state+1 );
324309 }
325310 }
326311
@@ -334,7 +319,7 @@ GameState Field::checkWin(SDL_Point p) {
334319 }
335320
336321 if (state) {
337- return (GameState)(state+2 );
322+ return (GameState)(state+1 );
338323 }
339324 }
340325
@@ -346,7 +331,7 @@ GameState Field::checkWin(SDL_Point p) {
346331 state &= (Uint8)data[t + (p.y + t - p.x ) * width];
347332 }
348333 if (state) {
349- return (GameState)(state+2 );
334+ return (GameState)(state+1 );
350335 }
351336 }
352337
@@ -362,7 +347,7 @@ GameState Field::checkWin(SDL_Point p) {
362347 pos -= (width-1 );
363348 }
364349 if (state) {
365- return (GameState)(state+2 );
350+ return (GameState)(state+1 );
366351 }
367352 }
368353 } else {
@@ -376,7 +361,7 @@ GameState Field::checkWin(SDL_Point p) {
376361 pos -= (width-1 );
377362 }
378363 if (state) {
379- return (GameState)(state+2 );
364+ return (GameState)(state+1 );
380365 }
381366 }
382367 }
@@ -387,30 +372,6 @@ GameState Field::checkWin(SDL_Point p) {
387372 return gameState;
388373}
389374
390- void Field::checkEnd () {
391- switch (gameState) {
392- case GameState::CurrentWin:
393- sounds.play (Sounds::Loose);
394- logAdditional (" Opponent win" );
395- break ;
396-
397- case GameState::OpponentWin:
398- sounds.play (Sounds::Win);
399- logAdditional (" Current win" );
400- break ;
401-
402- case GameState::NobodyWin:
403- sounds.play (Sounds::Loose);
404- logAdditional (" Nobody win" );
405- break ;
406-
407- default :
408- return ;
409- }
410- // Setting start menu for next game
411- SelectingMenu::open ();
412- }
413-
414375void Field::blit (const Window& window) const {
415376 // Rendering cells with their background
416377 for (int y=0 ; y < width; ++y) {
0 commit comments