# Class ShieldGenerator

java.lang.Object
it.polimi.ingsw.is25am31.model.components.Component
it.polimi.ingsw.is25am31.model.components.ShieldGenerator

All Implemented Interfaces:
  `Serializable`

public class ShieldGenerator extends Component
Represents a shield generator component that can protect specific sides of the spaceship. The shield generator can be activated for one-time use and its orientation can be changed to protect different sides of the ship.

See Also:
  - Serialized Form

- ## Field Summary

  ### Fields inherited from class it.polimi.ingsw.is25am31.model.components.Component

  `connector, id, name, orientation, x, y`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ShieldGenerator(int id, String name, Map<Side,Connector> connector, Side orientation, OrientationShield orientationShield)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `activate()`
  Activates the shield generator, making it ready for one-time use.
  `static String`
  `center(String text, int width)`
  Centers a string within a specified width by adding spaces on both sides.
  `String[]`
  `getAsciiArt()`
  Generates an ASCII art representation of the shield generator component.
  `OrientationShield`
  `getOrientationShield()`
  Gets the current orientation of the shield protection.
  `boolean`
  `isActive()`
  Checks if the shield generator is currently active and automatically deactivates it.
  `OrientationShield`
  `protectedSides()`
  Gets the sides protected by this shield generator.
  `void`
  `setOrientationShield()`
  Cycles the shield orientation to the next configuration.

  ### Methods inherited from class it.polimi.ingsw.is25am31.model.components.Component

  `addContains, calculateFirePower, calculateThrust, getAlienColor, getCapacity, getConnector, getConnectors, getContains, getCrewMembers, getCurrentAlien, getId, getMaxGoodValue, getName, getOrientation, getPower, getX, getY, isAlienLifeSupport, isAlienStructural, modifyCapacity, modifyCrewMembers, modifyOrientation, removeContains, setX, setY`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ShieldGenerator

    public ShieldGenerator(int id, String name, Map<Side,Connector> connector, Side orientation, OrientationShield orientationShield)

- ## Method Details

  - ### protectedSides

    public OrientationShield protectedSides()
    Gets the sides protected by this shield generator.
    Overrides:
      `protectedSides` in class `Component`
    Returns:
      the orientation configuration indicating which sides are protected

  - ### isActive

    public boolean isActive()
    Checks if the shield generator is currently active and automatically deactivates it. This method implements a one-time use mechanism where checking the status consumes the activation.
    Overrides:
      `isActive` in class `Component`
    Returns:
      `true` if the shield was active (and is now deactivated), `false` if it was already inactive

  - ### activate

    public void activate()
    Activates the shield generator, making it ready for one-time use.
    Overrides:
      `activate` in class `Component`

  - ### setOrientationShield

    public void setOrientationShield()
    Cycles the shield orientation to the next configuration. The orientation cycles through all available OrientationShield enum values.
    Overrides:
      `setOrientationShield` in class `Component`

  - ### getOrientationShield

    public OrientationShield getOrientationShield()
    Gets the current orientation of the shield protection.
    Overrides:
      `getOrientationShield` in class `Component`
    Returns:
      the current shield orientation configuration

  - ### getAsciiArt

    public String[] getAsciiArt()
    Generates an ASCII art representation of the shield generator component. The representation shows the shield direction based on the component's orientation.
    Overrides:
      `getAsciiArt` in class `Component`
    Returns:
      an array of strings representing the ASCII art, with each string being one line

  - ### center

    public static String center(String text, int width)
    Centers a string within a specified width by adding spaces on both sides.
    Parameters:
      `text` - the string to center
      `width` - the total width in which to center the string
    Returns:
      the centered string with padding spaces, or the original string if it's already wider than the specified width