Professional Documents
Culture Documents
//How big do you want the connect-4 to be? Standard is 6 rows and 7 cols
int const ROWS = 6; //Standard: 6
int const COLS = 7; //Standard: 7 More then 9 COLS wouldn't show more then 9
numbers and putting in 10 still works
int const connect = 4; //Standard; 4 If you wanna to have to have more then 4
connections to win!!
}
}
//If col is not full this will find the lowest available stop
int checkrow (int colnr){
int rownr = 0;
while(gamearray[row-rownr-2][colnr]!='*'){
rownr++;
}
return row-rownr-2;
}
}
}
if(tie==ROWS*COLS){ //If it is a tie
return 2; //returns a 2
//vertical check
//Almost the same as the horizontal check except the two for loops have switched
places
one=0;
two=0;
for(int c=1;c<col-1;c++){
one =0;
two =0;
for(int r=1;r<row-1;r++){
if(gamearray[r][c]==Player1){
one++;
two = 0;
if(one==connect){
return 1;
}
}
if(gamearray[r][c]==Player2){
two++;
one = 0;
if(two==connect){
return 1;
}
}
if(gamearray[r][c]=='*'){
one=0;
two=0;
}
}
}
int main(){
gamearray[row-1][0]='+'; //Put in +
gamearray[row-1][col-1]='+';
cout << endl;
//Game code
int poneinput; //Input of player on
e
int ptwoinput; //Input of player to
w
//The welcome to the user
cout << "Welcome to a game of Connect-4!" << endl;
cout << "If you dont the rules of the game: Ask google!" << endl;
cout << "Player one is: " << Player1 << endl; //Telling what simbo
l user one got
cout << "Player two is: " << Player2 << endl; //Telling what simbo
l user one got
int width = 3; //width of the gameboard
//Displays the gameboard the first time
for(int r=0;r<row;r++){
cout << endl;
cout.width(width);
for(int c=0;c<col;c++){
cout.width(width);
cout<< gamearray[r][c];
}
}
cout << endl;
}
//After end game, the user get the option to play again or quit
char yesno;
cout << "Wanna play again? Y/N" << endl;
cin >> yesno;
if(yesno== 'y' || yesno == 'Y'){
goto start;
}
else{
cout <<"Okay then.. have a great day!";
return 0;
}
return 0;
}