/**
 * An implementation of the old Lunar Lander game.
 * 
 * @author David Matuszek 
 * @version 1.1
 */
public class LunarLanderGame {
    LunarLander lander;
    static IOFrame frame = new IOFrame("Lunar Lander");
     
    /** No parameters required. */
    public static void main(String[] args) {
        LunarLanderGame game = new LunarLanderGame();
        game.run();
    }
    
    void run() {
        double safeLandingSpeed = 10.0;
        String again;
        
        do {
            lander = new LunarLander(100, 0, 15);
            frame.clear();
            displayStatus();
            while (lander.getAltitude() > 0) {
                double amount = frame.getDouble("How much fuel should I burn?");
                lander.burn(amount);
                frame.displayLine("");
                displayStatus();
            }
            double finalVelocity = lander.getVelocity();
            if (finalVelocity > safeLandingSpeed) {
                frame.display("CRASH!");
            }
            else {
                frame.display("Congratulations! A safe landing!");
            }
            do {
                frame.display("\nWould you like to play again (yes/no)?");
                again = frame.getString("Would you like to play again (yes/no)?");
            } while (!"yes".equalsIgnoreCase(again) && !"no".equalsIgnoreCase(again));
        } while ("yes".equalsIgnoreCase(again));
        frame.exit();
    }
    
    void displayStatus() {
        frame.displayLine("Altitude: " + lander.getAltitude());
        frame.displayLine("Velocity: " + lander.getVelocity());
        frame.displayLine("Fuel left: " + lander.getFuelRemaining());
    }
}
