Advertisement
Guest User

OO BACKUP

a guest
Feb 27th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.51 KB | None | 0 0
  1. package oo15loipe;
  2.  
  3. public class Loipe implements InfoLoipe{
  4.  
  5. private String pad;
  6. private Richting richting;
  7. private int width,height,startX,startY;
  8. private Fragment [][] loipe;
  9.  
  10. public Loipe (String pad) {
  11. this.pad = pad;
  12. richting = Richting.N;
  13. vindAfmetingen();
  14. richting = Richting.N;
  15. loipe = new Fragment[width][height];
  16. emptyLoipe ();
  17. fillLoipe ();
  18.  
  19. }
  20.  
  21. public void vindAfmetingen () {
  22. int currentX = 0, currentY = 0, minX=0,minY=0,maxX=0,maxY=0;
  23.  
  24. for (int i = 0; i < pad.length(); i++) {
  25. switch (richting) {
  26. case N:
  27. switch (pad.charAt(i)) {
  28. case 's':
  29. currentY--;
  30. break;
  31. case 'l':
  32. richting=richting.turnLeft();
  33. currentX--;
  34. break;
  35. default:
  36. richting=richting.turnRight();
  37. currentX++;
  38. break;
  39. }break;
  40. case O:
  41. switch (pad.charAt(i)) {
  42. case 's':
  43. currentX++;
  44. break;
  45. case 'l':
  46. richting=richting.turnLeft();
  47. currentY--;
  48. break;
  49. default:
  50. richting=richting.turnRight();
  51. currentY++;;
  52. break;
  53. }break;
  54. case Z:
  55. switch (pad.charAt(i)) {
  56. case 's':
  57. currentY++;
  58. break;
  59. case 'l':
  60. richting=richting.turnLeft();
  61. currentX++;
  62. break;
  63. default:
  64. richting=richting.turnRight();
  65. currentX--;
  66. break;
  67. }break;
  68. default:
  69. switch (pad.charAt(i)) {
  70. case 's':
  71. currentX--;
  72. break;
  73. case 'l':
  74. richting=richting.turnLeft();
  75. currentY++;
  76. break;
  77. default:
  78. richting=richting.turnRight();
  79. currentY--;
  80. break;
  81. }break;
  82. }
  83. if (currentY > maxY) {maxY=currentY;}
  84. if (currentY < minY) {minY=currentY;}
  85. if (currentX > maxX) {maxX=currentX;}
  86. if (currentX < minX) {minX=currentX;}
  87. }
  88.  
  89. width = Math.abs(maxX-minX)+1;
  90. height = Math.abs(maxY-minY)+1;
  91. startX = Math.abs(minX);
  92. startY = Math.abs(minY);
  93.  
  94. System.out.println(width + " " + height + " " + startX + " " + startY);
  95.  
  96. }
  97.  
  98. public void emptyLoipe () {
  99. for (int i = 0; i < height; i++) {
  100. for (int j = 0; j < width; j++) {
  101. loipe [j][i] = Fragment.EM;
  102. }
  103. }
  104. }
  105.  
  106. public void fillLoipe () {
  107. int currentX = startX, currentY = startY;
  108. for (int i = 0; i < pad.length(); i++) {
  109. switch (richting) {
  110. case N:
  111. switch (pad.charAt(i)) {
  112. case 's':
  113. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NZ;}
  114. else {loipe[currentX][currentY] = Fragment.KR;}
  115. currentY--;
  116. break;
  117. case 'l':
  118. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.ZW;}
  119. else {loipe[currentX][currentY] = Fragment.KR;}
  120. currentX--;
  121. richting = richting.turnLeft();
  122. break;
  123. default:
  124. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.ZO;}
  125. else {loipe[currentX][currentY] = Fragment.KR;}
  126. currentX++;
  127. richting = richting.turnRight();
  128. break;
  129. }break;
  130. case O:
  131. switch (pad.charAt(i)) {
  132. case 's':
  133. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.OW;}
  134. else {loipe[currentX][currentY] = Fragment.KR;}
  135. currentX++;
  136. break;
  137. case 'l':
  138. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NW;}
  139. else {loipe[currentX][currentY] = Fragment.KR;}
  140. currentY--;
  141. richting = richting.turnLeft();
  142. break;
  143. default:
  144. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.ZW;}
  145. else {loipe[currentX][currentY] = Fragment.KR;}
  146. currentY++;
  147. richting = richting.turnRight();
  148. break;
  149. }break;
  150. case Z:
  151. switch (pad.charAt(i)) {
  152. case 's':
  153. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NZ;}
  154. else {loipe[currentX][currentY] = Fragment.KR;}
  155. currentY++;
  156. break;
  157. case 'l':
  158. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NO;}
  159. else {loipe[currentX][currentY] = Fragment.KR;}
  160. currentX++;
  161. richting = richting.turnLeft();
  162. break;
  163. default:
  164. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NW;}
  165. else {loipe[currentX][currentY] = Fragment.KR;}
  166. currentX--;
  167. richting = richting.turnRight();
  168. break;
  169. }break;
  170. default:
  171. switch (pad.charAt(i)) {
  172. case 's':
  173. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.OW;}
  174. else {loipe[currentX][currentY] = Fragment.KR;}
  175. currentX--;
  176. break;
  177. case 'l':
  178. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.ZO;}
  179. else {loipe[currentX][currentY] = Fragment.KR;}
  180. currentY++;
  181. richting = richting.turnLeft();
  182. break;
  183. default:
  184. if(loipe[currentX][currentY] == Fragment.EM){loipe[currentX][currentY] = Fragment.NO;}
  185. else {loipe[currentX][currentY] = Fragment.KR;}
  186. currentY--;
  187. richting = richting.turnRight();
  188. break;
  189. }break;
  190. }
  191. }
  192. }
  193.  
  194. public int getWidth() {
  195. return width;
  196. }
  197.  
  198. public int getHeight() {
  199. return height;
  200. }
  201.  
  202. public Fragment getFragment (int x, int y) {
  203. return loipe[x][y];
  204. }
  205.  
  206. @Override
  207. public int getX() {
  208. // TODO Auto-generated method stub
  209. return 0;
  210. }
  211.  
  212. @Override
  213. public int getY() {
  214. // TODO Auto-generated method stub
  215. return 0;
  216. }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement