- #1
- 142
- 3
Homework Statement
Need help programming the game connect four in C#.
Homework Equations
The Attempt at a Solution
Code:
private Boolean check_winner_v()
{
Boolean winner = false;
for (int i = 0; i < 7; i++)
{
for (int j = 0; j < 3; j++)
{
if (board[j, i] == 1 && board[j + 1, i] == 1 && board[j + 2, i] == 1 && board[j + 3, i] == 1 || board[j, i] == 2 && board[j + 1, i] == 2 && board[j + 2, i] == 2 && board[j + 3, i] == 2)
{
winner = true;
if (board[j, i] == 1)
{
player1_wins = 1;
games++;
}
else
{
player2_wins = 2;
games++;
}
}
}
}
return winner;
}
private void button17_Click_1(object sender, EventArgs e)
{
for (int i = 5; i > -1; i--)
{
if (board[i, 1] == 0)
{
if (turn == 0)
{
board[i, 1] = 1;
two[i].BackColor = Color.Red;
turn = 1;
row2++;
}
else
{
board[i, 1] = 2;
two[i].BackColor = Color.Yellow;
turn = 0;
row2++;
}
two[i].Visible = true;
i = -1;
}
}
if (row2 == 6)
{
button17.Enabled = false;
button17.Text = "Full";
}
textBox1.Text = check_winner_v().ToString();
textBox2.Text = check_winner_h().ToString();
if (winner == false && turn == 42)
{
textBox5.Text = tie.ToString();
tie++;
}
}
private void button68_Click(object sender, EventArgs e)
{
init_board();
for (int i = 0; i < 6; i++)
{
one[i].Visible = false;
two[i].Visible = false;
three[i].Visible = false;
four[i].Visible = false;
five[i].Visible = false;
six[i].Visible = false;
seven[i].Visible = false;
}
row1 = 0;
row2 = 0;
row3 = 0;
row4 = 0;
row5 = 0;
row6 = 0;
row7 = 0;
turn = 0;
games++;
textBox1.Text = "";
textBox2.Text = "";
button28.Enabled = true;
button16.Enabled = true;
button16.Text = "";
button17.Enabled = true;
button17.Text = "";
button18.Enabled = true;
button18.Text = "";
button19.Enabled = true;
button19.Text = "";
button8.Enabled = true;
button8.Text = "";
button20.Enabled = true;
button20.Text = "";
button21.Enabled = true;
button21.Text = "";
}
I'm having trouble programming the statistics. My stats do not work:
For when the player tie it for some reason will not tally up the tie and this is the part that should tally it up but it does not.
if (winner == false && turn == 42)
{
textBox5.Text = tie.ToString();
tie++;
}
Games does not want to increment either, which is incremented in the method of check_winner_v.
I did not give entire program only parts that I thought were necessary.