Advertisement
One_Step_Ahead

LevelCreator(Error)

Jun 3rd, 2014
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.73 KB | None | 0 0
  1. package ld29;
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class LevelCreator {
  6.     private static Scanner x;
  7.     public static void main (String[] args) throws IOException{
  8.         int count1 = 0, count2 =0, count3=0;
  9.         for(int k=1;k<=3;k++){
  10.             if (k == 1){
  11.                 try{
  12.                     x = new Scanner(new File("background.txt"));
  13.                 }
  14.                 catch(Exception e){
  15.                     System.out.println("Could not find file");
  16.                 }
  17.                 while(x.hasNextLine()){
  18.                     count1++;
  19.                     x.nextLine();
  20.                 }
  21.                 x.close();
  22.             }
  23.             else if (k == 2){
  24.                 try{
  25.                     x = new Scanner(new File("objects.txt"));
  26.                 }
  27.                 catch(Exception e){
  28.                     System.out.println("Could not find file");
  29.                 }
  30.                 while(x.hasNextLine()){
  31.                     count2++;
  32.                     x.nextLine();
  33.                 }
  34.                 x.close();
  35.             }
  36.             else{
  37.                 try{
  38.                     x = new Scanner(new File("characters.txt"));
  39.                 }
  40.                 catch(Exception e){
  41.                     System.out.println("Could not find file");
  42.                 }
  43.                 while(x.hasNextLine()){
  44.                     count3++;
  45.                     x.nextLine();
  46.                 }
  47.                 x.close();
  48.             }
  49.         }
  50.         System.out.println(count1+" "+count2+" "+count3);
  51.         int Lengths1[] = new int [count1];
  52.         int Lengths2[] = new int [count2];
  53.         int Lengths3[] = new int [count3];
  54.        
  55.         for(int l=1;l<=3;l++){
  56.             if (l == 1){
  57.                 try{
  58.                     x = new Scanner(new File("background.txt"));
  59.                 }
  60.                 catch(Exception e){
  61.                     System.out.println("Could not find file");
  62.                 }
  63.                 for(int i=0;i<count1;i++){
  64.                     while(x.hasNextLine()){
  65.                         String a = x.next();
  66.                         Lengths1[i] = a.length();
  67.                         System.out.print(Lengths1[i]+" ");
  68.                         break;
  69.                     }
  70.                 }
  71.                 x.close();
  72.             }
  73.             else if (l == 2){
  74.                 try{
  75.                     x = new Scanner(new File("objects.txt"));
  76.                 }
  77.                 catch(Exception e){
  78.                     System.out.println("Could not find file");
  79.                 }
  80.                 System.out.println(" ");
  81.                 for(int i=0;i<count1;i++){
  82.                     while(x.hasNextLine()){
  83.                         String a = x.next();
  84.                         Lengths2[i] = a.length();
  85.                         System.out.print(Lengths2[i]+" ");
  86.                         break;
  87.                     }
  88.                 }
  89.                 x.close();
  90.             }
  91.             else{
  92.                 try{
  93.                     x = new Scanner(new File("characters.txt"));
  94.                 }
  95.                 catch(Exception e){
  96.                     System.out.println("Could not find file");
  97.                 }
  98.                 System.out.println(" ");
  99.                 for(int i=0;i<count1;i++){
  100.                     while(x.hasNextLine()){
  101.                         String a = x.next();
  102.                         Lengths3[i] = a.length();
  103.                         System.out.print(Lengths3[i]+" ");
  104.                         break;
  105.                     }
  106.                 }
  107.        
  108.        
  109.             }
  110.  
  111.         }
  112.         System.out.println(" ");
  113.         int max1=0, max2=0, max3=0;
  114.         for(int m=1;m<=3;m++){
  115.             if (m==1){
  116.                 for (int i=0;i<count1;i++){
  117.                     if (Lengths1[i] > max1){
  118.                         max1 = Lengths1[i];
  119.                     }
  120.                 }
  121.                 System.out.println(max1);
  122.             }
  123.             else if (m == 2){
  124.                 for (int i=0;i<count3;i++){
  125.                     if (Lengths2[i] > max2){
  126.                         max2 = Lengths2[i];
  127.                     }
  128.                 }
  129.                 System.out.println(max2);
  130.             }
  131.             else{
  132.                 for (int i=0;i<count3;i++){
  133.                     if (Lengths3[i] > max3){
  134.                         max3 = Lengths3[i];
  135.                     }
  136.                 }
  137.                 System.out.println(max3);
  138.             }
  139.            
  140.         }
  141.         char background[][] = new char [count1][max1];
  142.         char objects[][] = new char [count2][max2];
  143.         char characters[][] = new char [count3][max3];
  144.         for(int n=0;n<=3;n++){
  145.             if (n == 1){
  146.                 try {
  147.                     FileInputStream fileinput = new FileInputStream("background.txt");
  148.                     int r;
  149.                     for(int i=0;i<count1;i++){
  150.                         for(int j=0;j<max1;j++){
  151.                             while((r = fileinput.read()) != -1){
  152.                                 char c = (char) r;
  153.                                 background[i][j] = c;
  154.                                 break;
  155.                             }
  156.                         }
  157.                     }
  158.                     fileinput.close();
  159.                 }
  160.                
  161.                 catch (FileNotFoundException e) {
  162.                     // TODO Auto-generated catch block
  163.                     e.printStackTrace();
  164.                 }
  165.                
  166.             }
  167.         }
  168.         for (int i=0;i<count1;i++){
  169.             for(int j=0;j<max1;j++){
  170.                 System.out.print(background[i][j]);
  171.             }
  172.         }
  173.         System.out.println(background[13][19]);
  174.     }
  175. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement