/// <summary> /// Draw Connect Four board /// </summary> private void Draw() { // Clear screen Console.Clear(); // Draw numbered column headers Console.Write(" "); for (uint column = 1; column <= _game.Columns; column++) { Console.Write(column.ToString("00")); if (column < _game.Columns) { Console.Write("|"); } } Console.WriteLine(); // Draw each disc by row and column for (uint row = 1; row <= _game.Rows; row++) { Console.Write(" "); for (uint column = 1; column <= _game.Columns; column++) { // get player's disc in location and set background colour accordingly var disc = _game.GetDisc(column, row); if (disc == null) { Console.BackgroundColor = ConsoleColor.Black; } else if (disc.Value == Game.Player.PlayerOne) { Console.BackgroundColor = ConsoleColor.Yellow; } else if (disc.Value == Game.Player.PlayerTwo) { Console.BackgroundColor = ConsoleColor.Red; } Console.Write(" "); Console.BackgroundColor = ConsoleColor.Black; if (column < _game.Columns) { Console.Write("|"); } } Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("User has Yellow disc. Computer has Red disc."); Console.WriteLine(); }
public void TestDiscLandedInExpectedSlot() { _game.Restart(); var row = _game.Rows; var disc = (Player?)null; Assert.IsNull(_game.GetDisc(1, row), "Column 1, Row " + row + " should be empty."); _game.AddDisc(1); disc = _game.GetDisc(1, row); Assert.IsTrue(disc != null && disc.Value == Player.PlayerOne, "Colum 1, Row " + row + " should have player one disc."); Assert.IsNull(_game.GetDisc(2, row), "Column 2, Row " + row + " should be empty."); _game.AddDisc(2); disc = _game.GetDisc(2, row); Assert.IsTrue(disc != null && disc.Value == Player.PlayerTwo, "Colum 2, Row " + row + " should have player two disc."); row--; Assert.IsNull(_game.GetDisc(1, row), "Column 1, Row " + row + " should be empty."); _game.AddDisc(1); disc = _game.GetDisc(1, row); Assert.IsTrue(disc != null && disc.Value == Player.PlayerOne, "Colum 1, Row " + row + " should have player one disc."); }