Enum SoundFile

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<SoundFile>

    public enum SoundFile
    extends java.lang.Enum<SoundFile>
    A sound file that is loaded once and can be played multiple times consecutively using the play() method.

    For this system, enum variants are used. Each variant represents a sound file that is preloaded and can be played at any time. This is done to avoid the overhead of loading the sound file every time it is played. It also neatly prevents overlap as the sound file is simply restarted if it is already playing.

    Due to the static nature of the enum, it can be used from anywhere in the codebase without the need to pass around instances of the sound files.

    All sound files were created by Luna Otte and Juno Veenstra as part of the game's development.

    Author:
    Luna Otte
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      BGM_GAME_OVER
      Background music of the game over screen.
      BGM_MAIN
      Background music of the game.
      BGM_WE_KNOW_WHAT_YOU_DID
      Background music of the "Cheated Detected" screen.
      CLICK
      For basic successful UI interactions.
      CONSTRUCT
      For constructing a cable.
      EMPTY
      For UI interactions that are canceled.
      ERROR
      For UI interactions that result in an error.
      LAST_ROUND
      For when the last round commences.
      OPEN
      For UI interactions where a menu or pop-up is opened.
      REJECT
      For unsuccessful UI interactions.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void loop()
      Loops the SoundFile infinitely.
      void play()
      Plays the SoundFile.
      static void setMainVolume​(float volume)
      Sets the volume that all SoundFile instances will be played at.
      void setVolume​(float volume)
      Sets the volume that the SoundFile will be played at.
      void stop()
      Stops the SoundFile.
      static SoundFile valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static SoundFile[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • CLICK

        public static final SoundFile CLICK
        For basic successful UI interactions.
      • CONSTRUCT

        public static final SoundFile CONSTRUCT
        For constructing a cable.
      • EMPTY

        public static final SoundFile EMPTY
        For UI interactions that are canceled.
      • ERROR

        public static final SoundFile ERROR
        For UI interactions that result in an error.
      • LAST_ROUND

        public static final SoundFile LAST_ROUND
        For when the last round commences.
      • OPEN

        public static final SoundFile OPEN
        For UI interactions where a menu or pop-up is opened.
      • REJECT

        public static final SoundFile REJECT
        For unsuccessful UI interactions.
      • BGM_MAIN

        public static final SoundFile BGM_MAIN
        Background music of the game.
      • BGM_GAME_OVER

        public static final SoundFile BGM_GAME_OVER
        Background music of the game over screen.
      • BGM_WE_KNOW_WHAT_YOU_DID

        public static final SoundFile BGM_WE_KNOW_WHAT_YOU_DID
        Background music of the "Cheated Detected" screen.
    • Method Detail

      • values

        public static SoundFile[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (SoundFile c : SoundFile.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static SoundFile valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • setMainVolume

        public static void setMainVolume​(float volume)
        Sets the volume that all SoundFile instances will be played at.
        Parameters:
        volume - The volume, as a linear gain ratio between 0.0 and 1.0
      • setVolume

        public void setVolume​(float volume)
        Sets the volume that the SoundFile will be played at.
        Parameters:
        volume - The volume, as a linear gain ratio between 0.0 and 1.0
      • play

        public void play()
        Plays the SoundFile.

        If called on a playing SoundFile, this method will simply restart it. Thus, a single SoundFile never overlaps with, or waits for itself.

      • stop

        public void stop()
        Stops the SoundFile.
      • loop

        public void loop()
        Loops the SoundFile infinitely.