I'm trying to display the best player name and time, so the player that has the lowest score and wrote this:
and also tried this:
And in the ArcadeScores.txt file there's this:
that I randomly added manually
Can anyone help me make this work please?
import greenfoot.*;
import java.io.*;
import java.util.ArrayList;
public class ArcScoreBoard extends Menu
{
ArrayList<String> lines = new ArrayList<String>();
public ArcScoreBoard()
{
GreenfootImage background1;
Font font1 = new Font("Defaut1", false, false, 24);
background1 = getBackground();
background1.setFont(font1);
background1.setColor(Color.BLACK);
try
{
FileReader fr = new FileReader("ArcadeScores.txt");
BufferedReader br = new BufferedReader(fr);
//String line = br.readLine();
String line = null; // sets up a local field for each line of text
while ((line = br.readLine()) != null) lines.add(line); // read each line and add them to the 'lines' list
for(int i = 0; i < lines.size(); i++)
{
String[] firstPlace = null;
String[] fullLine = lines.get(i).toString().split(";");
int score = Integer.parseInt(fullLine[0]);
if(firstPlace == null && score == i)
{
firstPlace = fullLine;
background1 .drawString("1." + firstPlace[1] + firstPlace[2], 50, 50);
}
}
}
catch(IOException e)
{
System.err.println("Caught IOException: " + e.getMessage());
}
}import greenfoot.*;
import java.io.*;
import java.util.ArrayList;
public class ArcScoreBoard extends Menu
{
ArrayList<String> lines = new ArrayList<String>();
public ArcScoreBoard()
{
GreenfootImage background1;
Font font1 = new Font("Defaut1", false, false, 24);
background1 = getBackground();
background1.setFont(font1);
background1.setColor(Color.BLACK);
}
public void act(){
try
{
FileReader fr = new FileReader("ArcadeScores.txt");
BufferedReader br = new BufferedReader(fr);
//String line = br.readLine();
String[] firstPlace = null;
String line = null; // sets up a local field for each line of text
while ((line = br.readLine()) != null) lines.add(line); // read each line and add them to the 'lines' list
for(int i = 0; i < lines.size(); i++)
{
String[] fullLine = lines.get(i).toString().split(";");
int score = Integer.parseInt(fullLine[0]);
if(firstPlace == null && score == i)
{
firstPlace = fullLine;
getBackground().drawString("1." + firstPlace[1] + firstPlace[2], 50, 50);
}
}
}
catch(IOException e)
{
System.err.println("Caught IOException: " + e.getMessage());
}
}
}
824;Player1;00:00:03.82 236;Player2;00:00:01.56 654;Player3;00:02:03:36 686;Player4;00:64:65.00 986;Player5;00:05:23.65 355;Player6;00:00:51.67
