Connect Four game...need help
I am making a connect four game in console mode.
I have just written the function that determines what to do when the current player drops their piece in a row.
Here's what it is:
Code:
void DropRow(int row)
{
char piece;
if (p1.myturn)
piece = 'Q';
else if (p2.myturn)
piece = 'X';
//check drop and win criteria
//not done yet
//Big stuff--------------
if (putvert < 0)
{
msg = 1;
putvert = 7;
StartGame();
}
if (board[putvert][row-1] != 'O')
{
putvert--;
DropRow(row);
}
if (board[putvert][row-1] == 'O')
{
board[putvert][row-1] = piece;
}
//End of big stuff-------
SwitchTurns();
putvert = 7;
}
Putvert is an int that determines where to place the piece vertically. Board[][] is the char that stores all the grid spots. There is a global struct named Player that stores 2 people's score, name, and turn status.
'O' is an empty grid space, 'Q' is player one's piece, and 'X' is player two's piece. The 'msg' you see being assigned to 1 is an instruction to a function that prints error messages. StartGame() is the main game loop, where it prints all the necessary stuff, the board, and lets they player input their row choice.
Now here is the bug. If a player drops a piece on top of a piece that exists, they get an extra turn. I have no idea why it is happening.
Here is the switch turn function:
Code:
void SwitchTurns()
{
if (p1.myturn == TRUE)
{
p1.myturn = FALSE;
p2.myturn = TRUE;
}
else if (p2.myturn == TRUE)
{
p1.myturn = TRUE;
p2.myturn = FALSE;
}
}
Anyone have any ideas?