static void Main(string[] args) { var game = new Connect4(); do { Display(game); for (; ; ) { Console.WriteLine($"Player {game.activePlayer} : Which column 1-{game.ColCount} ?"); var turn = Console.ReadLine(); int column; if (int.TryParse(turn, out column)) { if(column > game.ColCount || column < 1) { Console.Error.WriteLine("Number out of bounds."); } else { game.Play(column - 1); break; } } else { Console.Error.WriteLine("Invalid column number."); } } } while (!game.ended); Display(game); if(game.winner == 0) { Console.WriteLine("Draw"); } else { Console.WriteLine($"Player {game.winner} wins."); } }
static void Main(string[] args) { var game = new Connect4(); do { Display(game); for (;;) { Console.WriteLine($"Player {game.PlayerNumber} : Which column 1-{game.ColCount} ?"); var turn = Console.ReadLine(); int column; // check if column is within ColCout bounds if (int.TryParse(turn, out column) && (column > 0 && column <= game.ColCount)) { bool played = game.Play(column); if (played) { break; } } Console.Error.WriteLine("Invalid play."); } } while (!game.Ended); Display(game); if (game.Winner == 0) { Console.WriteLine("Draw"); } else { Console.WriteLine($"Player {game.Winner} wins."); } }