private static void PrintBoard(IBoard board, TileColorizer colorizer) { Console.Clear(); Console.WriteLine("Used {0,4} steps, score {1,5}", board.StepsCount, board.Score); var arr = board.To2DArray(); int rowLength = arr.GetLength(0); int colLength = arr.GetLength(1); for (int i = 0; i < rowLength; i++) { for (int j = 0; j < colLength; j++) { Console.ForegroundColor = colorizer.GetColorByValue(arr[i, j].Value); Console.Write("{0,4} ", arr[i, j].Value); } Console.Write(Environment.NewLine + Environment.NewLine); } Console.ForegroundColor = ConsoleColor.Black; Console.WriteLine("Press q to exit, use arrow keys for game, ctrl+z to undo"); }
static void Main(string[] args) { IGameEngine engine = GetGameEngine(); IGameOptions options = new _2048Options(); IStatefullBoard board = new Board(); var colorizer = new TileColorizer(); Console.BackgroundColor = ConsoleColor.White; PrintBoard(board, colorizer); IGame game2048 = new Game2048(engine, options, board); game2048.RepaintRequiredEvent += (o, e) => PrintBoard(e.Board, colorizer); game2048.Play(); Console.WriteLine("Game over!"); if (engine.IsAI() && board.StepsCount > options.MaxStepCount) { Console.WriteLine("Halt! {0} step limit reached!", options.MaxStepCount); } Console.ResetColor(); }