Exemple #1
0
        public IField SetSpawnPoint(IField field, IFieldPresentable fieldProperty)
        {
            var coord = GenerateSpawnPoint(field, fieldProperty);

            field.Contents[coord.CoordinateX, coord.CoordinateY] = fieldProperty.Body;
            return(field);
        }
Exemple #2
0
        public Coordinates Move(IField field, IFieldPresentable presentableObject, int stepsize)
        {
            var newCoords = GenerateNextMoveCoordinates(field, presentableObject, stepsize);

            field.Contents[presentableObject.CoordinateX, presentableObject.CoordinateY] = Settings.EmptyBlock;
            field.Contents[newCoords.CoordinateX, newCoords.CoordinateY] = presentableObject.Body;
            return(newCoords);
        }
Exemple #3
0
        private Coordinates GenerateSpawnPoint(IField field, IFieldPresentable fieldProperty)
        {
            int xPos;
            int yPos;

            do
            {
                xPos = _rand.Next(0, FieldDimensions.Width);
                yPos = _rand.Next(0, FieldDimensions.Height);
            } while (!IsSpawnTaken(field, xPos, yPos));
            fieldProperty.CoordinateX = xPos;
            fieldProperty.CoordinateY = yPos;
            return(new Coordinates(fieldProperty.CoordinateX, fieldProperty.CoordinateY));
        }
Exemple #4
0
        private Coordinates GenerateNextMoveCoordinates(IField field, IFieldPresentable presentableObject, int stepSize)
        {
            int moveToX, moveToY;
            int minRand = -stepSize;
            int maxRand = stepSize + 1;

            do
            {
                var offsetX = _rand.Next(minRand, maxRand);
                var offsetY = _rand.Next(minRand, maxRand);
                moveToX = presentableObject.CoordinateX + offsetX;
                moveToY = presentableObject.CoordinateY + offsetY;
            } while (!(_validator.CoordinatesAreValid(moveToX, moveToY) &&
                       field.Contents[moveToX, moveToY] == Settings.EmptyBlock));

            return(new Coordinates(moveToX, moveToY));
        }