mirror of
https://github.com/guezoloic/racing-game.git
synced 2026-03-28 18:03:50 +00:00
feat: ajout getters
This commit is contained in:
@@ -109,4 +109,9 @@ public class Car implements GObserver
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getPos()
|
||||||
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ public class Game
|
|||||||
private Map map;
|
private Map map;
|
||||||
|
|
||||||
private ArrayList<GObserver> obs;
|
private ArrayList<GObserver> obs;
|
||||||
|
private final int time = 1000;
|
||||||
|
|
||||||
public static class Builder
|
public static class Builder
|
||||||
{
|
{
|
||||||
@@ -122,7 +123,7 @@ public class Game
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
step();
|
step();
|
||||||
Thread.sleep(1000);
|
Thread.sleep(time);
|
||||||
}
|
}
|
||||||
catch (InterruptedException e)
|
catch (InterruptedException e)
|
||||||
{ e.printStackTrace(); }
|
{ e.printStackTrace(); }
|
||||||
|
|||||||
@@ -1,33 +1,11 @@
|
|||||||
public class Main {
|
public class Main {
|
||||||
public static void main(String[] args) throws InterruptedException {
|
public static void main(String[] args) throws InterruptedException
|
||||||
// Map m = Map.fromChars(new Character[][] {
|
{
|
||||||
// {'3', '#', '2'},
|
|
||||||
// {'#', ' ', 'S'},
|
|
||||||
// {'9', '#', 'F'},
|
|
||||||
// });
|
|
||||||
|
|
||||||
Game game = new Game.Builder()
|
Game game = new Game.Builder()
|
||||||
.defaultMap()
|
.defaultMap()
|
||||||
.setPlayers(3)
|
.setPlayers(3)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
Thread t = new Thread(() -> {
|
|
||||||
int i = 0;
|
|
||||||
while (i++ < 10)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(5000);
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
System.out.println(game.togglePause() ? "stop" : "fini" );
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
t.start();
|
|
||||||
game.run();
|
game.run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
16
src/Map.java
16
src/Map.java
@@ -22,6 +22,8 @@ public class Map
|
|||||||
*/
|
*/
|
||||||
private ArrayList<Point> pathMap;
|
private ArrayList<Point> pathMap;
|
||||||
|
|
||||||
|
private int width, height;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée une nouvelle instance de Map à partir d'un tableau générique
|
* Crée une nouvelle instance de Map à partir d'un tableau générique
|
||||||
* et d'une fonction de transformation.
|
* et d'une fonction de transformation.
|
||||||
@@ -108,6 +110,10 @@ public class Map
|
|||||||
private Map(Circuit[][] map)
|
private Map(Circuit[][] map)
|
||||||
{
|
{
|
||||||
this.map = map;
|
this.map = map;
|
||||||
|
|
||||||
|
this.width = map[0].length;
|
||||||
|
this.height = map.length;
|
||||||
|
|
||||||
boolean isPossible = this.buildPath();
|
boolean isPossible = this.buildPath();
|
||||||
|
|
||||||
if (!isPossible)
|
if (!isPossible)
|
||||||
@@ -280,4 +286,14 @@ public class Map
|
|||||||
{
|
{
|
||||||
return this.pathMap.size();
|
return this.pathMap.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getWidth()
|
||||||
|
{
|
||||||
|
return this.width;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight()
|
||||||
|
{
|
||||||
|
return this.height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user