-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettings.java
More file actions
73 lines (62 loc) · 2.1 KB
/
Copy pathSettings.java
File metadata and controls
73 lines (62 loc) · 2.1 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import java.sql.*;
public class Settings {
private String mode = "Singleplayer";
private int boardSize = 3;
private boolean musicEnabled = true;
public Settings() {
loadSettings();
}
public void loadSettings() {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:settings.db")) {
Statement stmt = conn.createStatement();
stmt.execute("CREATE TABLE IF NOT EXISTS settings (mode TEXT, boardSize INTEGER, music INTEGER)");
ResultSet rs = stmt.executeQuery("SELECT * FROM settings");
if (rs.next()) {
mode = rs.getString("mode");
boardSize = rs.getInt("boardSize");
musicEnabled = rs.getInt("music") == 1;
} else {
saveSettings();
}
} catch (SQLException e) {
System.err.println("Failed to load settings: " + e.getMessage());
}
}
public void saveSettings() {
try (Connection conn = DriverManager.getConnection("jdbc:sqlite:settings.db")) {
Statement stmt = conn.createStatement();
stmt.execute("DELETE FROM settings");
PreparedStatement ps = conn.prepareStatement("INSERT INTO settings VALUES (?, ?, ?)");
ps.setString(1, mode);
ps.setInt(2, boardSize);
ps.setInt(3, musicEnabled ? 1 : 0);
ps.execute();
} catch (SQLException e) {
System.err.println("Failed to save settings: " + e.getMessage());
}
}
public void reset() {
mode = "Singleplayer";
boardSize = 3;
musicEnabled = true;
saveSettings();
}
public String getMode() {
return mode;
}
public void setMode(String mode) {
this.mode = mode;
}
public int getBoardSize() {
return boardSize;
}
public void setBoardSize(int boardSize) {
this.boardSize = boardSize;
}
public boolean isMusicEnabled() {
return musicEnabled;
}
public void setMusicEnabled(boolean musicEnabled) {
this.musicEnabled = musicEnabled;
}
}