示例#1
0
        /////////////////
        /// THE GAME! ///
        /////////////////

        public void PlayGame()
        {
            time.Start();
            while (true)
            {
                Input();

                if (!pause)
                {
                    if (time.ElapsedMilliseconds < 100)
                    {
                        continue;
                    }
                    time.Restart();

                    newH = PointFactory.Create(0, snake.Last().X, snake.Last().Y);
                    switch (newDir)
                    {
                    case 0:
                        newH.Y -= 1;
                        break;

                    case 1:
                        newH.X += 1;
                        break;

                    case 2:
                        newH.Y += 1;
                        break;

                    default:
                        newH.X -= 1;
                        break;
                    }
                    Checks();
                    Printer();
                }
            }
        }
示例#2
0
        //////////////////////////
        /// Printing to screen ///
        //////////////////////////

        public void Printer()
        {
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(snake.Last().X, snake.Last().Y);
            Console.Write("0");
            if (!Eaten)
            {
                Console.SetCursorPosition(snake.First().X, snake.First().Y);
                Console.Write(" ");
                snake.RemoveAt(0);
            }
            else
            {
                while (true)
                {
                    PointFactory.RenewApple((Apple)apple);
                    foreach (Point i in snake)
                    {
                        if (!(i.X == apple.X && i.Y == apple.Y))
                        {
                            break;
                        }
                    }
                    break;
                }
                Console.ForegroundColor = ConsoleColor.Green;
                Console.SetCursorPosition(apple.X, apple.Y);
                Console.Write("$");
                Eaten = false;
            }
            snake.Add(newH);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(newH.X, newH.Y);
            Console.Write("@");
            last = newDir;
        }