mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
feat(Game.java): ajout constructor et init fn
This commit is contained in:
42
src/Game.java
Normal file
42
src/Game.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
public class Game
|
||||||
|
{
|
||||||
|
private Car[] car;
|
||||||
|
private Map map;
|
||||||
|
|
||||||
|
public Game(int playerNumber, Map map)
|
||||||
|
{
|
||||||
|
this.car = new Car[playerNumber];
|
||||||
|
this.map = map;
|
||||||
|
|
||||||
|
init().run();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Game init()
|
||||||
|
{
|
||||||
|
// combien de route avant loop
|
||||||
|
int loop = this.map.getPathSize();
|
||||||
|
for (int i = 0; i < car.length; i++)
|
||||||
|
{
|
||||||
|
car[i] = new Car(loop);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isFinish()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < car.length; i++)
|
||||||
|
{
|
||||||
|
if (car[i].getFuel() == 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
while (isFinish())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user