

If ((A1.BackColor = A2.BackColor) & (A2.BackColor = A3.BackColor) & (A3.BackColor = A4.BackColor) & (A4.BackColor = A5.BackColor) & (!A1.Enabled))Įlse if ((B1.BackColor = B2.BackColor) & (B2.BackColor = B3.BackColor) & (B3.BackColor = B4.BackColor) & (B4.BackColor = B5.BackColor) & (!B1.Enabled))Įlse if ((C1.BackColor = C2.BackColor) & (C2.BackColor = C3.BackColor) & (C3.BackColor = C4.BackColor) & (C4.BackColor = C5.BackColor) & (!C1.Enabled))Įlse if ((D1.BackColor = D2.BackColor) & (D2.BackColor = D3.BackColor) & (D3.BackColor = D4.BackColor) & (D4.BackColor = D5.BackColor) & (!D1.Enabled))Įlse if ((E1.BackColor = E2.BackColor) & (E2.BackColor = E3.BackColor) & (E3.BackColor = E4.BackColor) & (E4.BackColor = E5.BackColor) & (!E1.Enabled))

Private void button_click(object sender, EventArgs e)

Also run checkForWinner function after every move (button click) function to alternate turns between red and yellow players and count turns for potential draws (see below). Private void Form1_Load(object sender, EventArgs e) Int turn_count = 0 //counts each turn for features such as draw functionīool winner_found = false // automatically sets winner found function to false to If it is not too much trouble i would also like to add a 'dropping' mechanic like the real connect four and make a more efficient checkforwinner function so i can expand the board to 12 x 8 or so and not have double or triple the amount of checkforwinner if statements, cheers.Ĭode is below: public partial class Form1 : Formīool turn = true //if true it is red turn / if false it is yellow turn When the board is reset, it changes the colour of all the buttons to color.lightgray which may interfere with the checkforwinner function. I don't know exactly what is causing the issue, but i have a feeling it has something to do with the checkforwinner method and how it checks that all buttons in a row or column by matching all colours. The code works perfectly until the player uses the 'reset board' function the game decides that the any button click afterwards is a winner and the only way to stop this is to close and re-build the application (using visual studio).
