Hi,
I am new to C++ and am trying my hand at programming a Connect Four game.
I've been trying my best to find what's gone wrong but after a good look I've come up result less. There are 42 spots where the "markers" go and each spot has a variable declared for it. One's represent the markers of Player 1 and two's represent the markers of Player 2.
http://i49.tinypic.com/de5qg1.jpg
I input Player 1's first turn, it goes in correctly and displays.
http://tinypic.com/r/1zfsbj6/6
Then I input Player 2's first turn, it also goes in without a problem.
http://tinypic.com/r/fx9vs3/6
Then comes Player 1's second turn; despite choosing only the fifth column, a 1 is place in the desired location and an extra 1 is place over the previous column I selected for Player 2's turn.
This happens over and over again with player 1 placing a marker in his desired column and one in the column that player 2 previously chose giving poor player 2 not a chance to win.
This is the main display for the game which I use for both players, changing a few things of course to differentiate from P1 and P2.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
cout << endl;
cout << "Turn" << " "<< TurnCounter << endl;
cout << endl<< "Player 1, place your marker!";
cout << endl;
cout << endl;
cout << "1 2 3 4 5 6 7" << endl;
cout << "_____________" << endl;
cout << endl;
cout << Column1Row1 << " " << Column2Row1 << " " << Column3Row1 << " " << Column4Row1 << " " << Column5Row1 << " " << Column6Row1 << " " << Column7Row1 << endl;
cout << Column1Row2 << " " << Column2Row2 << " " << Column3Row2 << " " << Column4Row2 << " " << Column5Row2 << " " << Column6Row2 << " " << Column7Row2 << endl;
cout << Column1Row3 << " " << Column2Row3 << " " << Column3Row3 << " " << Column4Row3 << " " << Column5Row3 << " " << Column6Row3 << " " << Column7Row3 << endl;
cout << Column1Row4 << " " << Column2Row4 << " " << Column3Row4 << " " << Column4Row4 << " " << Column5Row4 << " " << Column6Row4 << " " << Column7Row4 << endl;
cout << Column1Row5 << " " << Column2Row5 << " " << Column3Row5 << " " << Column4Row5 << " " << Column5Row5 << " " << Column6Row5 << " " << Column7Row5 << endl;
cout << Column1Row6 << " " << Column2Row6 << " " << Column3Row6 << " " << Column4Row6 << " " << Column5Row6 << " " << Column6Row6 << " " << Column7Row6 << endl;
cout << "_____________" << endl;
int Player1Turn = 0;
cin >> Player1Turn;
|
There's a total of 7 integers declared to keep track of the columns and I add markers into columns using the following
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
//Input Player 1 markers for column 7
if (Player1Turn == 7 && Column7Counter == 6)
{cout << endl << "This column is full; select another column!" << endl;
goto main;}
if (Player1Turn == 7 && Column7Row2 == 1 && Column7Counter == 5 || Column7Row2 == 2 && Column7Counter == 5)
{Column7Row1 = 1;
Column7Counter++;}
if (Player1Turn == 7 && Column7Row3 == 1 && Column7Counter == 4 || Column7Row3 == 2 && Column7Counter == 4)
{Column7Row2 = 1;
Column7Counter++;}
if (Player1Turn == 7 && Column7Row4 == 1 && Column7Counter == 3 || Column7Row4 == 2 && Column7Counter == 3)
{Column7Row3 = 1;
Column7Counter++;}
if (Player1Turn == 7 && Column7Row5 == 1 && Column7Counter == 2 || Column7Row5 == 2 && Column7Counter == 2)
{Column7Row4 = 1;
Column7Counter++;}
if (Player1Turn == 7 && Column7Row6 == 1 && Column7Counter == 1 || Column7Row6 == 2 && Column7Counter == 1)
{Column7Row5 = 1;
Column7Counter++;}
if (Player1Turn == 7 && Column7Row6 == 0 && Column7Counter == 0)
{Column7Row6 = 1;
Column7Counter++;}
}
|
All I do is change the Player # and Column/Row # and the Column Counter # and that pretty much is the bulk of my code.
Those two chunks are just changed a bit and looped using a goto to make my game.
Any tips, hints, etc. would be greatly appreciated.