示例#1
0
        /// <summary>
        /// Initialise all the tile colours.
        /// </summary>
        static TileColors()
        {
            _blankColor = new TileColors(ConsoleColor.Black, ConsoleColor.DarkGray);

            _colors.Add(2, new TileColors(ConsoleColor.DarkRed, ConsoleColor.White));
            _colors.Add(4, new TileColors(ConsoleColor.DarkYellow, ConsoleColor.White));
            _colors.Add(8, new TileColors(ConsoleColor.DarkGreen, ConsoleColor.White));
            _colors.Add(16, new TileColors(ConsoleColor.DarkCyan, ConsoleColor.White));
            _colors.Add(32, new TileColors(ConsoleColor.DarkBlue, ConsoleColor.White));
            _colors.Add(64, new TileColors(ConsoleColor.DarkMagenta, ConsoleColor.White));
            _colors.Add(128, new TileColors(ConsoleColor.Red, ConsoleColor.White));
            _colors.Add(256, new TileColors(ConsoleColor.Yellow, ConsoleColor.Black));
            _colors.Add(512, new TileColors(ConsoleColor.Green, ConsoleColor.Black));
            _colors.Add(1024, new TileColors(ConsoleColor.Cyan, ConsoleColor.Black));
            _colors.Add(2048, new TileColors(ConsoleColor.Blue, ConsoleColor.White));

            _defaultColor = new TileColors(ConsoleColor.Magenta, ConsoleColor.White);
        }
示例#2
0
        /// <summary>
        /// Initialise all the tile colours.
        /// </summary>
        static TileColors()
        {
            _blankColor = new TileColors(ConsoleColor.Black, ConsoleColor.DarkGray);

            _colors.Add(2, new TileColors(ConsoleColor.DarkRed, ConsoleColor.White));
            _colors.Add(4, new TileColors(ConsoleColor.DarkYellow, ConsoleColor.White));
            _colors.Add(8, new TileColors(ConsoleColor.DarkGreen, ConsoleColor.White));
            _colors.Add(16, new TileColors(ConsoleColor.DarkCyan, ConsoleColor.White));
            _colors.Add(32, new TileColors(ConsoleColor.DarkBlue, ConsoleColor.White));
            _colors.Add(64, new TileColors(ConsoleColor.DarkMagenta, ConsoleColor.White));
            _colors.Add(128, new TileColors(ConsoleColor.Red, ConsoleColor.White));
            _colors.Add(256, new TileColors(ConsoleColor.Yellow, ConsoleColor.Black));
            _colors.Add(512, new TileColors(ConsoleColor.Green, ConsoleColor.Black));
            _colors.Add(1024, new TileColors(ConsoleColor.Cyan, ConsoleColor.Black));
            _colors.Add(2048, new TileColors(ConsoleColor.Blue, ConsoleColor.White));

            _defaultColor = new TileColors(ConsoleColor.Magenta, ConsoleColor.White);
        }
示例#3
0
        /// <summary>
        /// Draws the tile from board coordinates onto the screen.
        /// </summary>
        /// <param name="x">X index of the tile on the board.</param>
        /// <param name="y">Y index of the tile on the board.</param>
        private void DrawTile(int x, int y)
        {
            TileColors tileColors = TileColors.GetTileColors(board[y, x]);

            Console.BackgroundColor = tileColors.BackgroundColor;
            Console.ForegroundColor = tileColors.ForegroundColor;

            Console.SetCursorPosition(24 + x * 8, y * 5 + 3);
            Console.Write("┌──────┐");

            Console.SetCursorPosition(24 + x * 8, y * 5 + 4);
            Console.Write("│      │");

            Console.SetCursorPosition(24 + x * 8, y * 5 + 5);
            Console.Write("│");
            if (board[y, x] != 0)
            {
                // Write the number on the tile, centered (or a bit to the right if it can't be perfectly centered)
                // If the tile number is longer than 6 digits, it will overflow :D
                string numString = board[y, x].ToString();
                int    postfix   = (6 - numString.Length) / 2;
                int    prefix    = 6 - numString.Length - postfix;
                for (int i = 0; i < prefix; i++)
                {
                    Console.Write(" ");
                }
                Console.Write("{0}", numString);
                for (int i = 0; i < postfix; i++)
                {
                    Console.Write(" ");
                }
            }
            else
            {
                Console.Write("      ");
            }
            Console.Write("│");

            Console.SetCursorPosition(24 + x * 8, y * 5 + 6);
            Console.Write("│      │");

            Console.SetCursorPosition(24 + x * 8, y * 5 + 7);
            Console.Write("└──────┘");
        }