package com.google.code.tretris.common;
import java.util.HashMap;
public class Tetromino {
public final char letter;
public final int code ;
public final int width ;
public final int[][][] rotationmasks ;
public static Tetromino getFromChar(char ch) {
if (ch == 'I') return I ;
if (ch == 'J') return J ;
if (ch == 'L') return L ;
if (ch == 'O') return O ;
if (ch == 'S') return S ;
if (ch == 'T') return T ;
if (ch == 'Z') return Z ;
throw new IllegalArgumentException("No tetromino matches character: " + ch ) ;
}
private Tetromino(final char letter, final int code, final int width, final int[][][] rotationmasks) {
this.letter = letter;
this.code = code ;
this.width = width ;
this.rotationmasks = rotationmasks ;
}
@Override
public String toString() {
StringBuffer buffer = new StringBuffer("Tetromino ") ;
buffer.append(letter) ;
buffer.append("\n") ;
for (int n=0; n<4; n++) {
for (int y=0; y<width; y++) {
for (int x=0; x<width; x++) {
buffer.append(rotationmasks[n][x][y]) ;
}
buffer.append("\n") ;
}
buffer.append("\n") ;
}
return buffer.toString() ;
}
public static final Tetromino I = new Tetromino('I', 0, 4, new int[][][]
{
{
{0,0,0,0},
{1,1,1,1},
{0,0,0,0},
{0,0,0,0},
},
{
{0,0,1,0},
{0,0,1,0},
{0,0,1,0},
{0,0,1,0},
},
{
{0,0,0,0},
{0,0,0,0},
{1,1,1,1},
{0,0,0,0},
},
{
{0,1,0,0},
{0,1,0,0},
{0,1,0,0},
{0,1,0,0}
}
}
) ;
public static final Tetromino J = new Tetromino('J', 1, 3, new int[][][]
{
{
{1,0,0},
{1,1,1},
{0,0,0}
},
{
{0,1,1},
{0,1,0},
{0,1,0}
},
{
{0,0,0},
{1,1,1},
{0,0,1}
},
{
{0,1,0},
{0,1,0},
{1,1,0}
}
}
) ;
public static final Tetromino L = new Tetromino('L', 2, 3, new int[][][]
{
{
{0,0,1},
{1,1,1},
{0,0,0}
},
{
{0,1,0},
{0,1,0},
{0,1,1}
},
{
{0,0,0},
{1,1,1},
{1,0,0}
},
{
{1,1,0},
{0,1,0},
{0,1,0}
}
}
) ;
public static final Tetromino O = new Tetromino('O', 3, 2, new int[][][]
{
{
{1,1},
{1,1}
},
{
{1,1},
{1,1}
},
{
{1,1},
{1,1}
},
{
{1,1},
{1,1}
}
}
) ;
public static final Tetromino S = new Tetromino('S', 4, 3, new int[][][]
{
{
{0,1,1},
{1,1,0},
{0,0,0}
},
{
{0,1,0},
{0,1,1},
{0,0,1}
},
{
{0,0,0},
{0,1,1},
{1,1,0}
},
{
{1,0,0},
{1,1,0},
{0,1,0}
}
}
) ;
public static final Tetromino T = new Tetromino('T', 5, 3, new int[][][]
{
{
{0,1,0},
{1,1,1},
{0,0,0}
},
{
{0,1,0},
{0,1,1},
{0,1,0}
},
{
{0,0,0},
{1,1,1},
{0,1,0}
},
{
{0,1,0},
{1,1,0},
{0,1,0}
}
}
) ;
public static final Tetromino Z = new Tetromino('Z', 6, 3, new int[][][]
{
{
{1,1,0},
{0,1,1},
{0,0,0}
},
{
{0,0,1},
{0,1,1},
{0,1,0}
},
{
{0,0,0},
{1,1,0},
{0,1,1}
},
{
{0,1,0},
{1,1,0},
{1,0,0}
}
}
) ;
public static final HashMap<Integer, float[]> COLORS = new HashMap<Integer, float[]>() {
private static final long serialVersionUID = 1L;
{
put(I.code, new float[] {0f, 1.0f, 1.0f, 1f});
put(J.code, new float[] {0f, 0f, 1.0f, 1f});
put(L.code, new float[] {1f, 165f/255f, 0f, 1f});
put(O.code, new float[] {1.0f, 1.0f, 0f, 1f});
put(S.code, new float[] {127f/255f, 1.0f, 0.0f, 1f});
put(T.code, new float[] {160f/255f, 32f/255f, 240f/255f, 1f});
put(Z.code, new float[] {1.0f, 0f, 0f, 1f});
}
};
}
|