- Start World to Game World

This commit is contained in:
Max
2026-09-15 19:35:25 +02:00
parent cce1abcc81
commit 60d21d5f68
7 changed files with 30 additions and 32 deletions
Binary file not shown.
+5 -3
View File
@@ -1,12 +1,14 @@
#BlueJ class context
comment0.target=MyWorld
comment0.text=\r\n\ Write\ a\ description\ of\ class\ MyWorld\ here.\r\n\ \r\n\ @author\ (your\ name)\ \r\n\ @version\ (a\ version\ number\ or\ a\ date)\r\n
comment1.params=
comment1.target=MyWorld()
comment1.params=pCharakterP1\ pCharakterP2
comment1.target=MyWorld(int,\ int)
comment1.text=\r\n\ Constructor\ for\ objects\ of\ class\ MyWorld.\r\n\ \r\n
comment2.params=
comment2.target=void\ prepare()
comment2.text=\r\n\ Prepare\ the\ world\ for\ the\ start\ of\ the\ program.\r\n\ That\ is\:\ create\ the\ initial\ objects\ and\ add\ them\ to\ the\ world.\r\n
comment3.params=
comment3.target=void\ act()
numComments=4
comment4.params=
comment4.target=void\ gameEnd()
numComments=5
+15 -1
View File
@@ -10,15 +10,19 @@ public class MyWorld extends World
{
Player1 player1;
Player2 player2;
int charakterP1;
int charakterP2;
/**
* Constructor for objects of class MyWorld.
*
*/
public MyWorld()
public MyWorld(int pCharakterP1, int pCharakterP2)
{
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(600, 400, 1);
prepare();
charakterP1 = pCharakterP1;
charakterP2 = pCharakterP2;
}
/**
@@ -45,5 +49,15 @@ public class MyWorld extends World
}
}
showText(String.valueOf(player2.leben),300,300);
gameEnd();
}
public void gameEnd(){
if(player1.leben == 0){
Greenfoot.setWorld(new EndWorld("Player Two"));
}
if(player2.leben == 0){
Greenfoot.setWorld(new EndWorld("Player One"));
}
}
}
Binary file not shown.
+1 -1
View File
@@ -101,7 +101,7 @@ public class StartWorld extends World
SpielerWahl2();
if (Greenfoot.isKeyDown("enter")){
if(aktuellerSpieler1 > 0 && aktuellerSpieler2 > 0){
Greenfoot.setWorld(new MyWorld());
Greenfoot.setWorld(new MyWorld(aktuellerSpieler1, aktuellerSpieler2));
}
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

+9 -27
View File
@@ -1,6 +1,5 @@
#Greenfoot project file
class.MyWorld.image=crumpled-paper.jpg
class.Pfeil.image=cursor.png
class.Player1.image=man01.png
class.Player2.image=man01.png
dependency1.from=StartWorld
@@ -15,16 +14,13 @@ dependency3.type=UsesDependency
dependency4.from=MyWorld
dependency4.to=Player2
dependency4.type=UsesDependency
dependency5.from=EndWorld
dependency5.to=StartWorld
dependency5.type=UsesDependency
editor.fx.0.height=737
editor.fx.0.width=814
editor.fx.0.x=151
editor.fx.0.y=18
editor.fx.0.x=168
editor.fx.0.y=39
height=686
package.numDependencies=5
package.numTargets=7
package.numDependencies=4
package.numTargets=5
project.charset=UTF-8
publish.hasSource=false
publish.locked=true
@@ -47,49 +43,35 @@ target1.width=120
target1.x=0
target1.y=0
target2.height=70
target2.name=EndWorld
target2.name=StartWorld
target2.showInterface=false
target2.type=ClassTarget
target2.width=120
target2.x=0
target2.y=0
target3.height=70
target3.name=StartWorld
target3.name=Player2
target3.showInterface=false
target3.type=ClassTarget
target3.width=120
target3.x=0
target3.y=0
target4.height=70
target4.name=startScreen
target4.name=Player1
target4.showInterface=false
target4.type=ClassTarget
target4.width=120
target4.x=0
target4.y=0
target5.height=70
target5.name=Player2
target5.name=MyWorld
target5.showInterface=false
target5.type=ClassTarget
target5.width=120
target5.x=0
target5.y=0
target6.height=70
target6.name=Player1
target6.showInterface=false
target6.type=ClassTarget
target6.width=120
target6.x=0
target6.y=0
target7.height=70
target7.name=MyWorld
target7.showInterface=false
target7.type=ClassTarget
target7.width=120
target7.x=0
target7.y=0
version=3.1.0
width=1294
world.lastInstantiated=StartWorld
xPosition=0
yPosition=12
yPosition=0