Now I have some mistake about printing the board.
here is the code
Code:
#include <iostream>
#include<string>
#include<iomanip>
using namespace std;
const int maxrow = 6;
const int maxcol = 7;
void logo();
void playername(string name);
void rules();
void initBoard(char board[][maxcol], int maxrow, int maxcol);
void printBoard(char board[][maxcol], int maxrow, int maxcol);
int main()
{
char board[maxrow][maxcol];
string name;
logo();
playername(name);
rules();
initBoard(board, maxrow, maxcol);
printBoard(board, maxrow, maxcol);
}
void logo()
{
cout<<"------------Welcome to Connect 4 ----------------"<<endl;
cout<<" ************Connect*************"<<endl;
cout<<" **********************************"<<endl;
cout<<" *****************4******************"<<endl;
cout<<" *****************4*4******************"<<endl;
cout<<" ****************4**4******************"<<endl;
cout<<" **************4444444***************"<<endl;
cout<<" *****************4****************"<<endl;
cout<<" ****************4***************"<<endl;
cout<<"\n\n"<<endl;
}
void playername(string name)
{
cout<<"What is player's name : ";
cin>>name;
cout<<"Hi "<<name<<endl;
}
void rules()
{
cout<<"The following is the rules of the Connect 4 : \n";
cout<<"1. Each player in his turn drops one of his checkers down any of the slots \n in the top of the grid. \n";
cout<<"2. The play alternates until one of the players gets four checkers of his \n colour in a row. The four in a row can be horizontal, vertical, or diagonal.\n";
cout<<"3. The first player to get four in a row wins.\n";
cout<<"4. If the board is filled with pieces and neither player has 4 in a row, \n then the game is a draw.\n";
}
void initBoard(char board[][maxcol], int row, int col){
for (int i = 0; i < row; i++)
{
for (int j = 0; j < col; j++)
{
board[i][j] = ' ';
}
}
}
void printBoard(char board[][maxcol], int row, int col)
{
for (int i = 1; i <= row; i++){
for (int j = 1; j <= col; j++){
cout << setw(3) << board[row][col]<<"| ";
}
cout << endl;
}
for (char i = 'A'; i <= 'G'; i++){
cout << setw(3)<<i<<" ";
}
cout << endl;
}
Like this image
http://i1128.photobucket.com/albums/..._connect_4.jpg
why there is some 'n'???
what's the problem??