Connect 4 - Column Change

Hi i am just looking for a bit of help i am creating a connect 4 programme in c++ and it all works fine so far just the bit i am stuck on is when the player enters were they want their move to go on the board instead of dropping down to the bottom of the column on the board the move goes to were ever in the board the user picks

Im not sure how i can change it so instead of going anywere in the column the player picks the move will drop down to the bottom of the column like a real connect 4 game

This is the code i have

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <limits>

using std::cout;
using std::cin;
using std::endl;

char a[] = {'|','_','|','_','|','_','|','_','|','_','|','_','|','_','|'};
char b[] = {'|','1','|','2','|','3','|','4','|','5','|','6','|','7','|'};
char board[6][7];

void print_board()
{
//Clears the screen
system("cls");

int i, j = 0;

cout << " ";

for( j = 0; j<15; j++)
cout << b[j];
cout << endl;

for ( i=0; i<6; i++)
{
cout << i+1;
cout << '|';
for (j = 0; j < 7; j++)
cout << board[i][j] << '|';

cout << endl;
}
}

int main()
{
int i, j, k = 0;
int row;
int column;
int gameover = 0;

//Build the board
for (i=0; i<6; i++)
for (j=0; j<7; j++)
board[i][j] = '_';


char player='2'; /* Keeps track of who's playing */

/* Loop through this block until the game ends */
while(! gameover)
{
int row, column;


//Calls the print board method 
print_board();

/* Switch players */
if(player == '1')
player='2';
else
player='1';

/* Print a message for the player */
cout << endl << "Player " << player << "'s turn:" << endl;

/* Read two values from the keyboard */
cout << "X:";
cin >> column;
cout << "Y:";
cin >> row;

/* Change the game board */
board[row-1][column-1]=player;

cout << "Player " << player << " wins!" << endl;
gameover = 1;
}
*/

k++;
if( k == 42)
gameover = 1;

cout << endl;
}

cout << "Game Over" <<endl;
system("pause");
return 0;
}


And this is a image of what i mean about the move not dropping down the column

http://img249.imageshack.us/img249/836/30177856tu4.jpg

Thanks Ross
Why are you even asking for a Y co-ordinant? All that matters is an X co-ordinant. Just check if the lowest Y co-ord is taken, and if it is, decrement one and check again, until you get to the top.

Also, you have declared row and column twice.
Last edited on
Topic archived. No new replies allowed.