1 package de
.cwde
.freeshisen
;
3 import android
.app
.Application
;
4 import android
.content
.SharedPreferences
;
5 import android
.preference
.PreferenceManager
;
6 import android
.util
.Log
;
8 public class ShisenSho
extends Application
{
9 private static ShisenSho instance
= null;
10 private ShisenShoView view
= null;
11 public ShisenShoActivity activity
= null;
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 int tilesetid
= R
.drawable
.classic
;
18 public boolean gravity
=true;
19 public boolean timeCounter
=true;
21 public static void log(String msg
) {
22 Log
.w("ShisenSho", msg
);
25 public void newPlay() {
27 board
.buildRandomBoard(boardSize
[0],boardSize
[1],difficulty
,gravity
);
30 public void setSize(int s
) {
51 public void sleep(int deciSeconds
) {
53 Thread
.sleep(deciSeconds
*100);
54 } catch (InterruptedException e
) { }
62 public static synchronized ShisenSho
app() {
66 public ShisenShoView
getView() {
67 if (view
== null) view
= new ShisenShoView(this);
71 /** Called when the activity is first created. */
73 public void onCreate() {
75 PreferenceManager
.setDefaultValues(this, R
.xml
.preferences
, false);
79 public void setOptions() {
80 SharedPreferences sharedPref
= PreferenceManager
.getDefaultSharedPreferences(this);
82 // FIXME: handle NumberFormatException here?
83 int size
= Integer
.parseInt(sharedPref
.getString("pref_size", "1"));
84 int difficulty
= Integer
.parseInt(sharedPref
.getString("pref_diff", "1"));
85 boolean gravity
= sharedPref
.getBoolean("pref_grav", true);
86 boolean timeCounter
= sharedPref
.getBoolean("pref_time", true);
87 int tilesetid
= tilesetStringToRes(sharedPref
.getString("pref_tile", ""));
89 boolean needsReset
= false;
91 if (size
!= this.size
) {
96 if (difficulty
!= this.difficulty
) {
97 this.difficulty
= difficulty
;
101 if (gravity
!= this.gravity
) {
102 this.gravity
= gravity
;
106 if ((timeCounter
!= this.timeCounter
) && (view
!= null)) {
107 this.timeCounter
= timeCounter
;
108 view
.onTimeCounterActivate();
111 if ((tilesetid
!= this.tilesetid
) && (view
!= null)) {
112 this.tilesetid
= tilesetid
;
116 if (needsReset
&& (view
!= null)) {
122 private int tilesetStringToRes(String s
)
124 if (s
.equals("classic")) {
125 return R
.drawable
.classic
;
126 } else if (s
.equals("jade")) {
127 return R
.drawable
.jade
;
128 } else if (s
.equals("traditional")) {
129 return R
.drawable
.traditional
;
130 } else if (s
.equals("pixel")) {
131 return R
.drawable
.pixel
;
132 } else if (s
.equals("original")) {
133 return R
.drawable
.original
;
134 } else if (s
.equals("veit")) {
135 return R
.drawable
.veit
;
137 // shouldn't be reached...
138 Log
.e("ShisenSho", "somebody managed to set an invalid tileset string");
139 return R
.drawable
.classic
;