Exemple #1
0
        /////////////////
        /// THE GAME! ///
        /////////////////

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

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

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

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

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

                    default:
                        newHead.X -= 1;
                        break;
                    }
                    Checks();
                    Printer();
                }
            }
        }
Exemple #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(newHead);
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.SetCursorPosition(newHead.X, newHead.Y);
            Console.Write("@");
            lastDir = newDir;
        }