Jump to content
  • Advertisement
Sign in to follow this  
bd36

Checkers Game Movement

This topic is 2310 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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;
};


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
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!