/// <summary>
 /// Get a random Vertical Direction value (Up or Down).
 /// </summary>
 /// <returns>Direction value</returns>
 public static Direction GetRandomVerticalDirection()
 {
     // Will give values 0-1 inclusive; we don't want 2, 3, 4.
     return(DirectionUtils.GetRandomDirection(0, 2));
 }
 /// <summary>
 /// Get a random Direction value that isn't Direction.Random.
 /// </summary>
 /// <returns>Direction value</returns>
 public static Direction GetRandomDirection()
 {
     // Will give values 0-3 inclusive; we don't want 4 (random)
     return(DirectionUtils.GetRandomDirection(0, 4));
 }
 /// <summary>
 /// Get a random Horizontal Direction value (Left or Right).
 /// </summary>
 /// <returns>Direction value</returns>
 public static Direction GetRandomHorizontalDirection()
 {
     // Will give values 2-3 inclusive; we don't want 0, 1, 4.
     return(DirectionUtils.GetRandomDirection(2, 4));
 }
        /// <summary>
        /// Spawn a new MovableObject on the board.
        /// </summary>
        private void Spawn()
        {
            // Determine movement direction of the new MovableObject
            Direction objectMovementDirection = this.SpawnDirection;

            if (objectMovementDirection == Direction.Random)
            {
                objectMovementDirection = DirectionUtils.GetRandomDirection();
            }

            // Determine the turning direction of the new MovableObject
            Direction objectTurnDirection = GameSettings.TurnDirection;

            if (objectTurnDirection == Direction.Random)
            {
                objectTurnDirection = DirectionUtils.GetRandomHorizontalDirection();
            }

            // Calculate the starting cell based on the movement direction
            int objectStartCol = this.CellCol;
            int objectStartRow = this.CellRow;

            switch (objectMovementDirection)
            {
            case Direction.Up:
                objectStartRow--;
                break;

            case Direction.Down:
                objectStartRow++;
                break;

            case Direction.Right:
                objectStartCol++;
                break;

            case Direction.Left:
                objectStartCol--;
                break;

            default:
                throw new Exception(String.Format("Spawner is using an unknown or invalid Direction value: {0}", objectMovementDirection));
            }

            // Determine if this is a positive or negative object
            int objectScore = GameSettings.ObjectScore;

            if (GameSettings.RANDOM.NextDouble() <= GameSettings.ProbabilityOfNegativeSpawn)
            {
                objectScore = GameSettings.NegativeObjectScore;
            }

            MovableObject newObject = new MovableObject(objectStartCol, objectStartRow, objectMovementDirection, objectTurnDirection, objectScore, GameSettings.CellsPerMove);

            if (this.ObjectSpawnedHandler != null)
            {
                this.ObjectSpawnedHandler(newObject, null);
            }

            this.SpawnedObjects.Add(newObject);
        }