]> git.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/ShisenSho.java
scale down veit tileset to reduce size of package
[FreeShisen] / src / de / cwde / freeshisen / ShisenSho.java
CommitLineData
92b19250 1package de.cwde.freeshisen;
c6f3dff3 2
3import android.app.Application;
42aa846a 4import android.content.SharedPreferences;
5import android.preference.PreferenceManager;
c6f3dff3 6import android.util.Log;
7
8public class ShisenSho extends Application {
9 private static ShisenSho instance = null;
10 private ShisenShoView view = null;
11 public ShisenShoActivity activity = null;
655c3517 12
c6f3dff3 13 public Board board;
14 public int[] boardSize=new int[2];
29a01301 15 public int difficulty=1; // 1=Easy, 2=Hard
c6f3dff3 16 public int size=3; // 1=Small, 2=Medium, 3=Big
e1331c9c 17 public String tilesetid = "classic";
c6f3dff3 18 public boolean gravity=true;
19 public boolean timeCounter=true;
20
c6f3dff3 21 public void newPlay() {
d8d223b4 22 loadOptions();
c6f3dff3 23 board = new Board();
24 board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity);
25 }
26
27 public void setSize(int s) {
03f986ee 28 size = s;
29
c6f3dff3 30 switch (s) {
31 case 1:
03f986ee 32 boardSize[0] = 6 + 2;
33 boardSize[1] = 8 + 2;
c6f3dff3 34 break;
35 case 2:
03f986ee 36 boardSize[0] = 6 + 2;
37 boardSize[1] = 12 + 2;
c6f3dff3 38 break;
39 case 3:
40 default:
03f986ee 41 boardSize[0] = 6 + 2;
42 boardSize[1] = 16 + 2;
c6f3dff3 43 break;
44 }
45 }
46
47 public void sleep(int deciSeconds) {
48 try {
49 Thread.sleep(deciSeconds*100);
50 } catch (InterruptedException e) { }
51 }
52
53 public ShisenSho() {
54 instance = this;
55 setSize(size);
56 }
655c3517 57
c6f3dff3 58 public static synchronized ShisenSho app() {
59 return instance;
60 }
655c3517 61
c6f3dff3 62 public ShisenShoView getView() {
63 if (view == null) view = new ShisenShoView(this);
64 return view;
65 }
655c3517 66
c6f3dff3 67 /** Called when the activity is first created. */
29a01301 68 @Override
69 public void onCreate() {
70 super.onCreate();
71 PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
03f986ee 72 Log.d("ShisenSho", "starting up...");
73 loadOptions();
74 }
75
76 private void loadOptions() {
77 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
78
79 // FIXME: handle NumberFormatException here?
80 setSize(Integer.parseInt(sp.getString("pref_size", "1")));
81 difficulty = Integer.parseInt(sp.getString("pref_diff", "1"));
82 gravity = sp.getBoolean("pref_grav", true);
83 timeCounter = sp.getBoolean("pref_time", true);
84 tilesetid = sp.getString("pref_tile", "");
29a01301 85 }
86
03f986ee 87 public void checkForChangedOptions() {
88 SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
655c3517 89
9054c57f 90 // FIXME: handle NumberFormatException here?
03f986ee 91 int size = Integer.parseInt(sp.getString("pref_size", "1"));
92 int difficulty = Integer.parseInt(sp.getString("pref_diff", "1"));
93 boolean gravity = sp.getBoolean("pref_grav", true);
94 boolean timeCounter = sp.getBoolean("pref_time", true);
95 String tilesetid = sp.getString("pref_tile", "");
c6f3dff3 96
97 boolean needsReset = false;
655c3517 98
c6f3dff3 99 if (size != this.size) {
c6f3dff3 100 needsReset = true;
101 }
655c3517 102
c6f3dff3 103 if (difficulty != this.difficulty) {
c6f3dff3 104 needsReset = true;
105 }
106
107 if (gravity != this.gravity) {
c6f3dff3 108 needsReset = true;
109 }
655c3517 110
03f986ee 111 if (timeCounter != this.timeCounter) {
112 needsReset = true;
c6f3dff3 113 }
114
07fd4c9f 115 if ((tilesetid != this.tilesetid) && (view != null)) {
03f986ee 116 // tileset can be changed without a reset
07fd4c9f 117 this.tilesetid = tilesetid;
118 view.loadTileset();
119 }
120
a8ebc470 121 if (needsReset) {
122 if ((view != null) && (activity != null)) {
123 activity.onOptionsChanged();
124 } else {
125 Log.d("ShisenSho", "Preferences changed, but no view or activity online - huh?");
126 }
c6f3dff3 127 }
07fd4c9f 128
c6f3dff3 129 }
c6f3dff3 130}
Impressum, Datenschutz