Guest User

Untitled

a guest
Jun 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. enum Tetrominoes {
  2. SBlock(new Point[]{new Point(-1,0), new Point(0,0), new Point(-2,1),
  3. new Point(-1,1)}),
  4. ZBlock(new Point[]{new Point(-2,0), new Point(-1,0), new Point(-1,1),
  5. new Point(0,1)}),
  6. JBlock(new Point[]{new Point(-2,0), new Point(-2,1), new Point(-1,1),
  7. new Point(0,1)}),
  8. LBlock(new Point[]{new Point(0,0), new Point(-2,1), new Point(-1,1),
  9. new Point(0,1)}),
  10. OBlock(new Point[]{new Point(-1,0), new Point(0,0), new Point(-1,1),
  11. new Point(0,1)}),
  12. TBlock(new Point[]{new Point(-1,0), new Point(-2,1), new Point(-1,1),
  13. new Point(0,1)}),
  14. IBlock(new Point[]{new Point(-2,0), new Point(-1,0), new Point(0,0),
  15. new Point(1,0)});
  16.  
  17. final Point[] relativeStartPos;
  18. Point[] relativeCurrPos;
  19.  
  20. private Tetrominoes(Point[] relativeStartPos) {
  21. this.relativeStartPos = relativeStartPos;
  22. relativeCurrPos = new Point[4];
  23. resetPos();
  24. }
  25.  
  26. void resetPos() {
  27. relativeCurrPos = relativeStartPos.clone();
  28. }
  29.  
  30. void down() {
  31. for(int i = 0; i < 4; i++) {
  32. (relativeCurrPos[i].y)++;
  33. }
  34. }
  35. }
  36.  
  37. // ArrayList declaration appearing earlier in code
  38. private ArrayList<Integer> randBag = new ArrayList<Integer>();
  39.  
  40. void selectBlock() {
  41. Tetrominoes[] tetro = Tetrominoes.values();
  42. if(randBag.isEmpty()) {
  43. Collections.addAll(randBag, 0, 1, 2, 3, 4, 5, 6);
  44. Collections.shuffle(randBag);
  45. }
  46. currentBlock = tetro[nextBlock.ordinal()];
  47. currentBlock.resetPos();
  48.  
  49. randBag.remove(0);
  50. if(randBag.isEmpty()) {
  51. Collections.addAll(randBag, 0, 1, 2, 3, 4, 5, 6);
  52. Collections.shuffle(randBag);
  53. }
  54. nextBlock = tetro[randBag.get(0)];
  55. nextBlock.resetPos();
  56. }
Add Comment
Please, Sign In to add comment