Exemplo n.º 1
0
        void timer1_Tick(object sender, EventArgs e)
        {
            if (fruit == null)
            {
                fruit = CreateFruit();
            }

            if (snake.Head == fruit.Location)
            {
                snake.Eat(lineOfSight);
                fruit = null;
                if (timer1.Interval > 300)
                {
                    timer1.Interval -= 100;
                }
                score++;
            }
            else
            {
                snake.Move(lineOfSight);
            }

            if (CheckingBorders())
            {
                GameOver();
            }

            ScoreInfo.Text = "Score: " + score;
            pictureBox1.Invalidate();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(120, 30);

            Walls walls = new Walls(120, 30);

            walls.Draw();

            // Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(120, 30, '$');
            Point       food        = foodCreator.CreateFood();

            food.Draw();

            //Очки
            Score score = new Score(0);

            if (snake.Eat(food))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                food = foodCreator.CreateFood();
                food.Draw();
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Green;
                snake.Move();
            }



            int time = 100;

            Thread.Sleep(time);

            //Время
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            //Имя
            string name;



            Console.Write("Type your name: ");
            name = Console.ReadLine();



            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }

                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            WriteGameOver();
            Console.ReadLine();
        }