Ejemplo n.º 1
0
        public bool Crash(Board Board, Point newHeadPosition)
        {
            if (Positions.Exists(point => point.X == newHeadPosition.X && point.Y == newHeadPosition.Y))
            {
                var tailPosition = Positions.Last();

                if (tailPosition.X == newHeadPosition.X && tailPosition.Y == newHeadPosition.Y)
                {
                    if (!Board.DidEat(newHeadPosition))
                    {
                        return false;
                    }
                }

                return true;
            }

            return false;
        }
Ejemplo n.º 2
0
        public void Tick(Board Board)
        {
            var newHeadPosition = new Point();
            switch (CurrentDirection)
            {
                case Direction.Up:
                    newHeadPosition = new Point(Positions[0].X, mod((int)Positions[0].Y - 1, Rows));
                    break;
                case Direction.Right:
                    newHeadPosition = new Point(mod((int)Positions[0].X + 1, Columns), Positions[0].Y);
                    break;
                case Direction.Down:
                    newHeadPosition = new Point(Positions[0].X, mod((int)Positions[0].Y + 1, Rows));
                    break;
                case Direction.Left:
                    newHeadPosition = new Point(mod((int)Positions[0].X - 1, Columns), Positions[0].Y);
                    break;
            }

            IsAlive = !Crash(Board, newHeadPosition);

            Positions.Insert(0, newHeadPosition);

            if (Board.DidEat(newHeadPosition))
            {
                Length++;
            }
            else
            {
                Positions.RemoveAt(Positions.Count - 1);
            }
        }