/// <summary> /// The equivalent of dropping one of the dots into the frame /// </summary> /// <param name="index">1-7, the horizontal left to right coordinate of the hole to "drop" it into.</param> public void DropDot(int index) { if (index <= Columns && index >= 1) { Connect4Colour[] column = ConnectFourGrid[index - 1]; int columnCount = column.Count(x => x != null); if (columnCount < Rows) { column[Utillity.Clamp(columnCount, 0, Rows)] = CurrPlayerColour; //check if there are matches whenever a dot drops LookForFourInARow(index - 1, columnCount); if (!GameWon) { //swap colour if (CurrPlayerColour == Connect4Colour.Red) { CurrPlayerColour = Connect4Colour.Yellow; } else { CurrPlayerColour = Connect4Colour.Red; } } } } }
private void InitGrid() { for (int i = 0; i < Columns; i++) { ConnectFourGrid[i] = new Connect4Colour[Rows]; } }