Esempio n. 1
0
File: Snake.cs Progetto: MIDgar/t
        public ClassPoint GetNextPoint()
        {
            ClassPoint head      = pList.Last();
            ClassPoint nextPoint = new ClassPoint(head);

            nextPoint.Move(1, direction);
            return(nextPoint);
        }
Esempio n. 2
0
File: VLine.cs Progetto: MIDgar/t
 public VLine(int yTop, int yBottom, int x, char ch)
 {
     pList = new List <ClassPoint>();
     for (int y = yTop; y <= yBottom; y++)
     {
         ClassPoint p = new ClassPoint(x, y, ch);
         pList.Add(p);
     }
 }
Esempio n. 3
0
 public HLine(int xLeft, int xRight, int y, char ch)
 {
     pList = new List <ClassPoint>();
     for (int x = xLeft; x <= xRight; x++)
     {
         ClassPoint p = new ClassPoint(x, y, ch);
         pList.Add(p);
     }
 }
Esempio n. 4
0
 public bool IsHit(ClassPoint point)
 {
     foreach (var p in pList)
     {
         if (p.IsHit(point))
         {
             return(true);
         }
     }
     return(false);
 }
Esempio n. 5
0
File: Snake.cs Progetto: MIDgar/t
 public Snake(ClassPoint tail, int lenght, Direction _direction)
 {
     direction = _direction;
     pList     = new List <ClassPoint>();
     for (int i = 0; i < lenght; i++)
     {
         ClassPoint p = new ClassPoint(tail);
         p.Move(i, direction);
         pList.Add(p);
     }
 }
Esempio n. 6
0
File: Snake.cs Progetto: MIDgar/t
        internal void Move()
        {
            ClassPoint tail = pList.First();

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

            pList.Add(head);

            tail.Clear();
            head.pointDraw();
        }
Esempio n. 7
0
File: Snake.cs Progetto: MIDgar/t
        internal bool Eat(ClassPoint food)
        {
            ClassPoint head = GetNextPoint();

            if (head.IsHit(food))
            {
                food.ch = head.ch;
                pList.Add(food);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);
            Walls walls = new Walls(80, 25);

            walls.Draw();

            ClassPoint p = new ClassPoint(2, 4, '*');

            Snake snake = new Snake(p, 3, Direction.DOWN);

            snake.Draw();

            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            ClassPoint  food        = foodCreator.CreateFood();

            food.pointDraw();

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    By bye = new By();
                    bye.SayBy();
                    break;
                }

                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    food.pointDraw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(100);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }

            Console.ReadKey();
        }
Esempio n. 9
0
 public bool IsHit(ClassPoint p)
 {
     return(p.x == this.x && p.y == this.y);
 }
Esempio n. 10
0
 public ClassPoint(ClassPoint p)
 {
     x  = p.x;
     y  = p.y;
     ch = p.ch;
 }