From 87e98e00e0ca5ac4229091aa9bb0e5c09093f50f Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 13 Dec 2012 22:14:24 -0800 Subject: Tetris project from TCSS305 class. Original project was in SVN on the school servers, so the versioning history is gone. --- src/tetris/piece/TetrisPieces.java | 103 +++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/tetris/piece/TetrisPieces.java (limited to 'src/tetris/piece/TetrisPieces.java') diff --git a/src/tetris/piece/TetrisPieces.java b/src/tetris/piece/TetrisPieces.java new file mode 100644 index 0000000..642be97 --- /dev/null +++ b/src/tetris/piece/TetrisPieces.java @@ -0,0 +1,103 @@ +/* + * Jesse Morgan + * + * 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 + * @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; + } +} -- cgit v1.2.3