Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import greenfoot.World;
  2.  
  3. /**
  4. * Write a description of class TPiece here.
  5. *
  6. * @author (your name)
  7. * @version (a version number or a date)
  8. */
  9. @SuppressWarnings("UnusedAssignment")
  10. public class TPiece implements Piece{
  11. // instance variables - replace the example below with your own
  12. private Blue[] pieces = new Blue[4];
  13. private int rotation = 0;
  14.  
  15. /**
  16. * Constructor for objects of class TPiece
  17. */
  18. public TPiece(World w){
  19. for (int i = 0; i < pieces.length; i++) {
  20. if (i != 3){
  21. pieces[i] = new Blue(this, 1);
  22. } else pieces[i] = new Blue(this);
  23. }
  24. w.addObject(pieces[0], 3, 0);
  25. w.addObject(pieces[1], 4, 0);
  26. w.addObject(pieces[2], 5, 0);
  27. w.addObject(pieces[3], 4, 1);
  28. }
  29.  
  30.  
  31. @Override
  32. public void stop() {
  33. for (Blue b : pieces){
  34. b.stop();
  35. }
  36. }
  37.  
  38. /**
  39. * The Method for rotating the piece
  40. */
  41. public void rotate(){
  42. Blue blue;
  43. switch (rotation){
  44. case 0:
  45. blue = (Blue) pieces[1].getWorld(). //Gigantic, any idea to short it?
  46. getObjectsAt(pieces[1].getX() - 1, pieces[1].getY(), null).get(0);
  47. blue.setLocation(blue.getX() + 1, blue.getY() - 1);
  48. rotation = 90;
  49. blue = null;
  50. break;
  51. case 90:
  52. blue = (Blue) pieces[1].getWorld(). //Gigantic, any idea to short it?
  53. getObjectsAt(pieces[1].getX(), pieces[1].getY() - 1, Blue.class).get(0);
  54. blue.setLocation(blue.getX() - 1, blue.getY() - 1);
  55. for(int i = 0; i < 4; i++){
  56. if (pieces[i] == blue){
  57. continue;
  58. }
  59. pieces[i].addStep(1);
  60. }
  61. rotation = 180;
  62. blue = null;
  63. break;
  64. case 180:
  65. blue = pieces[2];
  66. blue.setLocation(blue.getX() -1, blue.getY() + 1);
  67. //GENIUS!!!!
  68. for(int i = 1; i < 4; i++){
  69. //pieces[i].removeStep(1);
  70. }
  71. rotation = 270;
  72. blue = null;
  73. break;
  74. case 270:
  75. blue = pieces[0];
  76. blue.setLocation(blue.getX() + 1, blue.getY() + 1);
  77. rotation = 0;
  78. blue = null;
  79. break;
  80. }
  81. // put your code here
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement