]> git.zerfleddert.de Git - FreeShisen/blob - src/de/cwde/shisensho/ShisenSho.java
654e4e0f0c9f988bfdcbd2cb6cf855447cc6932a
[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=Hard, 2=Easy
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 }
76
77 public void setOptions() {
78 SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
79
80 int size = sharedPref.getInt("size", 1);
81 int difficulty = sharedPref.getInt("difficulty", 1);
82 boolean gravity = sharedPref.getBoolean("gravity", true);
83 boolean timeCounter = sharedPref.getBoolean("timeCounter", true);
84
85 boolean needsReset = false;
86
87 if (size != this.size) {
88 setSize(size);
89 needsReset = true;
90 }
91
92 if (difficulty != this.difficulty) {
93 this.difficulty = difficulty;
94 needsReset = true;
95 }
96
97 if (gravity != this.gravity) {
98 this.gravity = gravity;
99 needsReset = true;
100 }
101
102 if (timeCounter != this.timeCounter) {
103 this.timeCounter = timeCounter;
104 view.onTimeCounterActivate();
105 }
106
107 if (needsReset) {
108 view.reset();
109 }
110 }
111
112 }
Impressum, Datenschutz