Beispiel #1
0
        public static void Main(string[] args)
        {
            Console.CursorVisible = false;
            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight);

            Wall wall = new Wall(Console.WindowWidth, Console.WindowHeight, '+');

            wall.Draw();

            Point tail  = new Point(5, 10, '*');
            Snake snake = new Snake(tail, 5, Direction.Right);

            snake.OnHit += WriteGameOver;
            snake.Draw();

            Food  foodCreator = new Food(Console.WindowWidth, Console.WindowHeight, '$', snake);
            Point food        = foodCreator.Create();

            food.Draw();

            while (true)
            {
                snake.Run();

                if (snake.IsHitTail() || snake.IsHitWall(wall))
                {
                    break;
                }

                if (snake.Eat(food))
                {
                    food.Sym = tail.Sym;
                    food     = foodCreator.Create();
                    food.Draw();
                }

                if (Console.KeyAvailable)
                {
                    ConsoleKey key = Console.ReadKey().Key;
                    snake.Move(key);
                }

                Thread.Sleep(100);
            }

            Console.ReadKey();
        }
Beispiel #2
0
        private void FoodSpawnTimer_Tick(object sender, EventArgs e)
        {
            Food food = Food.Create();

            SpawnPoint(food);

            if (foodList.Count < 100)
            {
                foodList.Add(food);
            }
        }
Beispiel #3
0
 static void fun(object st)
 {
     if (walls.Collider(snake.snake.Last()) || snake.Collider(snake.snake.Last()))
     {
         snake.Clear();
         snake = new Snake(x / 2, y / 2, 5);
         walls = new Walls(x, y, '+');
     }
     else if (snake.Eat(food.food))
     {
         food.Create();
     }
     else
     {
         snake.Move();
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            Console.Clear();
            Console.CursorVisible = false;

            walls = new Walls(x, y, '+');
            food  = new Food(x, y, '@');
            food.Create();
            snake = new Snake(x / 2, y / 2, 5);

            time = new Timer(fun, null, 0, 80);

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.Rotation(key.Key);
                }
            }
        }