]>
Commit | Line | Data |
---|---|---|
d0e04237 | 1 | package de.cwde.shisensho; |
c6f3dff3 | 2 | |
3 | import android.app.Application; | |
42aa846a | 4 | import android.content.SharedPreferences; |
5 | import android.preference.PreferenceManager; | |
c6f3dff3 | 6 | import android.util.Log; |
7 | ||
8 | public class ShisenSho extends Application { | |
9 | private static ShisenSho instance = null; | |
10 | private ShisenShoView view = null; | |
11 | public ShisenShoActivity activity = null; | |
12 | ||
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 |
17 | public boolean gravity=true; | |
18 | public boolean timeCounter=true; | |
19 | ||
20 | public static void log(String msg) { | |
21 | Log.w("ShisenSho", msg); | |
22 | } | |
23 | ||
24 | public void newPlay() { | |
25 | board = new Board(); | |
26 | board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity); | |
27 | } | |
28 | ||
29 | public void setSize(int s) { | |
30 | switch (s) { | |
31 | case 1: | |
32 | size=1; | |
33 | boardSize[0]=6+2; | |
34 | boardSize[1]=8+2; | |
35 | break; | |
36 | case 2: | |
37 | size=2; | |
38 | boardSize[0]=6+2; | |
39 | boardSize[1]=12+2; | |
40 | break; | |
41 | case 3: | |
42 | default: | |
43 | size=3; | |
44 | boardSize[0]=6+2; | |
45 | boardSize[1]=16+2; | |
46 | break; | |
47 | } | |
48 | } | |
49 | ||
50 | public void sleep(int deciSeconds) { | |
51 | try { | |
52 | Thread.sleep(deciSeconds*100); | |
53 | } catch (InterruptedException e) { } | |
54 | } | |
55 | ||
56 | public ShisenSho() { | |
57 | instance = this; | |
58 | setSize(size); | |
59 | } | |
60 | ||
61 | public static synchronized ShisenSho app() { | |
62 | return instance; | |
63 | } | |
64 | ||
65 | public ShisenShoView getView() { | |
66 | if (view == null) view = new ShisenShoView(this); | |
67 | return view; | |
68 | } | |
69 | ||
70 | /** Called when the activity is first created. */ | |
29a01301 | 71 | @Override |
72 | public void onCreate() { | |
73 | super.onCreate(); | |
74 | PreferenceManager.setDefaultValues(this, R.xml.preferences, false); | |
75 | setOptions(); | |
76 | } | |
77 | ||
42aa846a | 78 | public void setOptions() { |
79 | SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this); | |
80 | ||
81 | int size = sharedPref.getInt("size", 1); | |
82 | int difficulty = sharedPref.getInt("difficulty", 1); | |
83 | boolean gravity = sharedPref.getBoolean("gravity", true); | |
84 | boolean timeCounter = sharedPref.getBoolean("timeCounter", true); | |
c6f3dff3 | 85 | |
86 | boolean needsReset = false; | |
87 | ||
88 | if (size != this.size) { | |
89 | setSize(size); | |
90 | needsReset = true; | |
91 | } | |
92 | ||
93 | if (difficulty != this.difficulty) { | |
94 | this.difficulty = difficulty; | |
95 | needsReset = true; | |
96 | } | |
97 | ||
98 | if (gravity != this.gravity) { | |
99 | this.gravity = gravity; | |
100 | needsReset = true; | |
101 | } | |
102 | ||
103 | if (timeCounter != this.timeCounter) { | |
104 | this.timeCounter = timeCounter; | |
105 | view.onTimeCounterActivate(); | |
106 | } | |
107 | ||
29a01301 | 108 | if (needsReset && (view != null)) { |
c6f3dff3 | 109 | view.reset(); |
110 | } | |
111 | } | |
112 | ||
113 | } |