Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- enum Tetrominoes {
- SBlock(new Point[]{new Point(-1,0), new Point(0,0), new Point(-2,1),
- new Point(-1,1)}),
- ZBlock(new Point[]{new Point(-2,0), new Point(-1,0), new Point(-1,1),
- new Point(0,1)}),
- JBlock(new Point[]{new Point(-2,0), new Point(-2,1), new Point(-1,1),
- new Point(0,1)}),
- LBlock(new Point[]{new Point(0,0), new Point(-2,1), new Point(-1,1),
- new Point(0,1)}),
- OBlock(new Point[]{new Point(-1,0), new Point(0,0), new Point(-1,1),
- new Point(0,1)}),
- TBlock(new Point[]{new Point(-1,0), new Point(-2,1), new Point(-1,1),
- new Point(0,1)}),
- IBlock(new Point[]{new Point(-2,0), new Point(-1,0), new Point(0,0),
- new Point(1,0)});
- final Point[] relativeStartPos;
- Point[] relativeCurrPos;
- private Tetrominoes(Point[] relativeStartPos) {
- this.relativeStartPos = relativeStartPos;
- relativeCurrPos = new Point[4];
- resetPos();
- }
- void resetPos() {
- relativeCurrPos = relativeStartPos.clone();
- }
- void down() {
- for(int i = 0; i < 4; i++) {
- (relativeCurrPos[i].y)++;
- }
- }
- }
- // ArrayList declaration appearing earlier in code
- private ArrayList<Integer> randBag = new ArrayList<Integer>();
- void selectBlock() {
- Tetrominoes[] tetro = Tetrominoes.values();
- if(randBag.isEmpty()) {
- Collections.addAll(randBag, 0, 1, 2, 3, 4, 5, 6);
- Collections.shuffle(randBag);
- }
- currentBlock = tetro[nextBlock.ordinal()];
- currentBlock.resetPos();
- randBag.remove(0);
- if(randBag.isEmpty()) {
- Collections.addAll(randBag, 0, 1, 2, 3, 4, 5, 6);
- Collections.shuffle(randBag);
- }
- nextBlock = tetro[randBag.get(0)];
- nextBlock.resetPos();
- }
Add Comment
Please, Sign In to add comment