void GameScreen::refreshAll() { clearAll(); if(!m_game.hasStarted()) m_placementUI.resetAvailability(); for(int i = 0; i < BOARD_SIZE; ++i) { for(int j = 0; j < BOARD_SIZE; ++j) { sf::Vector2i s(i,j); PiecePtr p = m_game[toSquare(s)]; if (p != nullptr) { m_pieces[p] = PieceSprite(p); m_pieces[p].moveOnSquare(s); m_pieces[p].freeze(m_game.isFrozen(toSquare(s))); //if the piece is frozen, show it if(!m_game.hasStarted() && (p->getColor() == m_game.getActivePlayer())) //if in placement phase, and if the piece belongs to the current player updatePieceAvailability(p->getType());//updating the availability in placement UI } } } updateNbMoves(); if(!m_game.hasStarted()) m_placementUI.setPlayer(m_game.getActivePlayer()); }
bool GameScreen::select(sf::Vector2i s) { if(m_selectedPiece != NULL_SQUARE) //if a piece is selected { if(m_selectedTarget != NULL_SQUARE) //if an enemy piece is selected { if(!m_highlighter.isHighlighted(s)) //square isn't selectable unselect(); else //square is selectable { bool res = m_game.displace(toSquare(m_selectedPiece), toSquare(s), toSquare(m_selectedTarget), false); unselect(); return res; } } else //no enemy piece selected { if(!m_highlighter.isHighlighted(s)) //square isn't selectable unselect(); else //square is selectable { PiecePtr p = m_game[toSquare(s)]; if (p == nullptr) //no piece here { bool res = m_game.move(toSquare(m_selectedPiece), toSquare(s), false); unselect(); return res; } else selectTarget(s); } } } else //no piece is selected { PiecePtr p = m_game[toSquare(s)]; if (p != nullptr && p->getColor() == m_game.getActivePlayer()) //there is a piece and it can be selected selectPiece(s); } return false; }