Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.67 KB | None | 0 0
  1. import java.awt.image.BufferedImage;
  2. import java.io.File;
  3. import java.io.IOException;
  4.  
  5. import javax.imageio.ImageIO;
  6.  
  7. public class Auto extends Thread {
  8. private int prAuto;
  9. private int x;
  10. private int y;
  11. private int tor;
  12. private int xy;
  13. private int wspX;
  14. private int wspY;
  15. private BufferedImage image;
  16. private Menu menu;
  17.  
  18. public Auto(Menu menu, int tor, int prAuto) {
  19. try {
  20. image = ImageIO.read(new File("res/s.png"));
  21. } catch (IOException e) {
  22. e.printStackTrace();
  23. }
  24. this.menu = menu;
  25. this.tor = tor;
  26. this.prAuto = prAuto;
  27. x = 0;
  28. y = 0;
  29. xy = -1;
  30. }
  31.  
  32. public int getX() {
  33. return x;
  34. }
  35.  
  36. public int getY() {
  37. return y;
  38. }
  39.  
  40. public void run() {
  41. for (; ; )
  42. move();
  43. }
  44.  
  45. private void nowyTor() {
  46. menu.repaint();
  47. try {
  48. sleep(100);
  49. } catch (InterruptedException e) {
  50. }
  51. }
  52.  
  53. public BufferedImage getImage() {
  54. return image;
  55. }
  56.  
  57. public void wybierzKierunekRuchu(int gora, int dol, int lewo, int prawo) {
  58. if (gora == 1 && prawo == 0 && lewo == 0) {
  59. wspX = x;
  60. wspY = y - 25;
  61. } else if (dol == 1 && prawo == 0 && lewo == 0) {
  62. wspX = x;
  63. wspY = y + 25;
  64. } else if (lewo == 1 && dol == 0 && gora == 0) {
  65. wspX = x - 25;
  66. wspY = y;
  67. } else if (prawo == 1 && dol == 0 && gora == 0) {
  68. wspX = x + 25;
  69. wspY = y;
  70. } else if(gora == 1 && lewo == 1){
  71. wspX = x - 25;
  72. wspY = wspY - 25;
  73. } else if(gora == 1 && prawo == 1){
  74. wspX = x + 25;
  75. wspY = wspY - 25;
  76. } else if(dol == 1 && lewo == 1){
  77. wspX = x - 25;
  78. wspY = wspY + 25;
  79. } else if(dol == 1 && prawo == 1){
  80. wspX = x + 25;
  81. wspY = wspY + 25;
  82. }
  83. if (!menu.sprawdzCzyMiejsceJestZajete(wspX, wspY)) {
  84. menu.dodajNoweZajeteMiejsce(new Miejsce(wspX, wspY));
  85. menu.usunZajeteMiejsce(x, y);
  86. try {
  87. Thread.sleep(prAuto);
  88. } catch (InterruptedException ex) {
  89. }
  90. menu.repaint();
  91. x = wspX;
  92. y = wspY;
  93. }
  94. }
  95.  
  96. public void wybierzTor4() {
  97. x = 570;
  98. y = 1000;
  99. while (y > 675) {
  100. wybierzKierunekRuchu(1, 0, 0, 0);
  101. }
  102. menu.getLight(tor).jedz();
  103. while (y <= 675 && y > -20) {
  104. wybierzKierunekRuchu(1, 0, 0, 0);
  105. }
  106. menu.usunZajeteMiejsce(x, y);
  107. nowyTor();
  108. }
  109.  
  110.  
  111. public void wybierzTor5() {
  112. x = 570;
  113. y = 1000;
  114. while (y > 675) {
  115. wybierzKierunekRuchu(1, 0, 0, 0);
  116. }
  117. menu.getLight(tor).jedz();
  118. while (y > 360) {
  119. wybierzKierunekRuchu(1, 0, 0, 0);
  120. }
  121. while (x > -20) {
  122. wybierzKierunekRuchu(0, 0, 1, 0);
  123. }
  124. menu.usunZajeteMiejsce(x, y);
  125. nowyTor();
  126. }
  127.  
  128. public void wybierzTor6() {
  129. x = 330;
  130. y = -50;
  131. while (y < 290) {
  132. wybierzKierunekRuchu(0, 1, 0, 0);
  133. }
  134. menu.getLight(tor).jedz();
  135. while (y <= 1000) {
  136. wybierzKierunekRuchu(0, 1, 0, 0);
  137. }
  138. menu.usunZajeteMiejsce(x, y);
  139. nowyTor();
  140. }
  141.  
  142. public void wybierzTor7() {
  143. x = 330;
  144. y = -50;
  145. while (y < 290) {
  146. wybierzKierunekRuchu(0, 1, 0, 0);
  147. }
  148. menu.getLight(tor).jedz();
  149. while (y < 600) {
  150. wybierzKierunekRuchu(0, 1, 0, 0);
  151. }
  152. while (x < 1020) {
  153. wybierzKierunekRuchu(0, 0, 0, 1);
  154. }
  155. menu.usunZajeteMiejsce(x, y);
  156. nowyTor();
  157. }
  158.  
  159. public void wybierzTor8() {
  160. x = 1000;
  161. y = 360;
  162. while (x > 660) {
  163. wybierzKierunekRuchu(0, 0, 1, 0);
  164. }
  165. menu.getLight(tor).jedz();
  166. while (x > -20) {
  167. wybierzKierunekRuchu(0, 0, 1, 0);
  168. }
  169. menu.usunZajeteMiejsce(x, y);
  170. nowyTor();
  171. }
  172.  
  173. public void wybierzTor9() {
  174. x = 1000;
  175. y = 360;
  176. while (x > 660) {
  177. wybierzKierunekRuchu(0, 0, 1, 0);
  178. }
  179. menu.getLight(tor).jedz();
  180. while (x > 330) {
  181. wybierzKierunekRuchu(0, 0, 1, 0);
  182. }
  183. while (y < 1020) {
  184. wybierzKierunekRuchu(0, 1, 0, 0);
  185. }
  186. menu.usunZajeteMiejsce(x, y);
  187. nowyTor();
  188. }
  189.  
  190. public void wybierzTor10() {
  191. x = -25;
  192. y = 600;
  193. while (x < 260) {
  194. wybierzKierunekRuchu(0, 0, 0, 1);
  195. }
  196. menu.getLight(tor).jedz();
  197. while (x < 1020) {
  198. wybierzKierunekRuchu(0, 0, 0, 1);
  199. }
  200. menu.usunZajeteMiejsce(x, y);
  201. nowyTor();
  202. }
  203.  
  204. public void wybierzTor11() {
  205. x = -25;
  206. y = 600;
  207. while (x < 260) {
  208. wybierzKierunekRuchu(0, 0, 0, 1);
  209. }
  210. menu.getLight(tor).jedz();
  211. while (x < 570) {
  212. wybierzKierunekRuchu(0, 0, 0, 1);
  213. }
  214. while (y > -20) {
  215. wybierzKierunekRuchu(1, 0, 0, 0);
  216. }
  217. menu.usunZajeteMiejsce(x, y);
  218. nowyTor();
  219. }
  220.  
  221. public void wybierzTor12() {
  222. x = 0;
  223. y = 640;
  224. while (x < 130) {
  225. wybierzKierunekRuchu(0, 0, 0, 1);
  226. }
  227. while (x < 300) {
  228. wybierzKierunekRuchu(0, 1, 0, 1);
  229. }
  230. while (y < 1020) {
  231. wybierzKierunekRuchu(0, 1, 0, 0);
  232. }
  233. menu.usunZajeteMiejsce(x, y);
  234. nowyTor();
  235. }
  236.  
  237. public void wybierzTor13() {
  238. x = 300;
  239. y = -20;
  240. while (y < 120) {
  241. wybierzKierunekRuchu(0, 1, 0, 0);
  242. }
  243. while (y < 320) {
  244. wybierzKierunekRuchu(0, 1, 1, 0);
  245. }
  246. while (x > -20) {
  247. wybierzKierunekRuchu(0, 0, 1, 0);
  248. }
  249. menu.usunZajeteMiejsce(x, y);
  250. nowyTor();
  251. }
  252.  
  253. public void wybierzTor14() {
  254. x = 1000;
  255. y = 320;
  256. while (x > 830) {
  257. wybierzKierunekRuchu(0, 0, 1, 0);
  258. }
  259. while (x > 630) {
  260. wybierzKierunekRuchu(1, 0, 1, 0);
  261. }
  262. while (y > -20) {
  263. wybierzKierunekRuchu(1, 0, 0, 0);
  264. }
  265. menu.usunZajeteMiejsce(x, y);
  266. nowyTor();
  267. }
  268.  
  269. public void move() {
  270. try {
  271. sleep(prAuto);
  272. } catch (InterruptedException e1) {
  273. e1.printStackTrace();
  274. }
  275. switch (tor) {
  276. case 4:
  277. wybierzTor4();
  278. break;
  279. case 5:
  280. wybierzTor5();
  281. break;
  282. case 6:
  283. wybierzTor6();
  284. break;
  285. case 7:
  286. wybierzTor7();
  287. break;
  288. case 8:
  289. wybierzTor8();
  290. break;
  291. case 9:
  292. wybierzTor9();
  293. break;
  294. case 10:
  295. wybierzTor10();
  296. break;
  297. case 11:
  298. wybierzTor11();
  299. break;
  300. case 12:
  301. wybierzTor12();
  302. break;
  303. case 13:
  304. wybierzTor13();
  305. break;
  306. case 14:
  307. wybierzTor14();
  308. break;
  309. }
  310. }
  311. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement