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 Tramwaj extends Thread {
- private int prTramwaju;
- private int x;
- private int y;
- private Menu menu;
- private int tor;
- private BufferedImage image;
- public Tramwaj(Menu menu, int tor, int prTramwaju, int wersjaTramwaju) {
- if (wersjaTramwaju == 1) {
- try {
- image = ImageIO.read(new File("res/t.png"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- } else if (wersjaTramwaju == 2) {
- try {
- image = ImageIO.read(new File("res/t2.png"));
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- this.menu = menu;
- this.tor = tor;
- this.prTramwaju = prTramwaju;
- x = y = 0;
- }
- public BufferedImage getImage() {
- return image;
- }
- public int getX() {
- return x;
- }
- public int getY() {
- return y;
- }
- public void run() {
- for (; ; ) {
- switch (tor) {
- case 0: {
- x = 418;
- y = 0;
- while (y < 250) {
- trasaTramwaju2();
- }
- menu.getLight(tor).jedz();
- while (y < 1000) {
- trasaTramwaju2();
- }
- try {
- sleep(1000);
- } catch (InterruptedException e1) {
- System.out.println();
- }
- menu.usunZajeteMiejsce(x, y - 25);
- menu.usunZajeteMiejsce(x, y - 50);
- }
- break;
- case 1: {
- x = 490;
- y = 1000;
- while (y > 680) {
- trasaTramwaju1();
- }
- menu.getLight(tor).jedz();
- while (y > -50) {
- trasaTramwaju1();
- }
- try {
- sleep(500);
- } catch (InterruptedException e1) {
- System.out.println();
- }
- menu.usunZajeteMiejsce(x, y + 25);
- menu.usunZajeteMiejsce(x, y + 50);
- }
- break;
- case 2: {
- x = 0;
- y = 518;
- while (x < 250) {
- trasaTramwaju3();
- }
- menu.getLight(tor).jedz();
- while (x < 1000) {
- trasaTramwaju3();
- }
- try {
- sleep(1000);
- } catch (InterruptedException e1) {
- System.out.println();
- }
- menu.usunZajeteMiejsce(x - 25, y);
- menu.usunZajeteMiejsce(x - 50, y);
- }
- break;
- case 3: {
- x = 1000;
- y = 438;
- while (x > 680) {
- trasaTramwaju4();
- }
- menu.getLight(tor).jedz();
- while (x > -50) {
- trasaTramwaju4();
- }
- try {
- sleep(500);
- } catch (InterruptedException e1) {
- System.out.println();
- }
- menu.usunZajeteMiejsce(x + 25, y);
- menu.usunZajeteMiejsce(x + 50, y);
- }
- break;
- }
- }
- }
- private void trasaTramwaju1() {
- if (!menu.sprawdzCzyMiejsceJestZajete(x, y)) {
- menu.usunZajeteMiejsce(x, y + 25);
- menu.usunZajeteMiejsce(x, y + 50);
- menu.dodajNoweZajeteMiejsce(new Miejsce(x, y));
- menu.dodajNoweZajeteMiejsce(new Miejsce(x, y + 25));
- try {
- sleep(prTramwaju);
- } catch (InterruptedException exception) {;
- System.out.println();
- }
- menu.repaint();
- y = y - 25;
- }
- }
- private void trasaTramwaju2() {
- if (!menu.sprawdzCzyMiejsceJestZajete(x, y)) {
- menu.usunZajeteMiejsce(x, y - 25);
- menu.usunZajeteMiejsce(x, y - 50);
- menu.dodajNoweZajeteMiejsce(
- new Miejsce(x, y));
- menu.dodajNoweZajeteMiejsce(new Miejsce(x, y - 25));
- try {
- sleep(prTramwaju);
- } catch (InterruptedException e) {
- System.out.println();
- }
- menu.repaint();
- y = y + 25;
- }
- }
- private void trasaTramwaju3() {
- if (!menu.sprawdzCzyMiejsceJestZajete(x, y)) {
- menu.usunZajeteMiejsce(x - 25, y);
- menu.usunZajeteMiejsce(x - 50, y);
- menu.dodajNoweZajeteMiejsce(new Miejsce(x, y));
- menu.dodajNoweZajeteMiejsce(new Miejsce(x - 25, y));
- ;
- try {
- sleep(prTramwaju);
- } catch (InterruptedException e) {
- System.out.println();
- }
- menu.repaint();
- x = x + 25;
- }
- }
- private void trasaTramwaju4() {
- if (!menu.sprawdzCzyMiejsceJestZajete(x, y)) {;
- menu.usunZajeteMiejsce(x + 25, y);
- menu.usunZajeteMiejsce(x + 50, y);
- menu.dodajNoweZajeteMiejsce(new Miejsce(x, y));
- menu.dodajNoweZajeteMiejsce(new Miejsce(x + 25, y));
- try {
- sleep(prTramwaju);
- } catch (InterruptedException e) {
- System.out.println();
- }
- menu.repaint();
- x = x - 25;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement