-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.java
More file actions
230 lines (189 loc) · 8.69 KB
/
MainActivity.java
File metadata and controls
230 lines (189 loc) · 8.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
package com.example.felixhankel.charactersheetds;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onStart(){
super.onStart();
final File dir = getFilesDir();
load();
ListAdpaterSetUp();
InitiateLists();
TextView Namensschild = (TextView) (findViewById(R.id.textView));
Namensschild.setText(Stats.name);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button D20 = (findViewById(R.id.buttonD20));
Button D6 = (findViewById(R.id.buttonD6));
D20.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Random r = new Random();
String rand =String.valueOf( r.nextInt(21-1)+1);
Toast.makeText(getApplicationContext(),rand,Toast.LENGTH_LONG).show();
}
});
D6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Random r = new Random();
String rand =String.valueOf( r.nextInt(7-1)+1);
Toast.makeText(getApplicationContext(),rand,Toast.LENGTH_LONG).show();
}
});
final File file = new File(getFilesDir(), "char.txt");
if (file.exists()){}
else{
Intent myIntent = new Intent(this,Create_Character.class);
startActivityForResult(myIntent,0);
Toast.makeText(this, "keinen gespeicherten Character gefunden", Toast.LENGTH_LONG).show();
}
Button buttondel = (findViewById(R.id.button2));
buttondel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog.Builder builder;
builder = new AlertDialog.Builder(MainActivity.this, android.R.style.Theme_Material_Dialog_Alert);
builder.setTitle("Character Löschen")
.setMessage("Bist du dir sicher, dass du deinen Character löschen möchtest um einen neuen zu erstellen?")
.setPositiveButton("JA", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
boolean deleted = file.delete();
Intent myIntent = new Intent(getApplicationContext(), Create_Character.class);
startActivityForResult(myIntent, 0);
}
})
.setNegativeButton("Nein", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
})
//.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
});
TextView Namensschild = (TextView) (findViewById(R.id.textView));
Namensschild.setText(Stats.name);
Spinner spinner = (Spinner) (findViewById(R.id.Activityspinner));
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.CharacterSpinner, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
// Setting up the Lists
InitiateLists();
// Setting up the List Adapter
ListAdpaterSetUp();
}
public void InitiateLists(){
Lists.haupt.clear();
Lists.haupt.add("Bewegung " + String.valueOf(Stats.bwg));
Lists.haupt.add("Charisma " + String.valueOf(Stats.ch));
Lists.haupt.add("Fingerfertigkeit " + String.valueOf(Stats.ff));
Lists.haupt.add("Geist " + String.valueOf(Stats.gei));
Lists.haupt.add("Gewandheit " + String.valueOf(Stats.ge));
Lists.haupt.add("Intuition " + String.valueOf(Stats.in));
Lists.haupt.add("Klugheit " + String.valueOf(Stats.kl));
Lists.haupt.add("Konstitution " + String.valueOf(Stats.ko));
Lists.haupt.add("Körper "+ String.valueOf(Stats.koer));
Lists.haupt.add("Körperkraft " + String.valueOf(Stats.kk));
Lists.haupt.add("Mut " + String.valueOf(Stats.mu));
Lists.haupt.add("Willenskraft " + String.valueOf(Stats.wil));
Stats.lvl = 1;
int le = ((Stats.koer+Stats.ko)*2+Stats.rmhealth);
int ae = ((Stats.gei+Stats.ch)*2+18);
int ke = ((Stats.wil+Stats.in)*2+Stats.lvl);
int gs = (Stats.bwg+1+Stats.rmspeed);
int ini = (Stats.bwg+Stats.mu+Stats.in);
int pa = (Stats.koer+Stats.ge+Stats.in);
int aus = (Stats.bwg+Stats.ge+Stats.in); //Mi
int at = (Stats.koer+Stats.kk+Stats.mu);
int fk = (Stats.bwg+Stats.ge+Stats.ff);
int zau = (Stats.gei+Stats.ch+Stats.kl);
int lit = (Stats.wil+Stats.ch+Stats.in);
int re = ((Stats.koer+Stats.ko)-1);
int mr = ((Stats.wil+Stats.kl)-1);
Lists.grund.clear();
Lists.grund.add("Astralenergie " + String.valueOf(ae));
Lists.grund.add("Attackebasis " + String.valueOf(at));
Lists.grund.add("Ausweichen " + String.valueOf(aus));
Lists.grund.add("Fernkampfbasis " + String.valueOf(fk));
Lists.grund.add("Geschwindigkeit " + String.valueOf(gs));
Lists.grund.add("Initiative " + String.valueOf(ini));
Lists.grund.add("Karmaenergie " + String.valueOf(ke));
Lists.grund.add("Lebensenergie " + String.valueOf(le));
Lists.grund.add("Liturgiebasis " + String.valueOf(lit));
Lists.grund.add("Magieresistenz " + String.valueOf(mr));
Lists.grund.add("Paradebasis " + String.valueOf(pa));
Lists.grund.add("Resistenz " + String.valueOf(re));
Lists.grund.add("Zauberbasis " + String.valueOf(zau));
}
public void load(){
FileInputStream fis = null;
try {
fis = openFileInput("char.txt");
InputStreamReader isr= new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
String text;
String[] Buffer = new String[15];
for (int i=0;i<15;i++){
Buffer[i] = br.readLine();
}
Stats.name = Buffer[0];
Stats.koer = Integer.parseInt(Buffer[1]);
Stats.bwg = Integer.parseInt(Buffer[2]);
Stats.wil = Integer.parseInt(Buffer[3]);
Stats.gei = Integer.parseInt(Buffer[4]);
Stats.kk = Integer.parseInt(Buffer[5]);
Stats.ge = Integer.parseInt(Buffer[6]);
Stats.mu = Integer.parseInt(Buffer[7]);
Stats.kl = Integer.parseInt(Buffer[8]);
Stats.ko = Integer.parseInt(Buffer[9]);
Stats.ff = Integer.parseInt(Buffer[10]);
Stats.ch = Integer.parseInt(Buffer[11]);
Stats.in = Integer.parseInt(Buffer[12]);
Stats.rmhealth = Integer.parseInt(Buffer[13]);
Stats.rmspeed = Integer.parseInt(Buffer[14]);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fis != null){
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public void ListAdpaterSetUp(){
ListAdapter HauptAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Lists.haupt);
ListView ExampleListView = findViewById(R.id.HauptattributeList);
ExampleListView.setAdapter(HauptAdapter);
ListAdapter GrundAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Lists.grund);
ListView ExampleListView2 = findViewById(R.id.GrundwerteList);
ExampleListView2.setAdapter(GrundAdapter);
}
}