Exemple #1
0
        public static void Main(string[] args)
        {
            Apple a = new Apple("red", "round", 12);

            System.Console.WriteLine(a.CreateApple());
        }
Exemple #2
0
        static void Main(string[] args)
        {
START:
            Console.ResetColor();
            Console.Clear();
            godlike          = false;
            goThroughWalls   = false;
            currentDirection = direction.Down;
            lastMove         = direction.Down;
            point            = 0;
            isDead           = false;
            snake            = new SnakeBody();
            appleLoc         = new PossibleAppleLoc();
            apple            = new Apple();
            ticker           = new Timer();

            Console.Write("Difficulty: <1-5>: ");

            while (!int.TryParse(Console.ReadKey().KeyChar.ToString(), out difficulty) || difficulty < 1 || difficulty > 5)
            {
                Console.Clear();
                Console.WriteLine("-Incorrect format-");
                Console.Write("Difficulty <1-5>: ");
            }

            Console.Clear();
            Console.OutputEncoding = Encoding.Unicode;
            for (int i = 0; i < width; i++)
            {
                Console.SetCursorPosition(i, 0);
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write('\0');

                Console.SetCursorPosition(i, height - 1);
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write('\0');
            }

            for (int i = 1; i < height; i++)
            {
                Console.SetCursorPosition(0, i);
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write('\0');

                Console.SetCursorPosition(width - 1, i);
                Console.BackgroundColor = ConsoleColor.Blue;
                Console.Write('\0');
            }

            Console.SetCursorPosition(8, 0);
            Console.Write("<P> to Pause\t<ESC> to Quit\tDifficulty: {0}\tP: 0\tHS: {1}", difficulty, HighScore);
            Console.SetCursorPosition(26, height - 1);
            Console.Write("Made by Stiig \"Neophear\" Gade");
            Console.BackgroundColor = ConsoleColor.Black;

            DrawGame();
            Console.Title = "Snake";
            apple.CreateApple();
            ticker.Interval = 200 / difficulty;
            ticker.Elapsed += ticker_Elapsed;
            ticker.Start();

            while (true)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey(true);

                if (keyInfo.KeyChar != '\0')
                {
                    code += keyInfo.KeyChar;
                }

                if (Strings.Right(code, "idspispopd".Length) == "idspispopd")
                {
                    goThroughWalls = !goThroughWalls;
                    Console.Title  = "Ghosting now, are we?";
                    code           = String.Empty;
                }
                if (Strings.Right(code, "iddqd".Length) == "iddqd")
                {
                    godlike       = !godlike;
                    Console.Title = "Welcome Marine!";
                    code          = String.Empty;
                }
                if (Strings.Right(code, "stiig er awesome".Length) == "stiig er awesome")
                {
                    ticker.Interval = 200;
                    code            = String.Empty;
                }

                if (Strings.Right(code, "Henriette".Length) == "henriette")
                {
                    Console.SetCursorPosition(26, height - 1);
                    Console.BackgroundColor = ConsoleColor.DarkRed;
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.Write(" <3 Jeg elsker dig Henriette <3 ");
                    Console.ResetColor();
                    code = String.Empty;
                }

                //cuts down the code string when it gets too long
                if (code.Length > 30)
                {
                    code = code.Substring(20);
                }

                switch (keyInfo.Key)
                {
                case ConsoleKey.Escape:
                    return;

                case ConsoleKey.UpArrow:
                    if (lastMove != direction.Down)
                    {
                        currentDirection = direction.Up;
                    }
                    break;

                case ConsoleKey.DownArrow:
                    if (lastMove != direction.Up)
                    {
                        currentDirection = direction.Down;
                    }
                    break;

                case ConsoleKey.LeftArrow:
                    if (lastMove != direction.Right)
                    {
                        currentDirection = direction.Left;
                    }
                    break;

                case ConsoleKey.RightArrow:
                    if (lastMove != direction.Left)
                    {
                        currentDirection = direction.Right;
                    }
                    break;

                case ConsoleKey.Y:
                    if (isDead)
                    {
                        goto START;
                    }
                    break;

                case ConsoleKey.N:
                    if (isDead)
                    {
                        return;
                    }
                    else
                    {
                        break;
                    }

                case ConsoleKey.P:
                    ticker.Enabled = !ticker.Enabled;
                    break;

                case ConsoleKey.PageDown:
                    if (difficulty > 1)
                    {
                        difficulty--;
                    }
                    ChangeDifficulty();
                    break;

                case ConsoleKey.PageUp:
                    if (difficulty < 5)
                    {
                        difficulty++;
                    }
                    ChangeDifficulty();
                    break;
                }
            }
        }