} //END OF ConnectFour METHOD /// <summary> /// This event handler takes care of placing a new /// game piece on the board in the corresponding column /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, EventArgs e) { Button button = (Button)sender; string buttonHit = button.Text; _game.FindColumn(buttonHit); Color color = new Color(); if (uxTurnLabel.BackColor == Color.Red) { color = Color.Red; uxTurnLabel.BackColor = Color.Black; uxTurnLabel.ForeColor = Color.White; uxTurnLabel.Text = "Black"; } //END OF IF else { color = Color.Black; uxTurnLabel.BackColor = Color.Red; uxTurnLabel.ForeColor = Color.Black; uxTurnLabel.Text = "Red"; } //END OF ELSE if (_game.Column.Data == null) { _game.Column.Data = new DoubleLinkedListCell <GamePiece>(buttonHit + 1); _game.Column.Data.Data = new GamePiece(color, 1, Convert.ToChar(buttonHit)); SetColor(buttonHit + "1", color); } else { GamePiece add = new GamePiece(color, _game.Column.Data.Data.Row + 1, Convert.ToChar(buttonHit)); DoubleLinkedListCell <GamePiece> newPiece = new DoubleLinkedListCell <GamePiece>((buttonHit + (_game.Column.Data.Data.Row + 1)).ToString()); newPiece.Data = add; newPiece.Next = null; newPiece.Prev = _game.Column.Data; _game.Column.Data = newPiece; SetColor(buttonHit + add.Row.ToString(), color); if (_game.Column.Data.Data.Row == 6) { button.Enabled = false; _counter++; } //END OF IF } //END OF ELSE if ((_game.CheckWin(_game.Column.Data))) { MessageBox.Show(color.ToString() + " is the winner"); try { Environment.Exit(0); } //END OF TRY catch { } //END OF CATCH } //END OF IF if (_counter == 7) { MessageBox.Show("It is a Draw"); try { Environment.Exit(0); } //END OF TRY catch { } //END OF CATCH } //END OF IF } //END OF uxButton_Click