fc23d4795d1042602cac8336c13051aef3552c1c
[FreeShisen] / src / de / cwde / shisensho / ShisenSho.java
1 package de.cwde.shisensho;
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 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);
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
108 if (needsReset && (view != null)) {
109 view.reset();
110 }
111 }
112
113 }
Impressum, Datenschutz