Hinzufügen der Vorlage
This commit is contained in:
parent
8a99189fb8
commit
8d00681b2c
68 changed files with 4731 additions and 0 deletions
85
Projektgruppe_XXX/src/dice3d/main/MainWindow.java
Normal file
85
Projektgruppe_XXX/src/dice3d/main/MainWindow.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
package dice3d.main;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import dice3d.models.cuboids.Cuboid;
|
||||
import dice3d.models.cuboids.Dice;
|
||||
|
||||
|
||||
public class MainWindow extends JPanel {
|
||||
World w = new World();
|
||||
|
||||
|
||||
public MainWindow() {
|
||||
addKeyListener(new KeyHandler());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void paintComponent(Graphics g) {
|
||||
super.paintComponent(g);
|
||||
draw((Graphics2D) g);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void draw(Graphics2D g) {
|
||||
for(Cuboid c : w.cuboids) {
|
||||
c.draw(g);
|
||||
}
|
||||
int yOffset = 0;
|
||||
g.drawString("Press space key to roll again", 10, yOffset =+ 20);
|
||||
|
||||
for(int i = 0; i < w.cuboids.size(); i++) {
|
||||
Cuboid c = w.cuboids.get(i);
|
||||
if(c instanceof Dice) {
|
||||
Dice d = (Dice) c;
|
||||
g.drawString("dice[" + i + "]: moving=" + !d.notMoving() + " number_rolled=" + d.getNumberRolled(), 10, yOffset += 20);
|
||||
} else {
|
||||
g.drawString("cuboid[" + i + "]: moving=" + !c.notMoving(), 10, yOffset += 20);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
private class KeyHandler extends KeyAdapter {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getID() != KeyEvent.KEY_PRESSED) {
|
||||
return;
|
||||
}
|
||||
if (e.getKeyCode() == KeyEvent.VK_SPACE) {
|
||||
for(Cuboid c : w.cuboids) {
|
||||
c.reset();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MainWindow view = new MainWindow();
|
||||
JFrame frame = new JFrame();
|
||||
frame.setTitle("Dice");
|
||||
frame.getContentPane().add(view);
|
||||
frame.setSize(1280, 720);
|
||||
frame.setLocationRelativeTo(null);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
// frame.setResizable(false);
|
||||
frame.setVisible(true);
|
||||
view.requestFocus();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
43
Projektgruppe_XXX/src/dice3d/main/World.java
Normal file
43
Projektgruppe_XXX/src/dice3d/main/World.java
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
package dice3d.main;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import dice3d.models.cuboids.Cuboid;
|
||||
import dice3d.models.cuboids.Dice;
|
||||
|
||||
public class World {
|
||||
|
||||
public static final double projectionDistance = 1000;
|
||||
|
||||
public ArrayList<Cuboid> cuboids;
|
||||
public Cuboid floor;
|
||||
|
||||
public World() {
|
||||
cuboids = new ArrayList<Cuboid>();
|
||||
|
||||
floor = new Cuboid(10, 400, 600, 700, 1000, 10);
|
||||
cuboids.add(floor);
|
||||
|
||||
cuboids.add(new Dice(150, 100, 800, 80));
|
||||
cuboids.add(new Dice(50, 120, 800, 80));
|
||||
|
||||
long delayInMS = 500; // start updating after 500ms
|
||||
long intervalInMS = 15; // update every 15ms
|
||||
|
||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
for(Cuboid c : cuboids) {
|
||||
if(c == floor) {
|
||||
continue;
|
||||
}
|
||||
c.update();
|
||||
}
|
||||
}
|
||||
}, delayInMS, intervalInMS);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue