Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.image.BufferedImage;
- import java.io.File;
- import java.io.IOException;
- import javax.imageio.ImageIO;
- public class Auto extends Thread {
- private int prAuto;
- private int x;
- private int y;
- private int tor;
- private int xy;
- private int wspX;
- private int wspY;
- private BufferedImage image;
- private Menu menu;
- public Auto(Menu menu, int tor, int prAuto) {
- try {
- image = ImageIO.read(new File("res/s.png"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- this.menu = menu;
- this.tor = tor;
- this.prAuto = prAuto;
- x = 0;
- y = 0;
- xy = -1;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public void run() {
- for (; ; )
- move();
- }
- private void nowyTor() {
- menu.repaint();
- try {
- sleep(100);
- } catch (InterruptedException e) {
- }
- }
- public BufferedImage getImage() {
- return image;
- }
- public void wybierzKierunekRuchu(int gora, int dol, int lewo, int prawo) {
- if (gora == 1 && prawo == 0 && lewo == 0) {
- wspX = x;
- wspY = y - 25;
- } else if (dol == 1 && prawo == 0 && lewo == 0) {
- wspX = x;
- wspY = y + 25;
- } else if (lewo == 1 && dol == 0 && gora == 0) {
- wspX = x - 25;
- wspY = y;
- } else if (prawo == 1 && dol == 0 && gora == 0) {
- wspX = x + 25;
- wspY = y;
- } else if(gora == 1 && lewo == 1){
- wspX = x - 25;
- wspY = wspY - 25;
- } else if(gora == 1 && prawo == 1){
- wspX = x + 25;
- wspY = wspY - 25;
- } else if(dol == 1 && lewo == 1){
- wspX = x - 25;
- wspY = wspY + 25;
- } else if(dol == 1 && prawo == 1){
- wspX = x + 25;
- wspY = wspY + 25;
- }
- if (!menu.sprawdzCzyMiejsceJestZajete(wspX, wspY)) {
- menu.dodajNoweZajeteMiejsce(new Miejsce(wspX, wspY));
- menu.usunZajeteMiejsce(x, y);
- try {
- Thread.sleep(prAuto);
- } catch (InterruptedException ex) {
- }
- menu.repaint();
- x = wspX;
- y = wspY;
- }
- }
- public void wybierzTor4() {
- x = 570;
- y = 1000;
- while (y > 675) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- menu.getLight(tor).jedz();
- while (y <= 675 && y > -20) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor5() {
- x = 570;
- y = 1000;
- while (y > 675) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- menu.getLight(tor).jedz();
- while (y > 360) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- while (x > -20) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor6() {
- x = 330;
- y = -50;
- while (y < 290) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- menu.getLight(tor).jedz();
- while (y <= 1000) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor7() {
- x = 330;
- y = -50;
- while (y < 290) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- menu.getLight(tor).jedz();
- while (y < 600) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- while (x < 1020) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor8() {
- x = 1000;
- y = 360;
- while (x > 660) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- menu.getLight(tor).jedz();
- while (x > -20) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor9() {
- x = 1000;
- y = 360;
- while (x > 660) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- menu.getLight(tor).jedz();
- while (x > 330) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- while (y < 1020) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor10() {
- x = -25;
- y = 600;
- while (x < 260) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- menu.getLight(tor).jedz();
- while (x < 1020) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor11() {
- x = -25;
- y = 600;
- while (x < 260) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- menu.getLight(tor).jedz();
- while (x < 570) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- while (y > -20) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor12() {
- x = 0;
- y = 640;
- while (x < 130) {
- wybierzKierunekRuchu(0, 0, 0, 1);
- }
- while (x < 300) {
- wybierzKierunekRuchu(0, 1, 0, 1);
- }
- while (y < 1020) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor13() {
- x = 300;
- y = -20;
- while (y < 120) {
- wybierzKierunekRuchu(0, 1, 0, 0);
- }
- while (y < 320) {
- wybierzKierunekRuchu(0, 1, 1, 0);
- }
- while (x > -20) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void wybierzTor14() {
- x = 1000;
- y = 320;
- while (x > 830) {
- wybierzKierunekRuchu(0, 0, 1, 0);
- }
- while (x > 630) {
- wybierzKierunekRuchu(1, 0, 1, 0);
- }
- while (y > -20) {
- wybierzKierunekRuchu(1, 0, 0, 0);
- }
- menu.usunZajeteMiejsce(x, y);
- nowyTor();
- }
- public void move() {
- try {
- sleep(prAuto);
- } catch (InterruptedException e1) {
- e1.printStackTrace();
- }
- switch (tor) {
- case 4:
- wybierzTor4();
- break;
- case 5:
- wybierzTor5();
- break;
- case 6:
- wybierzTor6();
- break;
- case 7:
- wybierzTor7();
- break;
- case 8:
- wybierzTor8();
- break;
- case 9:
- wybierzTor9();
- break;
- case 10:
- wybierzTor10();
- break;
- case 11:
- wybierzTor11();
- break;
- case 12:
- wybierzTor12();
- break;
- case 13:
- wybierzTor13();
- break;
- case 14:
- wybierzTor14();
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement