mirror of
https://github.com/jokerx3/HeatUp
synced 2026-07-27 11:39:45 +02:00
added UI and images
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 157 B |
Binary file not shown.
|
After Width: | Height: | Size: 169 B |
Binary file not shown.
|
After Width: | Height: | Size: 168 B |
Binary file not shown.
|
After Width: | Height: | Size: 166 B |
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
@@ -0,0 +1,127 @@
|
|||||||
|
package de.heatup.objects;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import javax.swing.ImageIcon;
|
||||||
|
import javax.swing.JLabel;
|
||||||
|
|
||||||
|
public class Gegner {
|
||||||
|
|
||||||
|
private static int numberOfInstances;
|
||||||
|
private BufferedImage opponentImage;
|
||||||
|
private JLabel opponentLabel;
|
||||||
|
public Thread t;
|
||||||
|
public Gegner() throws IOException {
|
||||||
|
numberOfInstances++;
|
||||||
|
String fname;
|
||||||
|
if (numberOfInstances == 1 ) {
|
||||||
|
fname="images/red48.png";
|
||||||
|
} else if (numberOfInstances == 2) {
|
||||||
|
fname="images/green48.png";
|
||||||
|
} else {
|
||||||
|
fname="images/black48.png";
|
||||||
|
}
|
||||||
|
opponentImage = ImageIO.read(new File(fname));
|
||||||
|
opponentLabel = new JLabel(new ImageIcon(opponentImage));
|
||||||
|
this.gegnerLogik();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JLabel getLabel() {
|
||||||
|
return this.opponentLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getX() {
|
||||||
|
return this.opponentLabel.getLocation().x;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getY() {
|
||||||
|
return this.opponentLabel.getLocation().y;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setY(int y) {
|
||||||
|
this.opponentLabel.setLocation(this.opponentLabel.getLocation().x,y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setX(int x) {
|
||||||
|
this.opponentLabel.setLocation(x,this.opponentLabel.getLocation().y);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Quick and dirty for testing...
|
||||||
|
*/
|
||||||
|
private void gegnerLogik() {
|
||||||
|
final Random rand = new Random();
|
||||||
|
t = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int movex=0, movey=0;
|
||||||
|
int move = 0;
|
||||||
|
int dir;
|
||||||
|
while (true) {
|
||||||
|
if ( move == 0 ) {
|
||||||
|
dir = rand.nextInt(20)+1;
|
||||||
|
// System.out.println("Entscheidung: " + dir);
|
||||||
|
if ( dir < 5 || dir > 15) {
|
||||||
|
movex = rand.nextInt(800)+1;
|
||||||
|
move = 2;
|
||||||
|
if (movex > 100) { move = -2; }
|
||||||
|
movey = 0;
|
||||||
|
// System.out.println("X " + move + " " + movex);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
movey = rand.nextInt(600)+1;
|
||||||
|
move = 1;
|
||||||
|
if (movey > 100) { move = -1; }
|
||||||
|
movex = 0;
|
||||||
|
// System.out.println("X " + move + " " + movex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( getLabel().getX() <= 0 && move == -2 ) {
|
||||||
|
move = move * -1;
|
||||||
|
}
|
||||||
|
if ( getLabel().getX() >= 752 && move == 2 ) {
|
||||||
|
move = move * -1;
|
||||||
|
}
|
||||||
|
if ( getLabel().getY() <= 0 && move == -1 ) {
|
||||||
|
move = move * -1;
|
||||||
|
}
|
||||||
|
if ( getLabel().getY() >= 552 && move == 1 ) {
|
||||||
|
move = move * -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println("Move " + move + " Movex " + movex + " Movey " + movey);
|
||||||
|
|
||||||
|
if ( move == -2 && movex >= 0) {
|
||||||
|
movex -= 4;
|
||||||
|
getLabel().setBounds(getLabel().getX()-8, getLabel().getY(), 48, 48);
|
||||||
|
} else if ( move == 2 && movex >= 0) {
|
||||||
|
movex -= 4;
|
||||||
|
getLabel().setBounds(getLabel().getX()+8, getLabel().getY(), 48, 48);
|
||||||
|
} else if (move == -1 && movey >= 0) {
|
||||||
|
movey -= 4;
|
||||||
|
getLabel().setBounds(getLabel().getX(), getLabel().getY()-8, 48, 48);
|
||||||
|
} else if (move == 1 && movey >= 0) {
|
||||||
|
movey -= 4;
|
||||||
|
getLabel().setBounds(getLabel().getX(), getLabel().getY()+8, 48, 48);
|
||||||
|
} else {
|
||||||
|
move = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// System.out.println("x: " + getX() + " y:" + getY());
|
||||||
|
try {
|
||||||
|
Thread.sleep(10);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
package de.heatup.ui;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.KeyAdapter;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
|
import javax.swing.JFrame;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public class GameInterface extends JFrame {
|
||||||
|
|
||||||
|
private JPanel outerPanel;
|
||||||
|
private JPanel statusPanel;
|
||||||
|
private JPanel gamePanel;
|
||||||
|
private JPanel actionPanel;
|
||||||
|
private BufferedImage image;
|
||||||
|
|
||||||
|
|
||||||
|
public GameInterface() throws IOException {
|
||||||
|
setTitle("HeatUP!");
|
||||||
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
|
setVisible(true);
|
||||||
|
setResizable(true);
|
||||||
|
|
||||||
|
|
||||||
|
createLayout();
|
||||||
|
pack();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createLayout() throws IOException {
|
||||||
|
/*
|
||||||
|
* outerPanel ist der Rahmen in dem das Spielfeld und der statusFrame vereinigt werden
|
||||||
|
*/
|
||||||
|
outerPanel = new JPanel();
|
||||||
|
outerPanel.setLayout(new BorderLayout());
|
||||||
|
outerPanel.setBorder(BorderFactory.createTitledBorder("outerPanel"));
|
||||||
|
outerPanel.setVisible(true);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* statusPanel enthält Elemente wie Score, Zeit, Level etc.
|
||||||
|
*/
|
||||||
|
statusPanel = new JPanel();
|
||||||
|
statusPanel.setLayout(new GridLayout(1,4));
|
||||||
|
statusPanel.setPreferredSize(new Dimension(800,80));
|
||||||
|
statusPanel.setBorder(BorderFactory.createTitledBorder("statusPanel"));
|
||||||
|
/*
|
||||||
|
* gamePanel enthält das Spielfeld
|
||||||
|
*/
|
||||||
|
gamePanel = new JPanel();
|
||||||
|
gamePanel.setLayout(null);
|
||||||
|
gamePanel.setPreferredSize(new Dimension(800,600));
|
||||||
|
gamePanel.setBorder(BorderFactory.createTitledBorder("gamePanel"));
|
||||||
|
/*
|
||||||
|
* actionPanel enthält Informationen zum durchführen einer Tätigkeit
|
||||||
|
*/
|
||||||
|
actionPanel = new JPanel();
|
||||||
|
actionPanel.setLayout(new GridLayout(1,1));
|
||||||
|
actionPanel.setBorder(BorderFactory.createTitledBorder("actionPanel"));
|
||||||
|
actionPanel.setPreferredSize(new Dimension(800,80));
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Panel korrekt im Layout ausrichten.
|
||||||
|
*/
|
||||||
|
this.getContentPane().add(outerPanel);
|
||||||
|
outerPanel.add(statusPanel,BorderLayout.NORTH);
|
||||||
|
outerPanel.add(gamePanel,BorderLayout.CENTER);
|
||||||
|
outerPanel.add(actionPanel,BorderLayout.SOUTH);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException, InterruptedException {
|
||||||
|
|
||||||
|
GameInterface gameWindow = new GameInterface();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gegner Routine instanzieren
|
||||||
|
*/
|
||||||
|
Gegner g1 = new Gegner();
|
||||||
|
Gegner g2 = new Gegner();
|
||||||
|
Gegner g3 = new Gegner();
|
||||||
|
|
||||||
|
Objekt o1 = new Objekt("images/objekt_dot144.png");
|
||||||
|
o1.getLabel().setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
|
Objekt s1 = new Objekt('0');
|
||||||
|
Objekt s2 = new Objekt('0');
|
||||||
|
Objekt s3 = new Objekt('0');
|
||||||
|
Objekt s4 = new Objekt('0');
|
||||||
|
Objekt s5 = new Objekt('0');
|
||||||
|
Objekt s6 = new Objekt('0');
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Gegner auf Spielfläche hinzufügen und positionieren
|
||||||
|
*/
|
||||||
|
gameWindow.gamePanel.add(g1.getLabel());
|
||||||
|
gameWindow.gamePanel.add(g2.getLabel());
|
||||||
|
gameWindow.gamePanel.add(g3.getLabel());
|
||||||
|
|
||||||
|
gameWindow.gamePanel.add(o1.getLabel());
|
||||||
|
|
||||||
|
g1.getLabel().setBounds(300, 100, 20, 20);
|
||||||
|
g2.getLabel().setBounds(300, 200, 20, 20);
|
||||||
|
g3.getLabel().setBounds(300, 300, 20, 20);
|
||||||
|
|
||||||
|
Objekt bg = new Objekt("images/bg_gray.png");
|
||||||
|
bg.setPosition(0, 0);
|
||||||
|
|
||||||
|
gameWindow.gamePanel.add(s1.getLabel());
|
||||||
|
gameWindow.gamePanel.add(s2.getLabel());
|
||||||
|
gameWindow.gamePanel.add(s3.getLabel());
|
||||||
|
gameWindow.gamePanel.add(s4.getLabel());
|
||||||
|
gameWindow.gamePanel.add(s5.getLabel());
|
||||||
|
gameWindow.gamePanel.add(s6.getLabel());
|
||||||
|
gameWindow.gamePanel.add(bg.getLabel());
|
||||||
|
|
||||||
|
bg.getLabel().repaint();
|
||||||
|
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(o1.getLabel(), 0);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(bg.getLabel(), 5);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(g1.getLabel(), 1);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(g2.getLabel(), 1);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(g3.getLabel(), 1);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s1.getLabel(), 2);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s2.getLabel(), 2);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s3.getLabel(), 2);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s4.getLabel(), 2);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s5.getLabel(), 2);
|
||||||
|
gameWindow.gamePanel.setComponentZOrder(s6.getLabel(), 2);
|
||||||
|
|
||||||
|
s1.setPosition(0, 0);
|
||||||
|
s2.setPosition(25, 0);
|
||||||
|
s3.setPosition(50, 0);
|
||||||
|
s4.setPosition(75, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user