Esempio n. 1
0
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());
}
Esempio n. 2
0
void GameScreen::place(sf::Vector2i s)
{
	if(BoardAlignedSprite::isOnBoard(s)) //there is a piece to be placed, and the square to place it in is valid
	{
		PiecePtr p = m_game[toSquare(s)];
		PieceType oldPieceType = NB_PIECES;
		if (p != nullptr)
			oldPieceType = p->getType();
		remove(s); //removing any piece that would happen to be here
		if(m_game.place(m_selectedType, toSquare(s))) //if the placement was a success
		{
			m_pieces[m_game[toSquare(s)]] = PieceSprite(m_game[toSquare(s)]);
			m_pieces[m_game[toSquare(s)]].moveOnSquare(s);
			updatePieceAvailability(m_selectedType);//updating the availability in placement UI
			if(oldPieceType != NB_PIECES)
				updatePieceAvailability(oldPieceType); //id a piece was replaced, update its availability as well
		}
		else if (oldPieceType != NB_PIECES) //the placement has failed : we put back the piece that was there before
		{
			m_game.place(oldPieceType, toSquare(s));
			m_pieces[m_game[toSquare(s)]] = PieceSprite(m_game[toSquare(s)]);
			m_pieces[m_game[toSquare(s)]].moveOnSquare(s);
		}
	}
}
Esempio n. 3
0
void Board::makeMove(Move move)
{
	PiecePtr tmp = _squares[move.src].getPiece();
	if(tmp->getType() == POWN){
		tmp->moved();
	}
	_squares[move.dest].putPiece(tmp);
	_squares[move.src].gonePiece();
}