]> cvs.zerfleddert.de Git - FreeShisen/blame - src/de/cwde/freeshisen/ShisenSho.java
Allow selecting tileset.
[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
07fd4c9f 17 public int tilesetid = R.drawable.classic;
c6f3dff3 18 public boolean gravity=true;
19 public boolean timeCounter=true;
20
21 public static void log(String msg) {
22 Log.w("ShisenSho", msg);
23 }
24
25 public void newPlay() {
26 board = new Board();
27 board.buildRandomBoard(boardSize[0],boardSize[1],difficulty,gravity);
28 }
29
30 public void setSize(int s) {
31 switch (s) {
32 case 1:
33 size=1;
34 boardSize[0]=6+2;
35 boardSize[1]=8+2;
36 break;
37 case 2:
38 size=2;
39 boardSize[0]=6+2;
40 boardSize[1]=12+2;
41 break;
42 case 3:
43 default:
44 size=3;
45 boardSize[0]=6+2;
46 boardSize[1]=16+2;
47 break;
48 }
49 }
50
51 public void sleep(int deciSeconds) {
52 try {
53 Thread.sleep(deciSeconds*100);
54 } catch (InterruptedException e) { }
55 }
56
57 public ShisenSho() {
58 instance = this;
59 setSize(size);
60 }
655c3517 61
c6f3dff3 62 public static synchronized ShisenSho app() {
63 return instance;
64 }
655c3517 65
c6f3dff3 66 public ShisenShoView getView() {
67 if (view == null) view = new ShisenShoView(this);
68 return view;
69 }
655c3517 70
c6f3dff3 71 /** Called when the activity is first created. */
29a01301 72 @Override
73 public void onCreate() {
74 super.onCreate();
75 PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
76 setOptions();
77 }
78
42aa846a 79 public void setOptions() {
80 SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
655c3517 81
9054c57f 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);
07fd4c9f 87 int tilesetid = tilesetStringToRes(sharedPref.getString("pref_tile", ""));
c6f3dff3 88
89 boolean needsReset = false;
655c3517 90
c6f3dff3 91 if (size != this.size) {
92 setSize(size);
93 needsReset = true;
94 }
655c3517 95
c6f3dff3 96 if (difficulty != this.difficulty) {
97 this.difficulty = difficulty;
98 needsReset = true;
99 }
100
101 if (gravity != this.gravity) {
102 this.gravity = gravity;
103 needsReset = true;
104 }
655c3517 105
d6b1a9d7 106 if ((timeCounter != this.timeCounter) && (view != null)) {
c6f3dff3 107 this.timeCounter = timeCounter;
108 view.onTimeCounterActivate();
109 }
110
07fd4c9f 111 if ((tilesetid != this.tilesetid) && (view != null)) {
112 this.tilesetid = tilesetid;
113 view.loadTileset();
114 }
115
29a01301 116 if (needsReset && (view != null)) {
c6f3dff3 117 view.reset();
118 }
07fd4c9f 119
c6f3dff3 120 }
121
07fd4c9f 122 private int tilesetStringToRes(String s)
123 {
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 {
133 return R.drawable.classic;
134 }
135 }
c6f3dff3 136}
Impressum, Datenschutz