diff --git a/options.json b/options.json new file mode 100644 index 0000000..e9c9c78 --- /dev/null +++ b/options.json @@ -0,0 +1,4 @@ +{ + "difficulty": 1, + "fontSize": 20 +} diff --git a/src/game/Game.java b/src/game/Game.java index a829291..86af5b5 100644 --- a/src/game/Game.java +++ b/src/game/Game.java @@ -10,6 +10,9 @@ import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; import java.util.ArrayList; import javax.swing.BoxLayout; @@ -18,6 +21,7 @@ import javax.swing.JLabel; import javax.swing.JPanel; +import org.json.*; public class Game { /* @@ -77,7 +81,13 @@ JLabel[] hintUI; JLabel[] thunderUI; JPanel[] playersUI; + Font font; + //Options stuff + final File options = new File("options.json"); + JSONObject root; + int difficulty; + int fontSize; public static void main(String[] args) { Game game = new Game(); @@ -90,6 +100,8 @@ } private void init(){ + font = new Font("Shanghai", Font.PLAIN, fontSize); + loadOptions(); CARDS_PER_PLAYER = (NR_PLAYERS < 3) ? 5 : 4; hints = MAX_HINTS; thunders = 0; @@ -102,6 +114,24 @@ dealCards(); } + private void loadOptions(){ + try { + JSONTokener tokener = new JSONTokener(options.toURI().toURL().openStream()); + root = new JSONObject(tokener); + difficulty = root.getInt("difficulty"); + fontSize = root.getInt("fontSize"); + } catch (JSONException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + public void resetMoveValues(){ selectedPlayer = -1; chosenColor = -1; @@ -112,12 +142,9 @@ private void createPlayers(){ players = new AbstractPlayer[NR_PLAYERS]; - //playersUI = new JPanel[NR_PLAYERS]; for(int i=0; i