Basic Flight
Flight Max Simulator
Copyright February 2020
Griffith Rock and Roll
This is a training simulator for airline pilots. The computer randomly selects a destination represented as a point in 3D space. Your job is to reach the destination by controlling the throttle, the vertical rise, and the heading. Your calculation will have to take into account the wind speed and direction. Your only control of the plane is through the entering of integers when prompted. Non-integers will instantly cause the plane to crash. Be careful, too many failed attempts will automatically trigger the computer's own attempt to calculate the optimum flight path which will most likely overload your system and end the simulation.
This is a Java program that can be run in any online Java web compiler. Copy and paste the code into the compiler, and then redo all the quotation marks (as you should already know). Or you could theoretically type this into the Jedona Compiler on your smartphone and fly anywhere!
Happy Flying!
-CWG
import java.io.*;
import java.util.*;
import java.lang.*;
public class plane{
//ThesearealltheInstruments
double[][][] position;
double airspeed;
double Heading;
double Loft;
int Power;
int windspeed;
int wind_direction;
double Vector;
public static void main(String args[]){
Random rand = new Random();
//SetWindConditions
int windspeed = rand.nextInt(25);
int wind_direction = rand.nextInt(360);
//CalculateWindFactor
double Vector = windspeed*Math.sin(wind_direction);
//CreateAirplane
plane plane = new plane();
//CreateScannerforInput
Scanner console = new Scanner(System.in);
double[][][] Destination = new double[2][2][2];
int f = rand.nextInt();
int g = rand.nextInt();
int h = rand.nextInt();
//InitializeDestinationArray
Destination[1][0][0] = f;
Destination[0][1][0] = g;
Destination[0][0][1] = h;
System.out.print("Welcome to Basic Flight! Only Enter Integers or you will crash!");
System.out.println("Your Destination is at:");
System.out.println(Arrays.deepToString(Destination));
//InitializeVariables
int i = 0;
int p =0;
int q = 0;
int t = 0;
int Score = 0;
//InitiateLoopForGaming
while (windspeed >= 0){
System.out.println("Wind speed is: " + windspeed);
System.out.println("Wind direction is: "+ wind_direction);
//ObtainNominalHeading
System.out.println("Enter Heading:");
int heading = console.nextInt();
//ObtainNominalLoft(VerticalRise)
System.out.println("Enter Vertical Rise:");
int loft = console.nextInt();
//SetThrottle
System.out.println("Set Throttle:");
int Power = Throttle();
//FindActualHeading
double Heading = heading - Math.atan(plane.Vector/plane.Power*loft/100);
//FindActualAirspeed
double airspeed = plane.Power*loft/100/Math.sin(Math.atan(plane.Vector/plane.Power*loft/100));
//FindActualVerticalRise
double Loft = airspeed+loft/2;
//IfPlanePositionequalsDestinationthenSuccess!
if (Position(i,p,q,t,Heading,Loft,airspeed)==Destination){
Score++;
System.out.println("Score is: "+Score);
System.out.println(Arrays.deepToString(Position(i,p,q,t,Heading,Loft,airspeed)));
break;
}
//If Not Then Repeat Process
else{
Score--;
System.out.println("Score is: "+Score);
System.out.println(Arrays.deepToString(Position(i,p,q,t,Heading,Loft,airspeed)));
//TooManyFailuresInitiatesAutoPilot
if (Score ==-10){
//CalculateOptimumPathViaAutoPilot
System.out.println("Optimum Course:");
System.out.println("Set heading to: "+Head(Destination,Vector));
double lofting = Destination[0][0][1]/10;
System.out.println("Set rise to: "+ lofting);
System.out.println("Set throttle to: "+Pow(Destination,Vector));
}
}
}
}
//FindBestHeading
public static double Head(double[][][]Destination, double Vector){
double loft = Destination[0][0][1]/10;
double airspeed = Destination[0][1][0]/Math.sin(Head(Destination, Vector));
double heading = Math.acos(airspeed/Destination[1][0][0]) + Math.atan(Vector/Pow(Destination, Vector)*loft/100);
double head = Math.asin(airspeed/Destination[0][1][0]) + Math.atan(Vector/Pow(Destination, Vector)*loft/100);
return (heading+head)/2;
}
//FindCorrectPower
public static double Pow(double[][][]Destination, double Vector){
double loft = Destination[0][0][1]/10;
double airspeed = Destination[0][1][0]/Math.sin(Head(Destination, Vector));
double power = airspeed/(loft/100/Math.sin(Head(Destination, Vector)));
return power;
}
public static double[][][] Position(int i, int p, int q, int t, double Heading, double Loft, double airspeed){
//InitializeArray
double[][][] Pos = new double[2][2][2];
//CalculateFlightPath
while (t <= 9){
//IterateAllVariablesOverLoop
t++;
p++;
i++;
q++;
//InitializeArrayValuesposition = new double[11][11][11];
Pos[i][0][0]= airspeed*Math.cos(Heading)*t;
Pos[0][p][0] = airspeed*Math.sin(Heading)*t;
Pos[0][0][q] = Loft*t;
return Pos;
}
return Position(i,p,q,t,Heading,Loft,airspeed);
}
//FunctionForThrottle
public static int Throttle(){
Scanner console = new Scanner(System.in);
int throttle = console.nextInt();
return throttle;
}
}
Comments
Post a Comment