Hallo liebe community
ich programmiere grad ein ein spiel mit levels
ich möchte spielern ermöglichen mitten im spiel neu an zu fangen
man beginnt immer von lvl1 dann
doch bei mir wird die schleife nach dem reset net weiter ausgeführt…
hab folgenden code:
import ch.aplu.jgamegrid.*;
import java.awt.event.KeyEvent;
import java.awt.*;
import java.util.ArrayList;
class test extends GameGrid implements GGButtonListener{
static test galaxy = new test();
Player player = new Player();
ArrayList<Actor> rockets = getActors(Rockets.class);
int x=getWidth();
int y=getHeight();
static int level;
static int score;
static int life;
static int n;
static boolean reset=false;
static GGButton newgame = new GGButton("sprites/newgame.png",true);
public test(){
super(625, 725,1,null,"",false);
String bar;
bar= String.format("RocketGun created by Imran");
setTitle(bar);
setSimulationPeriod(15);
}
public void Actor(){
addActor(player, new Location(300,550));
player.show();
}
public void Rockets(int Typ, int Number){
Location loc= new Location((int)(500*Math.random()+50),50);
Rockets[] rocket = new Rockets[Number];
for(int n=0; n<rocket.length;n++){
if(n==rocket.length){reset=false;n=0;}
if(reset==true){continue;}
rocket[n] = new Rockets("sprites/rocket"+Typ+".gif");
addActor(rocket[n], new Location(loc));
rocket[n].show();
}
public static void main(String[] args){
galaxy.show();
galaxy.Actor();
galaxy.doRun();
while(true){Levels();}
}
public void pausemenu(){
addActor(newgame, new Location(312, 350));
newgame.addButtonListener(this);
newgame.show();
}
public void buttonClicked(GGButton button){
if(button.equals(newgame)){
reset();}
public void buttonPressed(GGButton button){}
public void buttonReleased(GGButton button){}
//<---End Menu--->\\
//<---Begin Levels--->\\
static void Levels(){
while(reset==false){
switch(level){
case 0:
level=1;
case 1:
galaxy.Rockets(1,2,1,8,5,5,1,5,3,true,500,50);
galaxy.Rockets(2,2,2,4,5,5,2,2,1,false,0,0);
level=2;}
break;
case 2:
galaxy.Rockets(3,2,3,8,5,5,1,5,3,true,500,50);
galaxy.Rockets(4,2,4,4,5,5,2,2,1,false,0,0);
rocketscounter=0;
level=3;}
break;
}
}}
//<---End Levels--->\\
//<---Begin class Player--->\\
class Player extends Actor{
public Player(){
super("sprites/player_0.png");}
private void shoot(){
Bomb bomb1 = new Bomb();
gameGrid.addActor(bomb1,new Location(getX(),getY()-45));
bomb1.show();}
@Override
public void act(){
if (gameGrid.isKeyPressed(KeyEvent.VK_LEFT) && getX() > 36){
setX(getX() - 4);}
if (gameGrid.isKeyPressed(KeyEvent.VK_RIGHT) && getX() < x-36){
setX(getX() + 4);}
if (gameGrid.isKeyPressed(KeyEvent.VK_UP) && getY() > 62){
setY(getY() - 4);}
if (gameGrid.isKeyPressed(KeyEvent.VK_DOWN) && getY() < y-36){
setY(getY() + 4);}
if (gameGrid.isKeyPressed(KeyEvent.VK_SPACE)){
shoot();}
if (isKeyPressed(KeyEvent.VK_PAUSE)){
doPause();
pausemenu();}
}
}
//<---End class Player--->\\
//<---Begin class Rockets--->\\
class Rockets extends Actor{
public Rockets(String imagePath){
super(imagePath);
setVertMirror(true);}
@Override
public void act(){
Location loc=new Location(getX(),getY()+2);
setLocation(loc);
if(!isInGrid()){
removeSelf();}
}
}
//<---End class Rockets--->\\
//<---Begin Remove--->\\
public void remove(){
doPause();
removeActors(Player.class);
removeActors(Rockets.class);
removeActors(Bomb.class);
removeActors(RocketsBomb.class);
getBg().clear();
}
//<---End Remove--->\\
//<---Begin Reset--->\\
public void reset(){
doPause();
remove();
reset=true;
level=0;
n=0;
}
//<---End Reset--->\\
}```