summaryrefslogtreecommitdiff
path: root/src/tetris/piece/TetrisPieces.java
blob: 642be97bd457b42e6b307b00325e0401aa7e74f5 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Jesse Morgan <jesterpm@u.washington.edu>
 * 
 * TCSS 305 Ð Autumn 2009
 * Tetris Project
 * 17 November 2009
 */

package tetris.piece;

import java.util.Random;

/**
 * Enumeration of the various tetris pieces.
 * 
 * @author Jesse Morgan <jesterpm@u.washington.edu>
 * @version 1.0 23 November 2009
 */
public enum TetrisPieces {
  // Enumeration definition.
  /**
   * The I Piece.
   */
  I_PIECE,
  
  /**
   * The J Piece.
   */
  J_PIECE,
  
  /**
   * The L Piece.
   */
  L_PIECE,
  
  /**
   * The O Piece.
   */
  O_PIECE,
  
  /**
   * The S Piece.
   */
  S_PIECE,
  
  /**
   * The T Piece.
   */
  T_PIECE,
  
  /**
   * The Z Piece.
   */
  Z_PIECE;
  
  // Private Constants
  /**
   * A Random that we use for generating random pieces.
   */
  private static final Random RANDOM = new Random();
  
  /**
   * @param the_x X coordinate for this piece.
   * @param the_y Y coordinate for this piece.
   * @return a random tetris piece.
   */
  public static TetrisPiece getRandomPiece(final int the_x, final int the_y) {
    TetrisPiece piece;
   
    switch (values()[RANDOM.nextInt(values().length)]) {
      case I_PIECE:
        piece = new IPiece(the_x, the_y);
        break;
     
      case J_PIECE:
        piece = new JPiece(the_x, the_y);
        break;
      
      case L_PIECE:
        piece = new LPiece(the_x, the_y);
        break;
      
      case O_PIECE:
        piece = new OPiece(the_x, the_y);
        break;
      
      case S_PIECE:
        piece = new SPiece(the_x, the_y);
        break;
      
      case T_PIECE:
        piece = new TPiece(the_x, the_y);
        break;
      
      case Z_PIECE:
      default: // This is a fail-safe should something very bizarre happen.
        piece = new ZPiece(the_x, the_y);
        break;
    }
    
    return piece;
  }
}