summaryrefslogtreecommitdiff
path: root/src/tetris/audio/TetrisSounds.java
blob: b28e49a5a83bfba553b006429880e67a193416f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Jesse Morgan <jesterpm@u.washington.edu>
 * 
 * TCSS 305 - Autumn 2009
 * Tetris Project
 * 17 November 2009
 */

package tetris.audio;

import java.util.Observable;
import java.util.Observer;

import tetris.board.TetrisBoardEvent;


/**
 * Class to play sounds for a tetris game.
 * 
 * @author Jesse Morgan <jesterpm@u.washington.edu>
 * @version 1.0 23 November 2009
 */
public class TetrisSounds implements Observer {
  // Private fields.
  /**
   * The SoundPlayer.
   */
  private final SoundPlayer my_soundplayer;
  
  /**
   * Create a Tetris Sound Effects player.
   */
  public TetrisSounds() {
    my_soundplayer = new SoundPlayer();
  }

  /**
   * Handle notifications.
   * 
   * @param the_observable The TetrisBoard.
   * @param the_arg The Event.
   */
  public void update(final Observable the_observable, final Object the_arg) {
    if (the_arg instanceof TetrisBoardEvent) {
      final TetrisBoardEvent event = (TetrisBoardEvent) the_arg;
      
      try {
        switch (event.getType()) {
          case NEW_GAME:
            my_soundplayer.play("tetris/audio/pencilsharpen.aif");
            break;
            
          case LINES_CLEARED:
            my_soundplayer.play("tetris/audio/pencileraser.wav");
            break;
            
          case GAME_OVER:
            my_soundplayer.play("tetris/audio/papercrumple.wav");
            break;
            
          default:
        }
        
      } catch (final IllegalArgumentException the_exception) {
        // Couldn't play for some reason...
        // Sounds aren't important anyways, gracefully ignore
        return;
      }
    }
  }
  
  
}