Guest User

Untitled

a guest
Feb 29th, 2016
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 25.54 KB | None | 0 0
  1. /*WARNING, THIS IS WRITTEN WHEN I WAS 13,
  2. WHEN I HAD NO UNDERSTANDING OF OPTIMISATION
  3. OR DISCRETE MATHEMATICS, OR GENERAL GAME DESIGN
  4. SO IF YOU ARE READING THIS BECAUSE I
  5. SHOWED THIS OFF, OR A CODE REVIEW,
  6. I KNOW MY CODE IS MESSY.
  7. BUT AT LEAST I DIDNT GET EATEN
  8. BY A VELOCIRAPTOR*/
  9. package server;
  10.  
  11. //Import some stuff. One is for the Socket Connection, the other is for writing stuff.
  12. import java.util.*;
  13. import java.io.*;
  14. import java.net.*;
  15.  
  16. public class server {
  17.  
  18.     /**
  19.      * The port that the server listens on.     */
  20.     static Properties prop = new Properties();
  21.     private static HashSet<PrintWriter> writers = new HashSet<PrintWriter>();
  22.     private static HashSet<String> online = new HashSet<String>();
  23.     static Properties users = new Properties();
  24.     static InputStream input = null;
  25.     static InputStream input2= null;
  26.     static OutputStream output = null;
  27.     /**
  28.      * The application main method, which just listens on a port and
  29.      * spawns handler threads.
  30.      */
  31.     public static void main(String[] args) throws Exception {
  32.         initializeServer();
  33.         System.out.println("The server is running.");
  34.         int port = Integer.parseInt(prop.getProperty("port"));
  35.         ServerSocket listener;
  36.         while (true){
  37.             try{
  38.                 listener = new ServerSocket(port);
  39.                 break;
  40.             } catch (BindException e) {
  41.                 System.out.println("Port " + port + " already in use!");
  42.                 port++;
  43.                 System.out.println("Using "+ port + " instead!");
  44.             }
  45.         }
  46.         try {
  47.             while (true) {
  48.                 new Handler(listener.accept()).start();
  49.             }
  50.         } finally {
  51.             listener.close();
  52.         }
  53.     }
  54.  
  55.     /**
  56.      * A handler thread class.  Handlers are spawned from the listening
  57.      * loop and are responsible for a dealing with a single client
  58.      * and broadcasting its messages.
  59.      */
  60.     private static class Handler extends Thread {
  61.         private String response;
  62.         private Socket socket;
  63.         private BufferedReader in;
  64.         private PrintWriter out;
  65.  
  66.         /**
  67.          * Constructs a handler thread, squirreling away the socket.
  68.          * All the interesting work is done in the run method.
  69.          */
  70.         public Handler(Socket socket) {
  71.             this.socket = socket;
  72.         }
  73.  
  74.         /**
  75.          * Services this thread's client by requesting a
  76.          * screen name until a unique one has been submitted, then
  77.          * acknowledges the name and registers the output stream for
  78.          * the client in a global set, then repeatedly gets inputs and
  79.          * broadcasts them.
  80.          */
  81.         public void run() {
  82.             String user = null;
  83.             try {
  84.                 // Create character streams for the socket.
  85.                 in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
  86.                 out = new PrintWriter(socket.getOutputStream(), true);
  87.                 // Request a name from this client.Note that
  88.                 // checking for the existence of a name and adding the name
  89.                 System.out.println("User Connected from IP: " + socket.getRemoteSocketAddress() + " !");
  90.                 out.println("Are you registering or logging in?");
  91.                 boolean notloggedin = true;
  92.                 while (notloggedin) {
  93.                     response = in.readLine();
  94.                     if (response==null){
  95.                         return;
  96.                     } else {
  97.                         switch(response.toLowerCase()){
  98.                         case "login":
  99.                             out.println("Enter your details in this format:[Username],[Password]");
  100.                             while(true){
  101.                                 response = in.readLine();
  102.                                 if (response == null){
  103.                                     return;
  104.                                 } else {
  105.                                     String[] userpass = response.split(",");
  106.                                     if ((users.getProperty(userpass[0])==null)){
  107.                                         out.println("We could not find your account!");
  108.                                         out.println("Are you registering or logging in?");
  109.                                         break;
  110.                                     }else{
  111.                                         if (users.getProperty(userpass[0]).equals(userpass[1])){
  112.                                             user=userpass[0];
  113.                                            
  114.                                             if (!online.contains(user)){
  115.                                                 synchronized(online){
  116.                                                     online.add(user);
  117.                                                 }
  118.                                                 System.out.println("IP "+socket.getRemoteSocketAddress()+" logged in as " + user);
  119.                                             } else {
  120.                                                 out.println("This user is already logged in!");
  121.                                                 out.println("Are you registering or logging in?");
  122.                                                 break;
  123.                                             }
  124.                                             notloggedin=false;
  125.                                             break;
  126.                                         }else{
  127.                                             out.println("Wrong password!");
  128.                                             out.println("Are you registering or logging in?");
  129.                                             break;
  130.                                         }
  131.                                     }
  132.                                 }
  133.                             }
  134.                             break;
  135.                         case "register":
  136.                             out.println("Enter your details in this format:[Username],[Password]");
  137.                             while(true){
  138.                                 response = in.readLine();
  139.                                 if (response == null){
  140.                                     return;
  141.                                 } else {
  142.                                     String[] userpass = response.split(",");
  143.                                     if (!(users.getProperty(userpass[0])==null)){
  144.                                         out.println("This username is already taken!");
  145.                                         out.println("Are you registering or logging in?");
  146.                                         break;
  147.                                     }else{
  148.                                         try{
  149.                                             FileOutputStream output = new FileOutputStream("./users.properties");
  150.                                             users.setProperty(userpass[0], userpass[1]);
  151.                                             users.setProperty(userpass[0]+".money", prop.getProperty("starting.money"));
  152.                                             users.setProperty(userpass[0]+".location", "");
  153.                                             users.setProperty(userpass[0]+".ship", prop.getProperty("starting.ship"));
  154.                                             users.store(output, null);
  155.                                             output.flush();
  156.                                             output.close();
  157.                                         }catch (Exception e){
  158.                                             e.printStackTrace();
  159.                                         }finally{
  160.                                             user=userpass[0];
  161.                                                 synchronized(online){
  162.                                                     online.add(user);
  163.                                                 }
  164.                                                 System.out.println("IP "+socket.getRemoteSocketAddress()+" logged in as " + user);
  165.                                             notloggedin=false;
  166.                                         }
  167.                                         break;
  168.                                     }
  169.                                 }
  170.                             }
  171.                         }
  172.                     }
  173.                  }
  174.                 if(users.getProperty(user+".location").isEmpty()){
  175.                     if(prop.getProperty("starting.location").isEmpty()){
  176.                         Random r = new Random();
  177.                         String randomloc = Integer.toString(r.nextInt(10001));
  178.                         storeProp("users",user+".location",randomloc);
  179.                     }else{
  180.                         storeProp("users",user+".location",prop.getProperty("starting.location"));
  181.                     }
  182.                 }
  183.                 out.println("Logged in as "+user);
  184.                 while (true) {
  185.                     File sector = new File("./sectors/"+users.getProperty(user+".location")+".properties");
  186.                     if (!sector.exists()){
  187.                         System.out.println("Sector " + users.getProperty(user+".location") + "does not exist! Generating!");
  188.                         initializeSector(users.getProperty(user+".location"));
  189.                     }
  190.                         //Dis where da magic happens.
  191.                         out.println("You are now in "+ users.getProperty(user+".location"));
  192.                         Properties sectorprop = new Properties();
  193.                         try{
  194.                             FileInputStream sectorinput = new FileInputStream("./sectors/"+users.getProperty(user+".location")+".properties");
  195.                             sectorprop.load(sectorinput);
  196.                             sectorinput.close();
  197.                             if (sectorprop.getProperty("station.exists") != null){
  198.                                 out.println("You see a station.");
  199.                             }
  200.                             if (sectorprop.getProperty("wormholes.1") != null){
  201.                                 out.println("You see a wormhole.");
  202.                             }
  203.                             if (sectorprop.getProperty("wormholes.2") != null){
  204.                                 out.println("You see another wormhole.");
  205.                             }
  206.                             if (sectorprop.getProperty("asteroidbelt") != null){
  207.                                 switch(sectorprop.getProperty("asteroidbelt")){
  208.                                 case "small":
  209.                                     out.println("You see a small asteroid belt");
  210.                                     break;
  211.                                 case "medium":
  212.                                     out.println("You see a medium asteroid belt");
  213.                                     break;
  214.                                 case "large":
  215.                                     out.println("You see a large asteroid belt");
  216.                                     break;
  217.                                 }
  218.                             }
  219.                             if (sectorprop.getProperty("star.exists") != null){
  220.                                 out.println("You see a star.");
  221.                             }
  222.                             if (sectorprop.getProperty("nebula") != null){
  223.                                 switch(sectorprop.getProperty("nebula")){
  224.                                 case "small":
  225.                                     out.println("You see a small nebula.");
  226.                                     break;
  227.                                 case "medium":
  228.                                     out.println("You see a medium nebula.");
  229.                                     break;
  230.                                 case "large":
  231.                                     out.println("You see a large nebula.");
  232.                                     break;
  233.                                 }
  234.                             }
  235.                             out.println("What is your command?");
  236.                         } catch (IOException e){
  237.                             e.printStackTrace();
  238.                         }
  239.                         //Print out whats in the sector
  240.                         while (true){
  241.                             response=in.readLine();
  242.                             if (response==null){
  243.                                 return;
  244.                             }
  245.                                 switch(response.toLowerCase()){
  246.                                 case "map":
  247.                                     boolean inMap = true;
  248.                                     int mapcursor = 5;
  249.                                     while (inMap){
  250.                                         int maploc = Integer.parseInt(users.getProperty(user+".location"));
  251.                                         int mapn = (maploc - 100);
  252.                                         int mape = maploc + 1; //how the fuck does increment operators work
  253.                                         int mapw = maploc - 1;
  254.                                         int maps = maploc + 100;
  255.                                         int mapne = maploc - 99;
  256.                                         int mapse = maploc + 101;
  257.                                         int mapsw = maploc + 99;
  258.                                         int mapnw = maploc - 101; //TODO EDGES SECTORS
  259.                                         out.println("+-----+-----+-----+");
  260.                                         out.println("|"+sectorThing(mapnw)+"|"+sectorThing(mapn)+"|"+sectorThing(mapne)+"|");
  261.                                         switch (mapcursor){
  262.  
  263.                                         case 1:
  264.                                             out.println("|  o  |     |     |");
  265.                                             break;
  266.                                         case 2:
  267.                                             out.println("|     |  o  |     |");                                
  268.                                             break;
  269.                                         case 3:
  270.                                             out.println("|     |     |  o  |");
  271.                                             break;
  272.                                         default:
  273.                                             out.println("|     |     |     |");
  274.                                             break; 
  275.  
  276.                                         }
  277.                                         out.println("+-----+-----+-----+");
  278.                                         out.println("|"+sectorThing(mapw)+"|"+sectorThing(maploc)+"|"+sectorThing(mape)+"|");
  279.                                         switch (mapcursor){
  280.  
  281.                                         case 4:
  282.                                             out.println("|  o  |     |     |");
  283.                                             break;
  284.                                         case 5:
  285.                                             out.println("|     |  o  |     |");                                
  286.                                             break;
  287.                                         case 6:
  288.                                             out.println("|     |     |  o  |");
  289.                                             break;
  290.                                         default:
  291.                                             out.println("|     |     |     |");
  292.                                             break; 
  293.                                         }
  294.                                         out.println("+-----+-----+-----+");
  295.                                         out.println("|"+sectorThing(mapsw)+"|"+sectorThing(maps)+"|"+sectorThing(mapse)+"|");
  296.                                         switch (mapcursor){
  297.  
  298.                                         case 7:
  299.                                             out.println("|  o  |     |     |");
  300.                                             break;
  301.                                         case 8:
  302.                                             out.println("|     |  o  |     |");                                
  303.                                             break;
  304.                                         case 9:
  305.                                             out.println("|     |     |  o  |");
  306.                                             break;
  307.                                         default:
  308.                                             out.println("|     |     |     |");
  309.                                             break; 
  310.  
  311.                                         }
  312.                                         out.println("+-----+-----+-----+");
  313.                                         while (true){
  314.                                             response = in.readLine();
  315.                                             if (response == null){
  316.                                                 return;
  317.                                             }
  318.                                                 switch (response){
  319.                                                 case "back":
  320.                                                     inMap=false;
  321.                                                     out.println("What is your command?");
  322.                                                     break;
  323.                                                 case "up":
  324.                                                     mapcursor = mapcursor - 3;
  325.                                                     break;
  326.                                                 case "down":
  327.                                                     mapcursor = mapcursor + 3;
  328.                                                     break;
  329.                                                 case "left":
  330.                                                     mapcursor--;
  331.                                                     break;
  332.                                                 case "right":
  333.                                                     mapcursor++;
  334.                                                     break;
  335.                                                 case "warp":
  336.                                                     int warp = 0;
  337.                                                     switch(mapcursor){
  338.                                                     case 1:
  339.                                                         out.println("Warp to sector "+mapnw+"? Y/N");
  340.                                                         warp = mapnw;
  341.                                                         break;
  342.                                                     case 2:
  343.                                                         out.println("Warp to sector "+mapn+"? Y/N");
  344.                                                         warp = mapn;
  345.                                                         break;
  346.                                                     case 3:
  347.                                                         out.println("Warp to sector "+mapne+"? Y/N");
  348.                                                         warp = mapne;
  349.                                                         break;
  350.                                                     case 4:
  351.                                                         out.println("Warp to sector "+mapw+"? Y/N");
  352.                                                         warp = mapw;
  353.                                                         break;
  354.                                                     case 6:
  355.                                                         out.println("Warp to sector "+mape+"? Y/N");
  356.                                                         warp = maploc;
  357.                                                         break;
  358.                                                     case 7:
  359.                                                         out.println("Warp to sector "+mapsw+"? Y/N");
  360.                                                         warp = mapsw;
  361.                                                         break;
  362.                                                     case 8:
  363.                                                         out.println("Warp to sector "+maps+"? Y/N");
  364.                                                         warp = maps;
  365.                                                         break;
  366.                                                     case 9:
  367.                                                         out.println("Warp to sector "+mapse+"? Y/N");
  368.                                                         warp = mapse;
  369.                                                         break;
  370.                                                     }
  371.                                                     while (true){
  372.                                                         response = in.readLine();
  373.                                                         if (response.toUpperCase().startsWith("Y")){
  374.                                                             try{
  375.                                                                 output = new FileOutputStream("./users.properties");
  376.                                                                 users.setProperty(user+".location", Integer.toString(warp));
  377.                                                                 users.store(output, null);
  378.                                                                 output.flush();
  379.                                                                 output.close();
  380.                                                                 inMap=false; //TODO MAJOR BUG, DISCONNECTS HERE
  381.                                                                 break;
  382.                                                             }catch(IOException ex1){
  383.                                                                 ex1.printStackTrace();
  384.                                                             }
  385.                                                         }else{
  386.                                                             out.println("What is your command?");
  387.                                                             break;
  388.                                                         }
  389.                                                     }
  390.                                                     break;
  391.                                                 }
  392.                                            
  393.                                             break;
  394.                                         }
  395.                                     }
  396.                                     break;
  397.                                 }
  398.                            
  399.                             break;
  400.                         }
  401.                     return;
  402.                 }
  403.             } catch (IOException e) {
  404.                 System.out.println(e);
  405.             } finally {
  406.                 //client goes offline
  407.                 if (user != null) {
  408.                     online.remove(user);
  409.                 }
  410.                 if (out != null) {
  411.                     writers.remove(out);
  412.                 }
  413.                 try {
  414.                     socket.close();
  415.                 } catch (IOException e) {
  416.                     e.printStackTrace();
  417.                 } finally {
  418.                     System.out.println(user+" logged out!");
  419.                 }
  420.             }
  421.         }
  422.    
  423.     }
  424.     private static void initializeServer() {
  425.         try {
  426.             File sectorFolder = new File("./sectors");
  427.             if (!sectorFolder.exists()){
  428.                 sectorFolder.mkdirs();
  429.             }
  430.             input = new FileInputStream("./server.properties");
  431.             input2 = new FileInputStream("./users.properties");
  432.  
  433.             // load a properties file
  434.             prop.load(input);
  435.             users.load(input2);
  436.         } catch (FileNotFoundException ex) {
  437.             File serverprop = new File("./server.properties");
  438.             File usersprop = new File("./users.properties");
  439.             if (!serverprop.exists()) {
  440.                 try{
  441.                     serverprop.createNewFile();
  442.                     storeProp("server","port","1337");
  443.                 }catch(IOException ex1){
  444.                     ex1.printStackTrace();
  445.                 }
  446.             } else {
  447.                 try{
  448.                     usersprop.createNewFile();
  449.                     output = new FileOutputStream("./users.properties");
  450.                     prop.store(output, "User Database");
  451.                     output.flush();
  452.                     output.close();
  453.                 }catch(IOException ex1){
  454.                     ex1.printStackTrace();
  455.                 }
  456.             }
  457.         } catch (IOException ex) {
  458.             ex.printStackTrace();
  459.             System.out.println("Could not open one of the properties file..");
  460.             return;
  461.         } finally {
  462.                 try {
  463.                     input2.close();
  464.                     input.close();
  465.                     }catch (IOException e) {
  466.                     e.printStackTrace();
  467.             }
  468.            
  469.         }
  470.         return;
  471.        
  472.     }
  473.     /*Hey you! Do you hate copying and pasting the
  474.      *same code over again to do the same stuff dealing
  475.      *with storing properties? Use this.
  476.      */
  477.     public static void storeProp(String file,String key, String value){
  478.         try{
  479.             FileOutputStream output = new FileOutputStream("./"+file+".properties");
  480.             users.setProperty(key,value);
  481.             users.store(output, null);
  482.             output.flush();
  483.             output.close();
  484.         }catch (IOException e){
  485.             e.printStackTrace();
  486.         }
  487.         return;
  488.     }
  489.     public static synchronized void initializeSector(String sectorNum){
  490.         File sector = new File("./sectors/"+sectorNum+".properties");
  491.         if (!sector.exists()){
  492.             Random sectorRand = new Random();
  493.             int PlanetsAmount = sectorRand.nextInt(8);
  494.             boolean station=false;
  495.             boolean star=false;
  496.             int wormholes=0;
  497.             int asteroidBelt=0;
  498.             int nebula=0;
  499.             int[] planets = new int[PlanetsAmount];
  500.             //Because fuck arrays.
  501.             int stationChance = sectorRand.nextInt(101);
  502.             if (stationChance>=31){
  503.                 //Yes station
  504.                 station=true;
  505.             } else {
  506.                 //No station
  507.                 station=false;
  508.             }
  509.             int wormholeChance = sectorRand.nextInt(101);
  510.             if (wormholeChance >= 76 && wormholeChance <= 90){
  511.                 //1 wormholes
  512.                 wormholes=1;
  513.             }
  514.             if (wormholeChance >= 91){
  515.                 //2 wormholes
  516.                 wormholes=2;
  517.             }
  518.             int asteroidBeltChance = sectorRand.nextInt(101);
  519.             if (asteroidBeltChance >= 31 && asteroidBeltChance <= 70){
  520.                 //Small Belt
  521.                 asteroidBelt=1;
  522.             }
  523.             if (asteroidBeltChance >= 71 && asteroidBeltChance <= 90){
  524.                 //Medium Belt
  525.                 asteroidBelt=2;
  526.             }
  527.             if (asteroidBeltChance >= 91){
  528.                 //Large Belt
  529.                 asteroidBelt=3;
  530.             }
  531.             int starChance = sectorRand.nextInt(101);
  532.             if (starChance >=51){
  533.                 star=true;
  534.                 //Yes star
  535.                 int solarSystemChance = sectorRand.nextInt(101);
  536.                 if (solarSystemChance >= 71){
  537.                     //THERE IS A SOLARSYSTEM
  538.                     //Generate planets
  539.                     for (int i=0;i<(PlanetsAmount-1);i++){
  540.                         int planetType = sectorRand.nextInt(13);
  541.                         switch (planetType){
  542.                         case 1:
  543.                             planets[i]=1;
  544.                             //Terran
  545.                             break;
  546.                         case 2:
  547.                             planets[i]=2;
  548.                             //Jungle
  549.                             break;
  550.                         case 3:
  551.                             planets[i]=3;
  552.                             //Ocean
  553.                             break;
  554.                         case 4:
  555.                             planets[i]=4;
  556.                             //Arid
  557.                             break;
  558.                         case 5:
  559.                             planets[i]=5;
  560.                             //Tundra
  561.                             break;
  562.                         case 6:
  563.                             planets[i]=6;
  564.                             //Desert
  565.                             break;
  566.                         case 7:
  567.                             planets[i]=7;
  568.                             //Arctic
  569.                             break;
  570.                         case 8:
  571.                             planets[i]=8;
  572.                             //Lava
  573.                             break;
  574.                         case 9:
  575.                             planets[i]=9;
  576.                             //Barren
  577.                             break;
  578.                         case 10:
  579.                             planets[i]=10;
  580.                             //Methane
  581.                             break;
  582.                         case 11:
  583.                             planets[i]=11;
  584.                             //Hydrogen
  585.                             break;
  586.                         case 12:
  587.                             planets[i]=12;
  588.                             //Helium
  589.                             break;
  590.                         }
  591.                     }
  592.                 }  
  593.             }
  594.             int nebulaChance = sectorRand.nextInt(101);
  595.             if (nebulaChance >= 81 && asteroidBeltChance <= 70){
  596.                 //Small Nebula
  597.                 nebula=1;
  598.             }
  599.             if (nebulaChance >= 91 && asteroidBeltChance <= 90){
  600.                 //Medium Nebula
  601.                 nebula=2;
  602.             }
  603.             if (nebulaChance >= 96){
  604.                 //Large Nebula
  605.                 nebula=3;
  606.             }
  607.             try{
  608.                 sector.createNewFile();
  609.                 Properties sect = new Properties();
  610.                 //TODO Allow for generation configuration.
  611.                 //Decide if the sector will have certain features or not.
  612.                 //Make planet size here.
  613.                         if (station==true){
  614.                             sect.setProperty("station.exists","true");
  615.                         }else{
  616.                             sect.setProperty("station.exists","false");
  617.                         }
  618.                         switch(wormholes){
  619.                         case 1:
  620.                             sect.setProperty("wormholes.1",Integer.toString(sectorRand.nextInt(10001)));
  621.                             break;
  622.                         case 2:
  623.                             sect.setProperty("wormholes.1",Integer.toString(sectorRand.nextInt(10001)));
  624.                             sect.setProperty("wormholes.2",Integer.toString(sectorRand.nextInt(10001)));
  625.                             break;
  626.                         }
  627.                         switch(asteroidBelt){
  628.                         case 1:
  629.                             sect.setProperty("asteroidbelt","small");
  630.                             break;
  631.                         case 2:
  632.                             sect.setProperty("asteroidbelt","medium");
  633.                             break;
  634.                         case 3:
  635.                             sect.setProperty("asteroidbelt","large");
  636.                             break;
  637.                         }
  638.                         if (star){
  639.                             sect.setProperty("star.exists","true");
  640.                         }else{
  641.                             sect.setProperty("star.exists","false");
  642.                         }
  643.                         switch(nebula){
  644.                         case 1:
  645.                             sect.setProperty("nebula","small");
  646.                             break;
  647.                         case 2:
  648.                             sect.setProperty("nebula","medium");
  649.                             break;
  650.                         case 3:
  651.                             sect.setProperty("nebula","large");
  652.                             break;
  653.                         }
  654.                         String size = planetSize();
  655.                         for (int i=0;i<(planets.length-1);i++){
  656.                             String num = Integer.toString(i);
  657.                         switch(planets[i]){
  658.                         case 1:
  659.                             sect.setProperty("planet."+num,"terran"+","+size);
  660.                             break;
  661.                         case 2:
  662.                             sect.setProperty("planet."+num,"jungle"+","+size);
  663.                             break;
  664.                         case 3:
  665.                             sect.setProperty("planet."+num,"ocean"+","+size);
  666.                             break;
  667.                         case 4:
  668.                             sect.setProperty("planet."+num,"arid"+","+size);
  669.                             break;
  670.                         case 5:
  671.                             sect.setProperty("planet."+num,"tundra"+","+size);
  672.                             break;
  673.                         case 6:
  674.                             sect.setProperty("planet."+num,"desert"+","+size);
  675.                             break;
  676.                         case 7:
  677.                             sect.setProperty("planet."+num,"arctic"+","+size);
  678.                             break;
  679.                         case 8:
  680.                             sect.setProperty("planet."+num,"lava"+","+size);
  681.                             break;
  682.                         case 9:
  683.                             sect.setProperty("planet."+num,"barren"+","+size);
  684.                             break;
  685.                         case 10:
  686.                             sect.setProperty("planet."+num,"methane"+","+size);
  687.                             break;
  688.                         case 11:
  689.                             sect.setProperty("planet."+num,"hydrogen"+","+size);
  690.                             break;
  691.                         case 12:
  692.                             sect.setProperty("planet."+num,"helium"+","+size);
  693.                             break;
  694.                            
  695.                         }
  696.                         }
  697.                 output= new FileOutputStream("./sectors/"+sectorNum+".properties");
  698.                 sect.store(output, null);
  699.                 return;
  700.             } catch(IOException e){
  701.                 e.printStackTrace();
  702.             }
  703.         } else{
  704.             return;
  705.         }
  706.     }
  707.     public static String planetSize(){
  708.         Random planetRand = new Random();
  709.         String size = null;
  710.         int sizeChance = planetRand.nextInt(101);
  711.         if (sizeChance <= 10){
  712.             //Tiny
  713.             size="TINY";
  714.         }
  715.         if (sizeChance >= 11 && sizeChance <= 30){
  716.             //Small
  717.             size="SMALL";
  718.         }
  719.         if (sizeChance >= 31 && sizeChance <= 70){
  720.             //Medium
  721.             size="MEDIUM";
  722.         }
  723.         if (sizeChance >= 71 && sizeChance <= 90){
  724.             //Large
  725.             size="LARGE";
  726.         }
  727.         if (sizeChance >= 91){
  728.             //Huge
  729.             size="HUGE";
  730.         }
  731.         return size;
  732.     }
  733.         public static String sectorThing(int loc){
  734.             if (loc>=10){
  735.                 if (loc>=100){
  736.                     if (loc>=1000){
  737.                         if (loc==10000){
  738.                             return Integer.toString(loc);
  739.                         }
  740.                         return " "+Integer.toString(loc);
  741.                        
  742.                     }
  743.                     return " "+Integer.toString(loc)+" ";
  744.                 }
  745.  
  746.                 return "  "+Integer.toString(loc)+" ";
  747.             }
  748.             return "  "+Integer.toString(loc)+"  ";
  749.            
  750.         }
  751. }
Add Comment
Please, Sign In to add comment