-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCachedLevels.java
More file actions
43 lines (39 loc) · 1.3 KB
/
CachedLevels.java
File metadata and controls
43 lines (39 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
public class CachedLevels {
private String player;
public CachedLevels(String player) {
this.player = player;
}
public Record getRecord() {
Record c = null;
try {
HttpURLConnection conn = (HttpURLConnection) new URL("http://sokoban.heliohost.org/levelEdit.php?player=" + player).openConnection();
conn.setDoOutput(true);
Scanner s = new Scanner(new InputStreamReader(conn.getInputStream()));
if(s.hasNext()) c = new Record(s.nextLong(), s.next(), s.nextLong());
s.close();
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return c;
}
public boolean setRecord(long seed, long time) {
boolean recordHolder = false;
try {
HttpURLConnection conn = (HttpURLConnection) new URL("http://sokoban.heliohost.org/levelEdit.php?player=" + player + "&seed=" + seed + "&time=" + time).openConnection();
conn.setDoOutput(true);
Scanner s = new Scanner(new InputStreamReader(conn.getInputStream()));
if(s.hasNextInt() && s.nextInt() == 1) recordHolder = true;
s.close();
conn.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
return recordHolder;
}
}