@ -10,6 +10,7 @@ import javafx.fxml.FXML;
import javafx.geometry.Insets ;
import javafx.scene.Node ;
import javafx.scene.control.Alert ;
import javafx.scene.control.Button ;
import javafx.scene.control.ButtonType ;
import javafx.scene.control.Label ;
import javafx.scene.image.ImageView ;
@ -71,13 +72,10 @@ public class InGameLobbyController extends Controller {
private Label playerLabel6 ;
@FXML
private Label countdownLabel ;
private Button startButton ;
@FXML
private AnchorPane countdownTenPane ;
@FXML
private Label countdownTenText ;
private Button quitButton ;
private Event game ;
@ -209,37 +207,13 @@ public class InGameLobbyController extends Controller {
* Starts the race .
* /
private void startRace ( ) {
//Initialises the race clock.
initialiseRaceClock ( this . visualiserRaceEvent . getVisualiserRaceState ( ) ) ;
//Starts the race countdown timer.
countdownTimer ( ) ;
}
/ * *
* Initialises the race clock / timer labels for the start time , current time , and remaining time .
* @param visualiserRace The race to get data from .
* /
private void initialiseRaceClock ( VisualiserRaceState visualiserRace ) {
//Remaining time.
initialiseRaceClockDuration ( visualiserRace ) ;
}
/ * *
* Initialises the race duration label .
* @param visualiserRace The race to get data from .
* /
private void initialiseRaceClockDuration ( VisualiserRaceState visualiserRace ) {
visualiserRace . getRaceClock ( ) . durationProperty ( ) . addListener ( ( observable , oldValue , newValue ) - > {
Platform . runLater ( ( ) - > {
countdownLabel . setText ( newValue ) ;
} ) ;
} ) ;
}
/ * *
* Countdown timer until race starts .
* /
@ -250,19 +224,6 @@ public class InGameLobbyController extends Controller {
//Get the current race status.
RaceStatusEnum raceStatus = visualiserRaceEvent . getVisualiserRaceState ( ) . getRaceStatusEnum ( ) ;
//Try catch for getting interval times
try {
long interval = ChronoUnit . MILLIS . between ( visualiserRaceEvent . getVisualiserRaceState ( ) . getRaceClock ( ) . getCurrentTime ( ) , visualiserRaceEvent . getVisualiserRaceState ( ) . getRaceClock ( ) . getStartingTime ( ) ) ;
if ( interval < = 10000 ) {
countdownLabel . setVisible ( false ) ;
countdownTenPane . setVisible ( true ) ;
countdownTenText . setVisible ( true ) ;
}
countdownText ( interval ) ;
} catch ( Exception e ) {
}
//If the race has reached the preparatory phase, or has started...
if ( raceStatus = = RaceStatusEnum . PREPARATORY | | raceStatus = = RaceStatusEnum . STARTED ) {
@ -301,6 +262,8 @@ public class InGameLobbyController extends Controller {
this . visualiserRaceEvent . getVisualiserRaceState ( ) . getBoats ( ) . addListener ( this . lobbyUpdateListener ) ;
enableStartIfHost ( ) ;
startRace ( ) ;
} catch ( IOException e ) {
//TODO should probably let this propagate, so that we only enter this scene if everything works
@ -308,6 +271,22 @@ public class InGameLobbyController extends Controller {
}
}
/ * *
* Enables the start button if the client is the host of the game .
* /
private void enableStartIfHost ( ) {
if ( isHost ) {
startButton . setVisible ( true ) ;
startButton . setDisable ( false ) ;
} else {
startButton . setVisible ( false ) ;
startButton . setDisable ( true ) ;
}
}
/ * *
* Menu button pressed . Prompt alert then return to menu
* @throws IOException socket erro
@ -335,7 +314,7 @@ public class InGameLobbyController extends Controller {
* Start button pressed . Currently only prints out start
* /
public void startBtnPressed ( ) {
//System.out.println("Should start the race. This button is only visible for the host");
App . game . getRaceLogic ( ) . getRace ( ) . startRace ( App . game . getRaceLogic ( ) . getRace ( ) . getRacePreparatoryTime ( ) , true ) ;
}
public void joinSpecPressed ( ) {
@ -346,48 +325,5 @@ public class InGameLobbyController extends Controller {
//System.out.println("Empty race user pane pressed. Joining racers");
}
/ * *
* Countdown interval checker that updates the countdown text
* @param interval Countdown interval to check
* /
private void countdownText ( long interval ) {
countdownTenPane . setVisible ( false ) ;
//Do nothing if 5 seconds or less to go
if ( interval < = 5000 ) {
countdownTenPane . setVisible ( false ) ;
//countdownTenText.setText("5");
return ;
}
//6 seconds left. Display 1 second for countdown
if ( interval < = 6000 ) {
countdownTenText . setText ( "1" ) ;
return ;
}
//7 seconds left. Display 2 seconds for countdown
if ( interval < = 7000 ) {
countdownTenText . setText ( "2" ) ;
return ;
}
//8 seconds left. Display 3 seconds for countdown
if ( interval < = 8000 ) {
countdownTenText . setText ( "3" ) ;
return ;
}
//9 seconds left. Display 4 seconds for countdown
if ( interval < = 9000 ) {
countdownTenText . setText ( "4" ) ;
return ;
}
//10 seconds left. Display 5 seconds for countdown
if ( interval < = 10000 ) {
countdownTenText . setText ( "5" ) ;
return ;
}
}
}