예제 #1
0
        private void PlaceFood()
        {
            TwoDPoint fp = RandomPoint(_emptyTiles);

            _field[fp.X, fp.Y] = Tile.food;
            _emptyTiles.Remove(fp);

            _food.Add(fp);
        }
예제 #2
0
        public override bool Equals(object obj)
        {
            if (obj == null || obj.GetType() != this.GetType())
            {
                return(false);
            }

            // If parameter cannot be cast to Point return false.
            TwoDPoint p = (TwoDPoint)obj;

            return(X == p.X && Y == p.Y);
        }
예제 #3
0
        private void PlaceSnake()
        {
            _nextPos = RandomPoint(_emptyTiles);

            _snake = new Snake(_nextPos);

            DrawSnakeHeadOnTiles();

            for (int i = 0; i < SnakeStartingLength - 1; i++)
            {
                _nextPos = RandomPoint(GetAdjacent(_nextPos));
                _snake.Grow(_nextPos);
                DrawSnakeHeadOnTiles();
            }
        }
예제 #4
0
        void MoveTo(TwoDPoint p)
        {
            if (_food.Contains(p))
            {
                _snake.Grow(p);
                _score++;
                _food.Remove(p);
            }
            else
            {
                _emptyTiles.Remove(p);
                _field[_snake.Tail.X, _snake.Tail.Y] = Tile.empty;
                _emptyTiles.Add(_snake.Tail);
                _snake.Move(p);
            }

            _field[p.X, p.Y] = Tile.snake;
        }
예제 #5
0
 private bool isInvalid(TwoDPoint p)
 {
     return(p.X < 0 || p.Y < 0 || p.X >= Width || p.Y >= Height);
 }
예제 #6
0
 private IEnumerable <TwoDPoint> GetAdjacent(TwoDPoint point)
 {
     return(_emptyTiles.Where(p => p.ManhattanDistance(point) == 1));
 }
예제 #7
0
파일: Snake.cs 프로젝트: Mawrte/snakeNEAT
        //public void UnGrow()
        //{
        //    _points.RemoveAt(_points.Count - 1);
        //}

        public void Move(TwoDPoint p)
        {
            _points.Dequeue();
            _points.Enqueue(p);
        }
예제 #8
0
파일: Snake.cs 프로젝트: Mawrte/snakeNEAT
 public void Grow(TwoDPoint p)
 {
     _points.Enqueue(p);
 }
예제 #9
0
파일: Snake.cs 프로젝트: Mawrte/snakeNEAT
        public Snake(int x, int y)
        {
            TwoDPoint starting = new TwoDPoint(x, y);

            _points.Enqueue(starting);
        }
예제 #10
0
파일: Snake.cs 프로젝트: Mawrte/snakeNEAT
 public Snake(TwoDPoint starting)
 {
     _points.Enqueue(starting);
 }
예제 #11
0
파일: Snake.cs 프로젝트: Mawrte/snakeNEAT
        //readonly List<TwoDPoint> _points = new List<TwoDPoint>();

        public Snake()
        {
            TwoDPoint p = new TwoDPoint(0, 0);

            _points.Enqueue(p);
        }
예제 #12
0
 public bool Equals(TwoDPoint p)
 {
     return(X == p.X && Y == p.Y);
 }
예제 #13
0
 internal int ManhattanDistance(TwoDPoint p)
 {
     return(Math.Abs(_x - p.X) + Math.Abs(_y - p.Y));
 }