示例#1
0
文件: snake.cs 项目: Ptronix/Snake
 public void CheckCollision(Matchfield m)
 {
     //if (XposBody[0] <= 0 || XposBody[0] >= 81 || YposBody[0] <= 0 || YposBody[0] >= 21 )
     if (XposBody[0] <= 0 || XposBody[0] >= 81 || YposBody[0] <= 0 || YposBody[0] >= 21)
     {
         GameOver1(m);
     }
 }
示例#2
0
文件: snake.cs 项目: Ptronix/Snake
        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();
        }
示例#3
0
文件: snake.cs 项目: Ptronix/Snake
        public void GameOver1(Matchfield m)
        {
            Console.ForegroundColor = ConsoleColor.Red;
            Console.SetCursorPosition(m.Length / 2, m.Height / 2);
            Console.Write("Game Over!");
            System.Threading.Thread.Sleep(300);

            GameOver2(m);
        }
示例#4
0
文件: snake.cs 项目: Ptronix/Snake
        /// <summary>
        /// Width in fields 22 Snake in range 1-19
        /// heigth in fields 42 Snake 1-41
        /// Border x,y index 0
        /// Otherwise GAME OVER
        /// </summary>

        public void InitializeSnake(Matchfield m)
        {
            YposBody.Insert(0, m.Height / 2);
            XposBody.Insert(0, m.Length / 2);

            //start at the middle of the matchfield
            Console.SetCursorPosition(XposBody[0], YposBody[0]);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("{0}", Head);
        }
示例#5
0
文件: snake.cs 项目: Ptronix/Snake
        public void CheckBerryMatch(Matchfield m)
        {
            if (XposBody.Contains(m.xRandom) && YposBody.Contains(m.yRandom))
            {
                //Add 100 Points to Score Label
                m.Score += 100;

                //Thread sleep time -20 ms seconds
                m.Speed -= 20;

                //Draws New random "Berry Matchfield"
                m.DropItems();
                AppendBlock();
            }
        }
示例#6
0
文件: snake.cs 项目: Ptronix/Snake
        public void DrawSnake(Matchfield m)
        {
            Console.ForegroundColor = ConsoleColor.Green;

            Console.SetCursorPosition(XposBody[0], YposBody[0]);
            Console.Write("{0}", Head);

            for (var xPosition = 1; xPosition < XposBody.Count; xPosition++)
            {
                Console.ForegroundColor = ConsoleColor.DarkGreen;

                for (var yPosition = 1; yPosition < YposBody.Count; yPosition++)
                {
                    Console.SetCursorPosition(XposBody[xPosition], YposBody[yPosition]);
                    Console.Write("{0}", BodyPart);
                }
            }
            Console.ForegroundColor = ConsoleColor.White;
        }
示例#7
0
文件: Program.cs 项目: Ptronix/Snake
        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);
        }
示例#8
0
文件: snake.cs 项目: Ptronix/Snake
 public Snake(Matchfield m)
 {
 }