示例#1
0
文件: Snake.cs 项目: lihac92/snake
        public Point1 GetNextPoint()
        {
            Point1 head      = pList.Last();
            Point1 nextPoint = new Point1(head);

            nextPoint.Move(1, direction);
            return(nextPoint);
        }
示例#2
0
 public VerticalLine(int yUp, int yDown, int x, char sym)
 {
     pList = new List <Point1>();
     for (int y = yUp; y <= yDown; y++)
     {
         Point1 p = new Point1(x, y, sym);
         pList.Add(p);
     }
 }
示例#3
0
 public HorizontalLine(int xLeft, int xRight, int y, char sym)
 {
     pList = new List <Point1>();
     for (int x = xLeft; x <= xRight; x++)
     {
         Point1 p = new Point1(x, y, sym);
         pList.Add(p);
     }
 }
示例#4
0
 private bool IsHit(Point1 point)
 {
     foreach (var p in pList)
     {
         if (p.IsHit(point))
         {
             return(true);
         }
     }
     return(false);
 }
示例#5
0
文件: Snake.cs 项目: lihac92/snake
 public Snake(Point1 tail, int length, Direction _direction)
 {
     direction = _direction;
     pList     = new List <Point1>();
     for (int i = 0; i < length; i++)
     {
         Point1 p = new Point1(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
示例#6
0
文件: Snake.cs 项目: lihac92/snake
        internal void Move()
        {
            Point1 tail = pList.First();

            pList.Remove(tail);
            Point1 head = GetNextPoint();

            pList.Add(head);

            tail.Clear();
            head.Draw();
        }
示例#7
0
文件: Snake.cs 项目: lihac92/snake
        internal bool Eat(Point1 food)
        {
            Point1 head = GetNextPoint();

            if (head.IsHit(food))
            {
                food.sym = head.sym;
                pList.Add(food);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#8
0
        static void Main(string[] args)
        {
            Console.SetWindowSize(1, 1);
            Console.SetBufferSize(80, 25);
            Console.SetWindowSize(80, 25);

            Walls walls = new Walls(80, 25);

            walls.Draw();

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

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point1      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);
                }
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            Point1 p1 = new Point1();

            p1.x   = 1;
            p1.y   = 3;
            p1.sym = '*';

            p1.Draw();

            Point1 p2 = new Point1();

            p2.x   = 4;
            p2.y   = 5;
            p2.sym = '#';

            p2.Draw();

            Console.ReadLine();
        }
示例#10
0
 public bool IsHit(Point1 p)
 {
     return(p.x == this.x && p.y == this.y);
 }
示例#11
0
 public Point1(Point1 p)
 {
     x   = p.x;
     y   = p.y;
     sym = p.sym;
 }