Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden. Du solltest ein Upgrade durchführen oder ein alternativer Browser verwenden.
ich hab ein kleines Spiel gemacht (Doodle Jump)
jetzt will ich noch double punkte;
rechts oben im Spielfeld anzeigen.
nur weiß ich nicht wie ich das am besten mache.
Naja das kommt jetzt eben drauf an, wie du dein Spiel umgesetzt hast. Gibt ja vielfältige Möglichkeiten bei unterschiedlichsten Technologien, aber jetzt zu raten wie du es getan haben könntest.. und BlueJ oder nicht ist da vollkommen egal.
also das "Spielfeld" war von meinem Lehrer schon vorgegeben.
kann ja mal die klasse posten:
Java:
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferStrategy;
import java.util.*;
import java.awt.event.*;
public class GAMEWINDOW extends Canvas implements Runnable, KeyListener
{
private BufferStrategy strategy;
private long lastLoopTime;
private boolean gameRunning=true;
private static GAMEWINDOW instance;
private String Taste="";
private Vector<BILD> sprites=new Vector<BILD>();
KEYSTATE ks = new KEYSTATE();
public static GAMEWINDOW getInstance()
{
if(instance==null)
{
instance = new GAMEWINDOW();
}
return instance;
}
private GAMEWINDOW()
{
// create a frame to contain our game
JFrame container = new JFrame("Spielfeld");
// get hold the content of the frame and set up the
// resolution of the game
JPanel panel = (JPanel) container.getContentPane();
panel.setPreferredSize(new Dimension(600,700));
panel.setLayout(null);
// setup our canvas size and put it into the content of the frame
setBounds(0,0,600,700);
panel.add(this);
// Tell AWT not to bother repainting our canvas since we're
// going to do that our self in accelerated mode
setIgnoreRepaint(true);
// finally make the window visible
container.pack();
container.setResizable(false);
container.setVisible(true);
// create the buffering strategy which will allow AWT
// to manage our accelerated graphics
createBufferStrategy(2);
strategy = getBufferStrategy();
new Thread(this).start();
//addHierarchyListener(this);
addKeyListener(this);
}
public void run()
{
while (gameRunning) {
// work out how long its been since the last update, this
// will be used to calculate how far the entities should
// move this loop
long delta = System.currentTimeMillis() - lastLoopTime;
lastLoopTime = System.currentTimeMillis();
// Get hold of a graphics context for the accelerated
// surface and blank it out
Graphics2D g = (Graphics2D) strategy.getDrawGraphics();
g.setColor(Color.white);
g.fillRect(0,0,600,700);
synchronized(sprites)
{
Iterator<BILD> iterator = sprites.iterator();
while(iterator.hasNext())
{
BILD sprite = iterator.next();
if(sprite.LeseSichtbar())
{
sprite.Draw(g);
}
}
}
// finally, we've completed drawing so clear up the graphics
// and flip the buffer over
g.dispose();
strategy.show();
// finally pause for a bit. Note: this should run us at about
// 100 fps but on windows this might vary each loop due to
// a bad implementation of timer
try { Thread.sleep(10); } catch (Exception e) {}
}
}
public KEYSTATE getKeystate()
{
return ks;
}
public void AddSprite(BILD bild)
{
synchronized(sprites)
{
sprites.add(bild);
}
}
public void stopRunning()
{
gameRunning=false;
try { Thread.sleep(1000); } catch (Exception e) {}
synchronized(sprites)
{
sprites.clear();
}
instance=null;
}
public void hierarchyChanged(HierarchyEvent e)
{
gameRunning=false;
}
public void keyPressed(KeyEvent e)
{
ks.add(e);
}
public void keyReleased(KeyEvent e)
{
ks.remove(e);
}
public void keyTyped(KeyEvent e)
{
}
public String LeseTaste()
{
return Taste;
}
}
jetzt hab ich noch ne frage.
und zwar, wenn man jetzt game over ist
wie kann ich dann das Spielfeld schließen?
weil ich hab dann wenn man game over ist
einen einen button wo ich nochmal spielen auswählen kann.
nur wenn ich jetzt nochmal das spiel starte sind eben noch bilder, punkte etc. vom alten spiel drin.
aber ich wills nicht ganz schließen also nicht
System.exit(0);
Da wirst du dir anschauen müssen, wie die Bilder, etc. geladen wurden und wie du sie wieder los wirst.
Alternativ ganze rabiat könntest du auch inetwa das machen:
Java:
Runtime.getRuntime.exec(new String[]{"java", "-jar", "name deiner jar"}); // oder eben die classe starten oder sowas in der Art ;)
System.exit(0);
Also praktisch das Programm nochmal starten und das alte einfach beenden.
Sollte auch gehen.