Hi all,
I posted my message earliar and I got some positive feedbacks but that didn't help me to solve some programming problems. I have an Assignment due 20th of this month, next monday. The Assignment is about creating a Connect Four Game. I have designed the board and two players can play and fill the board. But when one playe fills 4 columns that player should win. I have problems implementing it like this. The other problem is to decide about Vertical, Horizontal and Diagonal win. Would you guys be able to help me with these problems for connect four game. I really appreciate your help. Below is the hasWon() method which decides for Horizontal Win. But it is not working and it does not decide about the win and some times it give ArrayIndexOutof Bound Exception.
//check for horizontal win
public int hasWon()
{
int status = 0;
for (int row=0; row<6; row++)
{
for (int col=0; col<4; col++)
{
if (ConnectFourArr ay[col][row] != 0 &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+1][row] &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+2][row] &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+3][row])
{status = 1;}
//status = true;//int winner;
if(status == 1)
{
System.out.prin tln("Player 1 is the winner");
}
else if(status == 0)
{
System.out.prin tln("Player 2 is the winner" );
}
}//end inner for loop
}// end outer for loop
} // end method Winner
return status;
}
Try to also send me some code so I can finish my project by then.
Thanks a lot for your help. Looking forward to your reply.
Koonda
I posted my message earliar and I got some positive feedbacks but that didn't help me to solve some programming problems. I have an Assignment due 20th of this month, next monday. The Assignment is about creating a Connect Four Game. I have designed the board and two players can play and fill the board. But when one playe fills 4 columns that player should win. I have problems implementing it like this. The other problem is to decide about Vertical, Horizontal and Diagonal win. Would you guys be able to help me with these problems for connect four game. I really appreciate your help. Below is the hasWon() method which decides for Horizontal Win. But it is not working and it does not decide about the win and some times it give ArrayIndexOutof Bound Exception.
//check for horizontal win
public int hasWon()
{
int status = 0;
for (int row=0; row<6; row++)
{
for (int col=0; col<4; col++)
{
if (ConnectFourArr ay[col][row] != 0 &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+1][row] &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+2][row] &&
ConnectFourArra y[col][row] == ConnectFourArra y[col+3][row])
{status = 1;}
//status = true;//int winner;
if(status == 1)
{
System.out.prin tln("Player 1 is the winner");
}
else if(status == 0)
{
System.out.prin tln("Player 2 is the winner" );
}
}//end inner for loop
}// end outer for loop
} // end method Winner
return status;
}
Try to also send me some code so I can finish my project by then.
Thanks a lot for your help. Looking forward to your reply.
Koonda
Comment