Beispiel #1
0
        public void MoveSnake(Matchfield m)
        {
            do
            {
                if (Console.KeyAvailable)
                {
                    keyPressed = Console.ReadKey().Key;
                }

                //Move Up y-1
                if (keyPressed == ConsoleKey.UpArrow && direction != Direction.Down)
                {
                    direction = Direction.Up;

                    YposBody.Insert(0, YposBody[0] - 1);
                    XposBody.Insert(0, XposBody[0]);

                    DeleteLastPart();
                }
                //Move Down = y+1
                else if (keyPressed == ConsoleKey.DownArrow && direction != Direction.Up)
                {
                    direction = Direction.Down;

                    YposBody.Insert(0, YposBody[0] + 1);
                    XposBody.Insert(0, XposBody[0]);
                    DeleteLastPart();
                }
                //MoveLeft = x-1
                else if (keyPressed == ConsoleKey.LeftArrow && direction != Direction.Right)
                {
                    direction = Direction.Left;

                    YposBody.Insert(0, YposBody[0]);
                    XposBody.Insert(0, XposBody[0] - 1);
                    DeleteLastPart();
                }
                //MoveRight = x+1
                else if (keyPressed == ConsoleKey.RightArrow && direction != Direction.Left)
                {
                    direction = Direction.Right;

                    YposBody.Insert(0, YposBody[0]);
                    XposBody.Insert(0, XposBody[0] + 1);
                    DeleteLastPart();
                }
                DeleteSnake();
                DrawSnake(m);
                //DeleteLastPart();
                CheckCollision(m);
                CheckBerryMatch(m);
                m.ScoreSpeedLabel();

                System.Threading.Thread.Sleep(m.Speed);
            } while (m.SnakeIsALive);

            Console.ReadLine();
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(83, 25);
            Console.WriteLine(Console.WindowWidth);
            Console.WriteLine(Console.WindowHeight);

            Matchfield m = new Matchfield();

            m.DrawBorders();
            Snake snake = new Snake(m);

            snake.InitializeSnake(m);

            m.DropItems();
            m.ScoreSpeedLabel();

            do
            {
                if (Console.KeyAvailable)
                {
                    snake.MoveSnake(m);
                }
            } while (m.SnakeIsALive);
        }