mitrolex wrote...
I wanted to ask where and how should i define the 'n' variable because of "cannot find symbol - variable n"?
I'm an idiot, i know.for (int n=0; n<data.length; n++) { System.out.println((String)data[n][0]+": "+(Integer)data[n][1]); }
import greenfoot.*; import java.io.*; import javax.swing.JOptionPane; public class bg extends World { boolean p=false; int razmak_cevi=100; int cevbr=0; int ptbr=0; int score=0; int prva_cev=230; int zmbr=0; skor skorObj=new skor(); boolean pocetak=false; String line = null; String inputValue=null; String c=null; BufferedWriter file = null; BufferedReader br = null; BufferedReader br1=null; BufferedWriter f = null; public bg() { super(600, 400, 1,false); setPaintOrder(rank.class,kraj.class,skor.class,najskor.class,tvsk.class,ptica.class,zemlja.class,cev.class,cevnadole.class); ptica pt = new ptica(); addObject(pt, 100, getHeight()/2-50); zemlja Zemlja = new zemlja(); addObject(Zemlja, 500, 375); skorObj.postaviskor(0); addObject(skorObj ,getWidth()/2,getHeight()/2-100); rank r = new rank(); addObject(r,30,20); } public void act() { if(Greenfoot.isKeyDown("space")==true && pocetak==false) { Greenfoot.delay(5); pocetak=true; } if(pocetak==true) { cevbr++; if (cevbr % 100 == 0) { stvoricev(); } if(cevbr >= prva_cev) { if(ptbr % 100 ==0) { score++; skorObj.postaviskor(score); Greenfoot.playSound("sfxpoint.mp3"); } ptbr++; } } zmbr++; if(zmbr%100==0) { stvorizemlju(); } ptica a = (ptica) getObjects(ptica.class).get(0); if (a != null) { if (a.touchingCev() || a.touchingZemlja() || a.touchingCevnadole()) { krajigre(); kraj(); } } try { br = new BufferedReader(new FileReader("skorevi/najscore.txt")); line = br.readLine(); br.close(); } catch(IOException ioe) { System.out.println(ioe); try { br.close(); } catch (IOException x){} line = "0"; } try { br1 = new BufferedReader(new FileReader("skorevi/rank.txt")); c = br1.readLine(); br.close(); } catch(IOException ioe) { System.out.println(ioe); try { br.close(); } catch (IOException x){} c = "0"; } if(score>Integer.parseInt(line)) { try { file = new BufferedWriter(new FileWriter("skorevi/najscore.txt")); file.write(""+score); file.close(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { file.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } } if(p==true) { try { f = new BufferedWriter(new FileWriter("skorevi/rank.txt")); f.write(""+c+inputValue+":"+score+"::"); f.close(); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { f.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } rank(); } } private void stvoricev() { cevnadole Cevnd = new cevnadole(); cev Cev = new cev(); GreenfootImage image = Cevnd.getImage(); addObject(Cev,getWidth(),getHeight()/2 + image.getHeight()- Greenfoot.getRandomNumber(200)); addObject(Cevnd,getWidth(),Cev.getY() - image.getHeight() - razmak_cevi); } private void stvorizemlju() { zemlja Zemlja = new zemlja(); addObject(Zemlja, 500, 375); } public void kraj() { p=true; Greenfoot.playSound("sfxhit.mp3"); tvsk kr = new tvsk(); addObject(kr,300,130); inputValue= JOptionPane.showInputDialog("UNESI SVOJE IME:"); if(inputValue==null) { inputValue="Bezimeni"; } Greenfoot.stop(); } public void krajigre() { Color c = new Color(0,0,0,0); Actor ns = new najskor(); addObject(ns, 341, 220); ns.setImage(new GreenfootImage(""+Integer.parseInt(line), 35, Color.BLACK, c)); } public void rank() { String temp = line; int recordCount = 0; while (!"".equals(temp)) { temp = temp.substring(temp.indexOf("::")+2); recordCount++; } Object[][] data = new Object[recordCount][2]; for (int i=0; i<recordCount; i++) { int recLen = line.indexOf("::"); String record = line.substring(0, recLen); line = line.substring(recLen+2); int nameLen = record.indexOf(":"); data[i][0] = record.substring(0, nameLen); data[i][1] = Integer.valueOf(record.substring(nameLen+1)); } for (int n=0; n<data.length; n++) { System.out.println((String)data[n][0]+": "+(Integer)data[n][1]); } } }
private String getOutputString(Object[][] data) { for (int i=1; i<data.length; i++) { int n = i; while (n > 0 && (Integer)data[n][1] > (Integer)data[n-1][1]) { Object[] hold = data[n-1]; data[n-1] - data[n]; data[n] = hold; n--; } } String outputLine = ""; for (int i=0; i<data.length; i++) outputLine += data[i][0]+":"+data[i][1]+"::"; return outputLine; }
int bestHighScore = (Integer)data[0][1];
String topPlayer = (String)data[0][0];
System.out.println("'"+line+"'");