/// <summary> /// Initializes a new instance of the <see cref="GameBoardSquare"/> class. Throws InvalidGameBoardSquareConfigurationException. /// </summary> /// <param name="coordinateX">The private member coordinateX will be set to this value (must be from 0 - 14).</param> /// <param name="coordinateY">The private member coordinateY will be set to this value (must be from 0 - 14).</param> /// <param name="wordMultiplier">The private member wordMultiplier will be set to this value (must be from 1 - 3, /// and must be 1 if letterMultiplier is not 1).</param> /// <param name="letterMultiplier">The private member letterMultiplier will be set to this value (must be from 1 - 3, /// and must be 1 if wordMultiplier is not 1).</param> public GameBoardSquare(int coordinateX, int coordinateY, int wordMultiplier, int letterMultiplier) { if (coordinateX >= 0 && coordinateX < 15) { this.coordinateX = coordinateX; } else { InvalidGameBoardSquareConfigurationException invalidSquare = new InvalidGameBoardSquareConfigurationException("coordinateX set to " + coordinateX.ToString()); throw invalidSquare; } if (coordinateY >= 0 && coordinateY < 15) { this.coordinateY = coordinateY; } else { InvalidGameBoardSquareConfigurationException invalidSquare = new InvalidGameBoardSquareConfigurationException("coordinateY set to " + coordinateY.ToString()); throw invalidSquare; } this.isStartSquare = this.coordinateX == 7 && this.coordinateY == 7; if (wordMultiplier != 1 && letterMultiplier != 1) { InvalidGameBoardSquareConfigurationException invalidSquare = new InvalidGameBoardSquareConfigurationException("wordMultiplier = " + wordMultiplier.ToString() + ", and letterMultiplier = " + letterMultiplier.ToString()); throw invalidSquare; } if (wordMultiplier < 1 || wordMultiplier > 3) { InvalidGameBoardSquareConfigurationException invalidSquare = new InvalidGameBoardSquareConfigurationException("wordMultiplier out of bounds (wordMultiplier = " + wordMultiplier.ToString() + ")"); throw invalidSquare; } if (letterMultiplier < 1 || letterMultiplier > 3) { InvalidGameBoardSquareConfigurationException invalidSquare = new InvalidGameBoardSquareConfigurationException("letterMultiplier out of bounds (wordMultiplier = " + letterMultiplier.ToString() + ")"); throw invalidSquare; } this.wordMultiplier = wordMultiplier; this.letterMultiplier = letterMultiplier; this.containedTile = new LetterTile('n', 0); }
/// <summary> /// Removes the contained letter tile from the GameBoardSquare, and returns it. /// </summary> /// <returns>The LetterTile contained in the GameBoardSquare</returns> public LetterTile RemoveLetterTile() { if (this.containedTile.IsNullLetterTile()) { InvalidGameBoardSquareConfigurationException invalidGameBoardSquareConfiguration = new InvalidGameBoardSquareConfigurationException("Invalid removal of LetterTile from an already empty GameBoardSquare object."); throw invalidGameBoardSquareConfiguration; } else { LetterTile letterTileToBeReturned = this.containedTile; this.containedTile = new LetterTile('n', 0); return letterTileToBeReturned; } }
/// <summary> /// Inserts a LetterTile object into the GameBoardSquare, unless the GameBoardSquare already contains a LetterTile. /// Then it throw an InvalidGameBoardSquareConfigurationException. /// </summary> /// <param name="letterTileToBeInserted">The letter tile that is being inserted into the GameBoardSquare.</param> public void InsertLetterTile(LetterTile letterTileToBeInserted) { if (this.IsEmpty()) { this.containedTile = letterTileToBeInserted; } else { InvalidGameBoardSquareConfigurationException invalidGameBoardSquareConfiguration = new InvalidGameBoardSquareConfigurationException("Invalid insertion of LetterTile object into GameBoardSquareObject."); throw invalidGameBoardSquareConfiguration; } }