mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 10:19:46 +02:00
Obejekt Datei hinzugefügt.
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
package de.heatup.objects;
|
||||
import java.awt.Point;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.Arrays;
|
||||
|
||||
|
||||
public class Objekt {
|
||||
private static int numberOfInstances;
|
||||
private BufferedImage objectImage;
|
||||
private JLabel objectLabel;
|
||||
private Point objectArea;
|
||||
private Point actionArea;
|
||||
public Thread t;
|
||||
private int objectType;
|
||||
private char objectIdentifier; // TODO: Identifizierung für Map Engine
|
||||
|
||||
/*
|
||||
* TODO: Use Graphics instead of JLabel
|
||||
*
|
||||
*/
|
||||
|
||||
Objekt(String filename) throws IOException {
|
||||
numberOfInstances++;
|
||||
objectImage = ImageIO.read(new File(filename));
|
||||
objectLabel = new JLabel(new ImageIcon(objectImage));
|
||||
}
|
||||
|
||||
Objekt(char objectIdentifier) throws IOException {
|
||||
numberOfInstances++;
|
||||
String filename = getImageFilename(objectIdentifier);
|
||||
System.out.println(filename);
|
||||
objectImage = ImageIO.read(new File(filename));
|
||||
objectLabel = new JLabel(new ImageIcon(objectImage));
|
||||
}
|
||||
|
||||
private String getImageFilename(char objectIdentifier) {
|
||||
String objectFilename;
|
||||
switch (objectIdentifier) {
|
||||
case '1':
|
||||
//leiterbahn
|
||||
objectFilename="images/25x25_black.png";
|
||||
break;
|
||||
case '2':
|
||||
//2:harware
|
||||
objectFilename="images/25x25_red.png";
|
||||
break;
|
||||
case '3':
|
||||
//3:wand
|
||||
objectFilename="images/25x25_blue.png";
|
||||
break;
|
||||
default:
|
||||
objectFilename="images/25x25_orange.png";
|
||||
break;
|
||||
}
|
||||
System.out.println(objectFilename);
|
||||
return objectFilename;
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets position of object via int x int y
|
||||
*/
|
||||
public void setPosition(int x, int y) {
|
||||
System.out.println(x + " " + y + " " + this.getDimensionX() + " " + this.getDimensionY());
|
||||
this.objectLabel.setBounds(x, y, this.getDimensionX(), this.getDimensionY());
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return this.objectLabel.getX();
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return this.objectLabel.getY();
|
||||
}
|
||||
|
||||
public int getDimensionX() {
|
||||
return this.objectImage.getWidth();
|
||||
}
|
||||
|
||||
public int getDimensionY() {
|
||||
return this.objectImage.getHeight();
|
||||
}
|
||||
|
||||
public JLabel getLabel() {
|
||||
return this.objectLabel;
|
||||
}
|
||||
|
||||
public void setObjectType(int objectType) {
|
||||
this.objectType = objectType;
|
||||
}
|
||||
|
||||
public int getObjectType() {
|
||||
return this.objectType;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user