]> cvs.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/ShisenSho.java
more adaptions.
[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
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 }
655c3517 60
c6f3dff3 61 public static synchronized ShisenSho app() {
62 return instance;
63 }
655c3517 64
c6f3dff3 65 public ShisenShoView getView() {
66 if (view == null) view = new ShisenShoView(this);
67 return view;
68 }
655c3517 69
c6f3dff3 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);
655c3517 80
9054c57f 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);
c6f3dff3 86
87 boolean needsReset = false;
655c3517 88
c6f3dff3 89 if (size != this.size) {
90 setSize(size);
91 needsReset = true;
92 }
655c3517 93
c6f3dff3 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 }
655c3517 103
d6b1a9d7 104 if ((timeCounter != this.timeCounter) && (view != null)) {
c6f3dff3 105 this.timeCounter = timeCounter;
106 view.onTimeCounterActivate();
107 }
108
29a01301 109 if (needsReset && (view != null)) {
c6f3dff3 110 view.reset();
111 }
112 }
113
114}
Impressum, Datenschutz