public MainWindow() { InitializeComponent(); var userInput = new TicTacToeUserWpfInput { CellType = TicTacToeCellType.Cross }; var random = new Random((int)DateTime.Now.Ticks); var p2 = new TicTacToePlayer(userInput); var buttons = new List <Button>(); buttons.Add(Button1); buttons.Add(Button2); buttons.Add(Button3); buttons.Add(Button4); buttons.Add(Button5); buttons.Add(Button6); buttons.Add(Button7); buttons.Add(Button8); buttons.Add(Button9); foreach (var button in buttons) { button.Click += (sender, args) => { var i = buttons.IndexOf(button); userInput.SendInput(i / 3, i % 3); }; } _buttons = buttons; var ttt = new TicTacToe(new TicTacToeWpfOutput(_buttons)); ttt.GameEnded += OnGameEnded; var p1Input = new TicTacToeCpuInput(TicTacToeCpuDifficulty.Impossible, (r, c) => ttt[r, c]) { CellType = TicTacToeCellType.Circle }; var p1 = new TicTacToePlayer(p1Input); p1.PlayerWaiting += sender => p1Input.GetInput(); ttt.Start(p1, p2); }
static void Main(string[] args) { var ttt = new TicTacToe(new TicTacToeConsoleOutput()); ttt.GameEnded += OnGameEnded; var random = new Random((int)DateTime.Now.Ticks); var p1Input = new TicTacToeCpuInput(TicTacToeCpuDifficulty.Impossible, (r, c) => ttt[r, c]) { CellType = TicTacToeCellType.Circle }; var p2Input = new TicTacToeCpuInput(TicTacToeCpuDifficulty.Easy, (r, c) => ttt[r, c]) { CellType = TicTacToeCellType.Cross }; //new TicTacToeUserConsoleInput { CellType = TicTacToeCellType.Cross }; var p1 = new TicTacToePlayer(p1Input); var p2 = new TicTacToePlayer(p2Input); p2.PlayerWaiting += sender => p2Input.GetInput(); p1.PlayerWaiting += sender => p1Input.GetInput(); ttt.Start(p1, p2); waitHandle.WaitOne(); }