Example #1
0
 public bool IsHit(point food)
 {
     return(food.x == this.x && food.y == this.y);
 }
Example #2
0
 internal bool IsHit(point p)
 {
     return(p.x == this.x && p.y == this.y);
 }
Example #3
0
 public point(point p)
 {
     x   = p.x;
     y   = p.y;
     sym = p.sym;
 }
Example #4
0
        static void Main(string[] args)
        {
            //Ограничение окна
            //Console.SetBufferSize(80, 25);
            #region Wall

            Walls walls = new Walls(80, 25);
            walls.Draw();


            #endregion

            #region SnakeBody

            point  p     = new point(4, 5, '*');
            Snakee snake = new Snakee(p, 4, Direction.RIGHT);
            snake.DrawLine();
            #endregion

            #region Food

            foodCreator foodCreator = new foodCreator(80, 25, '$');
            point       food        = foodCreator.CreateFood();
            food.Draw();

            #endregion

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                    //Console.Write("Game OVER");
                }
                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);
                }
            }

            #region Handle Key

            while (true)
            {
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
                Thread.Sleep(100);
                snake.Move();
            }
            #endregion



            //Console.ReadKey();
        }