Example #1
0
 public CPoint GetNextPoint()
 {
     CPoint head = pList.Last();
     CPoint nextPoint = new CPoint(head); ;
     nextPoint.Move(1, direction);
     return nextPoint;
 }
Example #2
0
 public HorizontalLine(int xLeft, int xRight, int y, char sym)
 {
     pList = new List<CPoint>();
     for (int x = xLeft; x <= xRight; x++)
     {
         CPoint p = new CPoint(x, y, sym);
         pList.Add(p);
     }
 }
Example #3
0
 public VerticalLine(int yUp, int yDown, int x, char sym)
 {
     pList = new List<CPoint>();
     for (int y = yUp; y <= yDown; y++)
     {
         CPoint p = new CPoint(x, y, sym);
         pList.Add(p);
     }
 }
Example #4
0
 internal bool Eat(CPoint food)
 {
     CPoint head = GetNextPoint();
     if (head.IsHit(food))
     {
         food.sym = head.sym;
         pList.Add(food);
         return true;
     }
     else return false;
 }
Example #5
0
 public Snake(CPoint tail, int length, Direction _direction)
 {
     direction = _direction;
     pList = new List<CPoint>();
     for (int i = 0; i < length; i++)
     {
         CPoint p = new CPoint(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Example #6
0
 private bool IsHit(CPoint point)
 {
     foreach (var p in pList)
     {
         if (point.IsHit(p))
         {
             return true;
         }
     }
     return false;
 }
Example #7
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);
            walls.Draw();

            //отрисовка змейки
            CPoint p = new CPoint(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);
            snake.Draw();

            //food
            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            CPoint food = foodCreator.CreateFood();
            food.Draw();

            //цикл игры
            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);
                }
            }
            //Console.ReadKey();
        }
Example #8
0
 internal bool IsHit(CPoint p)
 {
     return this.x == p.x && this.y == p.y;
 }
Example #9
0
 public CPoint(CPoint p)
 {
     x = p.x;
     y = p.y;
     sym = p.sym;
 }