Hello, Gravity Games here, and I'm having trouble updating an array so my level's size isn't hardcoded.
Here's the code:
package scorpioengine.main; import java.awt.*; import java.io.*; import java.util.*; import java.lang.*; import javax.swing.ImageIcon; public class Level { private Scanner l; private Scanner lh; private String Header[] = new String[5]; private String stringlevelsizex = "13"; private String stringlevelsizey = "13"; private String stringmusic = "1"; private String stringtileset = "1"; private int levelsizex = Integer.parseInt(stringlevelsizex); private int levelsizey = Integer.parseInt(stringlevelsizey); private int music = Integer.parseInt(stringmusic); private int tileset = Integer.parseInt(stringtileset); private String Level[] = new String[(levelsizey)]; private Image grassek, grassektop, waterek, path1, path2; public Level(){ ImageIcon img = new ImageIcon("C://CWWGFX//GrassmainEKlarge.PNG"); grassek=img.getImage(); img = new ImageIcon("C://CWWGFX//ChompPortrait.PNG"); grassektop=img.getImage(); img = new ImageIcon("C://CWWGFX//EKWaterLarge.PNG"); waterek=img.getImage(); img = new ImageIcon("C://CWWGFX//Path1Large.PNG"); path1=img.getImage(); img = new ImageIcon("C://CWWGFX//Path2Large.PNG"); path2=img.getImage(); openHeader(); readHeader(); closeHeader(); levelsizex = Integer.parseInt(stringlevelsizex); levelsizey = Integer.parseInt(stringlevelsizey); music = Integer.parseInt(stringmusic); tileset = Integer.parseInt(stringtileset); private String Level[] = new String[(levelsizey)]; openFile(); readFile(); closeFile(); } public Image getGrassEK(){ return grassek; } public Image getGrassEKTop(){ return grassektop; } public Image getWaterEK(){ return waterek; } public Image getPath1(){ return path1; } public Image getPath2(){ return path2; } public String getLevel(int x, int y){ String index = Level[y].substring(x,x+1); return index; } public int getlevelsizex(){ return levelsizex; } public int getlevelsizey(){ return levelsizey; } public void openHeader(){ try{ lh = new Scanner(new File("C://CWWLEVELS//world1stage1cfg.txt")); }catch(Exception e){ System.out.println("error loading configuration file"); } } public void readHeader(){ while(lh.hasNext()){ for(int i=0; i < 1; i++){ stringlevelsizex=lh.next(); } for(int i=1; i < 2; i++){ stringlevelsizey=lh.next(); } for(int i=2; i < 3; i++){ stringmusic=lh.next(); } for(int i=3; i < 4; i++){ stringtileset=lh.next(); } } } public void closeHeader(){ lh.close(); } public void openFile(){ try{ l = new Scanner(new File("C://CWWLEVELS//world1stage1.txt")); }catch(Exception e){ System.out.println("error loading map"); } } public void readFile(){ while(l.hasNext()){ for(int i=0; i < ((levelsizey)); i++){ Level[i]=l.next(); } } } public void closeFile(){ l.close(); } }
For some reason, updating the array gives me an error saying that final is the only valid modifier. When I change it to final, it gives me an error saying Strings can't be converted to finals.