Sign in to follow this  
bd36

Checkers Game Movement

Recommended Posts

I just finished creating a simple tower defense in SFML for a class and now I want to make a checkers game in SFML to learn some more c++ with the possibility of exploring some AI concepts or networking once I get a 2 player local game working first. I started to develop the game and so far the board is created and you can move a piece to an empty spot on the board. I just now started to try and add in the rules for valid moves. I have required forward diagonal moves but I am looking at it and seems like there has to be a better way than my current approach. Once jumps and stuff are involved it looks like it will get way out of hand.

Here is the code for a move
[CODE]
bool Board::move()
{
if(movePiece1.getPiece() != getCurrentTurnPieceType())
{
printf("The Selected piece to move isnt yours.\n");
pieceBeingMoved = false;
return false;
}
if(movePiece2.getPiece() != GamePiece::NONE)
{
printf("The Selected new space isnt empty.\n");
pieceBeingMoved = false;
return false;
}
if(getCurrentTurnPieceType() == GamePiece::BLACK)
{
if(movePiece1.isKing() == false && movePiece2.getRow() <= movePiece1.getRow())
{
printf("must move forward\n");
pieceBeingMoved = false;
return false;
}
}
else {
if(movePiece1.isKing() == false && movePiece2.getRow() >= movePiece1.getRow())
{
printf("must move forward]\n");
pieceBeingMoved = false;
return false;
}
}
if(movePiece1.getCol() == movePiece2.getCol())
{
printf("go diagonal not up\n");
pieceBeingMoved = false;
return false;
}
gamePieces[movePiece1.getRow()][movePiece1.getCol()].changePieceKind(GamePiece::NONE);
gamePieces[movePiece2.getRow()][movePiece2.getCol()].changePieceKind(getCurrentTurnPieceType());
blackTurn = !blackTurn;
return true;
};
[/CODE]

Does anyone have an suggestions for a better way to go about doing this. I also feel like the way I am getting the move isn't the best. Now the player clicks to get the space to move from and then clicks again to for the destination then the move is evaluated and the cells that are selected are stored as variables in the board object.

Thanks

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this