]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/freeshisen/ShisenSho.java
update about box a bit.
[FreeShisen] / src / de / cwde / freeshisen / ShisenSho.java
1 package de.cwde.freeshisen;
2
3 import android.app.Application;
4 import android.content.SharedPreferences;
5 import android.preference.PreferenceManager;
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];
15 public int difficulty=1; // 1=Easy, 2=Hard
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. */
71 @Override
72 public void onCreate() {
73 super.onCreate();
74 PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
75 setOptions();
76 }
77
78 public void setOptions() {
79 SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
80
81 // FIXME: handle NumberFormatException here?
82 int size = Integer.parseInt(sharedPref.getString("pref_size", "1"));
83 int difficulty = Integer.parseInt(sharedPref.getString("pref_diff", "1"));
84 boolean gravity = sharedPref.getBoolean("pref_grav", true);
85 boolean timeCounter = sharedPref.getBoolean("pref_time", true);
86
87 boolean needsReset = false;
88
89 if (size != this.size) {
90 setSize(size);
91 needsReset = true;
92 }
93
94 if (difficulty != this.difficulty) {
95 this.difficulty = difficulty;
96 needsReset = true;
97 }
98
99 if (gravity != this.gravity) {
100 this.gravity = gravity;
101 needsReset = true;
102 }
103
104 if (timeCounter != this.timeCounter) {
105 this.timeCounter = timeCounter;
106 view.onTimeCounterActivate();
107 }
108
109 if (needsReset && (view != null)) {
110 view.reset();
111 }
112 }
113
114 }
Impressum, Datenschutz