Esempio n. 1
0
        /// <summary>
        /// Show the game with borders and colors.
        /// </summary>
        /// <param name="pad">Left padding</param>
        private void ShowBoxed(int pad = 3)
        {
            var gap = "";

            gap = gap.PadRight(pad, ' ');

            var len    = 7;
            var status = IsOver();
            var hs     = (Highscores.Any() ? Highscores.Max(s => s.Score) : 0);


            Title(true, status, " 2048");

            Cons.WriteFormatted("   Score {0}", Color.DarkCyan, Color.DarkOrange, Score);
            Cons.WriteFormatted("\tHighscore {0}", Color.DarkCyan, Color.DarkOrange, hs);
            Console.WriteLine();

            #region Draw boxes
            Cons.Write(gap);
            Cons.Write("┌");
            for (int i = 0; i < 4 * len; i++)
            {
                if (i == 0)
                {
                    continue;
                }
                if (i % len != 0)
                {
                    Cons.Write("─");
                }
                else
                {
                    Cons.Write("┬");
                }
            }
            Cons.Write("┐\n");

            for (int i = 0; i < 4; i++)
            {
                Cons.Write(gap);
                for (int j = 0; j < 4; j++)
                {
                    var separator = "│";
                    var str       = "";

                    var blanks = len - 1;
                    var value  = Dimension[i][j];
                    var digits = value.ToString().Length;
                    var spaces = blanks - digits;

                    if (value != 0)
                    {
                        str = str.PadRight(spaces - 1, ' ') + value + ' ';
                    }
                    else
                    {
                        str = str.PadRight(blanks, ' ');
                    }


                    Cons.Write(separator);
                    Cons.ForegroundColor = Color.White;
                    if (value != 0)
                    {
                        var r = value % 255;
                        var g = (120 + r) % 255;
                        if (g >= 200)
                        {
                            Cons.ForegroundColor = Color.Black;
                        }
                        Cons.BackgroundColor = Color.FromArgb(r, g, 50);
                    }
                    Cons.Write(str);
                    Cons.ResetColor();

                    if (j == 3)
                    {
                        Cons.Write(separator);
                    }
                }

                Console.WriteLine();
                Cons.Write(gap);
                if (i != 3)
                {
                    for (int k = 0; k < 4 * len; k++)
                    {
                        if (k == 0)
                        {
                            Cons.Write("├");
                        }

                        if (k % len != 0)
                        {
                            Cons.Write("─");
                        }
                        else if (k != 0)
                        {
                            Cons.Write("┼");
                        }

                        if (k == 4 * len - 1)
                        {
                            Cons.Write("┤");
                        }
                    }
                    Console.WriteLine();
                }
            }

            Cons.Write("└");
            for (int i = 0; i < 4 * len; i++)
            {
                if (i == 0)
                {
                    continue;
                }
                if (i % len != 0)
                {
                    Cons.Write("─");
                }
                else
                {
                    Cons.Write("┴");
                }
            }
            Cons.Write("┘\n");
            #endregion
        }