@@ -32,7 +32,10 @@ public class LevelReader {
private static Level readLevel(List<String> levelfile) throws NumberFormatException, IllegalArgumentException, IllegalAccessException, NoSuchFieldException, SecurityException {
Level level = new Level();
- if (levelfile.size() == 2) {
+ if (levelfile.size() == 3) {
+ int levelnum = Integer.parseInt(levelfile.get(0));
+ level.setNum(levelnum);
+
String[] ballsstrings = levelfile.get(0).split("\\|"); // split all
// the balls
for (String ball : ballsstrings) {
@@ -2,6 +2,7 @@ package server.match;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.ListIterator;
import java.util.Timer;
@@ -45,6 +46,7 @@ public class Match implements Runnable {
this.nwuser2 = nwuser2;
System.out.println("New Match!");
levels = LevelReader.readLevelsFromFiles();
+ Collections.sort(levels);
playLevel(getCurrentLevel());
timer = new Timer();
@@ -5,14 +5,25 @@ import java.util.List;
import server.match.objects.Ball;
-public class Level {
+public class Level implements Comparable<Level>{
private List<Ball> startballs;
private int time;
-
+ private int num;
//Contains all the info to start a level
public Level() {
this.startballs = new ArrayList<Ball>();
}
+ public void setNum(int num)
+ {
+ this.num = num;
+ }
+ public int getNum()
+ return num;
public void addBall(Ball b) {
startballs.add(b);
@@ -30,4 +41,14 @@ public class Level {
return time;
+ @Override
+ public int compareTo(Level l) {
+ int rt = 0;
+ if(num < l.getNum())
+ rt = -1;
+ else if(num > l.getNum())
+ rt = 1;
+ return rt;
@@ -1,2 +1,3 @@
+1
2,200,red,200,400,-1,0.0
18000
+2
2,200,green,200,200,-1,0.0|3,300,magenta,500,200,1,0.0
30000
+3
2,200,green,200,200,-1,0.0|3,300,magenta,350,200,1,0.0|2,150,yellow,500,100,1,0.0
40000
+4
4,400,blue,600,100,-1,0.0
+5
7,650,green,300,100,1,0.0
120000
+6
4,500,magenta,200,300,-1,0.0|5,400,yellow,300,200,1,0.0|3,500,blue,600,350,-1,0.0
@@ -1,11 +1,9 @@
package main;
public class Main {
public static void main(String[] args) {
//Start new game
new Window();