Commit c9c7089d authored by Quentin DRUAULT-AUBIN's avatar Quentin DRUAULT-AUBIN Committed by Paul Jeannot
Browse files

[Table] Reset timer

parent c34fbf09
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="Battleship/src/main/resources"/>
<classpathentry kind="src" path="Battleship/src/test/java"/>
<classpathentry kind="src" path="Battleship/src/main/java"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>lo23-project</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
......@@ -172,6 +172,7 @@ public class IHMTableFacade implements IIHMTableToIHMMain, IIHMTableToData {
*/
@Override
public void notifyGameReady() {
System.out.println("notifygameready");
gameReady = true;
// Notify the controller the game has started.
controller.startGame();
......
......@@ -248,6 +248,11 @@ public class InGameGUIController {
* Frame for reloading a game
*/
private Timeline reloadTimeline = null;
/**
* Timer
*/
private Timeline timer;
/**
* Set the IHM Table facade.
......@@ -381,6 +386,7 @@ public class InGameGUIController {
buttonImage5.setOnMouseClicked(new SelectShipEvent(ShipType.SUBMARINE));
// Start chrono.
initTimer();
chronoTimeInit();
// Init the number of turns passed.
......@@ -590,6 +596,7 @@ public class InGameGUIController {
// Reinitialize chrono for the next turn.
chronoTimeInit();
cellToAttack = null;
// End of my turn.
switchOpponnentPane();
} catch (Exception e) {
......@@ -833,6 +840,10 @@ public class InGameGUIController {
* Function for initialize chrono
*/
private void chronoTimeInit() {
// Stop the timer.
if (timer != null) {
timer.stop();
}
switch (nbPassedTurns) {
case 0:
countdown = 30;
......@@ -856,16 +867,17 @@ public class InGameGUIController {
* Function for initialize chrono
*/
private void restartChronoTime() {
System.out.println("restartcronotime");
chronoTimeInit();
timePass();
timer.playFromStart();
}
/**
* Function for simulate chrono, using Timeline and KeyFrame import and set the label
*/
private void timePass() {
final Timeline time = new Timeline();
time.setCycleCount(Timeline.INDEFINITE);
private void initTimer() {
timer = new Timeline();
timer.setCycleCount(Timeline.INDEFINITE);
KeyFrame frame = new KeyFrame(Duration.seconds(1.1), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
......@@ -874,7 +886,7 @@ public class InGameGUIController {
countdown--;
// Time's up!
if (countdown <= 0) {
time.stop();
timer.stop();
chronoLabel.setText("00:00");
// Leave the game if te player has not played for the 3rd time.
......@@ -905,8 +917,7 @@ public class InGameGUIController {
}
});
time.getKeyFrames().add(frame);
time.playFromStart();
timer.getKeyFrames().add(frame);
}
/**
......@@ -1230,6 +1241,7 @@ public class InGameGUIController {
* @param destroyedShip : the destroyed ship or null.
*/
public void displayOpponentAttack(Coordinate coord, boolean touched, Ship destroyedShip) {
System.out.println("displayOpponentAttack");
// Get the cell.
Node cell = getNodeByRowColumnIndex(coord.getY(), coord.getX(), playerGrid);
// The opponent has touched my ship.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment