1
0
Fork 0

Introducing autogeneration

This commit is contained in:
Carlos Galindo 2015-02-21 16:22:20 +01:00
parent 7cc93f960d
commit 7d3b032f89
7 changed files with 367 additions and 157 deletions

View file

@ -13,7 +13,8 @@ import android.widget.Toast;
public class Introduction extends ActionBarActivity {
EditText name, className, raceName, level, maxPg, curativeEfforts, maxCurativeEfforts, pgE;
EditText name, level;
EditText fue, con, des, sab, intel, car;
Spinner classSpinner, raceSpinner;
@Override
@ -22,19 +23,20 @@ public class Introduction extends ActionBarActivity {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_introduction);
name = (EditText) findViewById(R.id.editNameIntro);
className = (EditText) findViewById(R.id.editClassIntro);
raceName = (EditText) findViewById(R.id.editRaceIntro);
level = (EditText) findViewById(R.id.editLevelIntro);
maxPg = (EditText) findViewById(R.id.editMaxPgIntro);
curativeEfforts = (EditText) findViewById(R.id.editEffortIntro);
maxCurativeEfforts = (EditText) findViewById(R.id.editMaxEffortIntro);
pgE = (EditText) findViewById(R.id.editPgIntro);
fue = (EditText) findViewById(R.id.FUE);
con = (EditText) findViewById(R.id.CON);
des = (EditText) findViewById(R.id.DES);
sab = (EditText) findViewById(R.id.SAB);
intel = (EditText) findViewById(R.id.INT);
car = (EditText) findViewById(R.id.CAR);
classSpinner = (Spinner) findViewById(R.id.classSpinner);
classSpinner.setAdapter(
new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_item,
android.R.layout.simple_spinner_dropdown_item,
Player.classStrings
)
);
@ -43,7 +45,7 @@ public class Introduction extends ActionBarActivity {
raceSpinner.setAdapter(
new ArrayAdapter<String>(
this,
android.R.layout.simple_spinner_item,
android.R.layout.simple_spinner_dropdown_item,
Player.raceStrings
)
);
@ -85,43 +87,54 @@ public class Introduction extends ActionBarActivity {
private boolean finished() {
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
SharedPreferences.Editor ed = p.edit();
String nameString = name.getText().toString();
String classString = className.getText().toString();
String raceString = raceName.getText().toString();
String classString = Player.classStrings[classSpinner.getSelectedItemPosition()];
String raceString = Player.raceStrings[raceSpinner.getSelectedItemPosition()];
int levelInt = 0, maxPgInt = 0, pg = 0, curEff = 0, mCurEff = 0;
int levelInt = 0;
if (!level.getText().toString().isEmpty())
levelInt = Integer.parseInt(level.getText().toString());
if (!maxPg.getText().toString().isEmpty())
maxPgInt = Integer.parseInt(maxPg.getText().toString());
if (!pgE.getText().toString().isEmpty())
pg = Integer.parseInt(pgE.getText().toString());
if (!curativeEfforts.getText().toString().isEmpty())
curEff = Integer.parseInt(curativeEfforts.getText().toString());
if (!maxCurativeEfforts.getText().toString().isEmpty())
mCurEff = Integer.parseInt(maxCurativeEfforts.getText().toString());
int fue = 0, con = 0, des = 0, intel = 0, sab = 0, car = 0;
if (!this.car.getText().toString().isEmpty())
car = Integer.parseInt(this.car.getText().toString());
if (!this.fue.getText().toString().isEmpty())
fue = Integer.parseInt(this.fue.getText().toString());
if (!this.con.getText().toString().isEmpty())
con = Integer.parseInt(this.con.getText().toString());
if (!this.des.getText().toString().isEmpty())
des = Integer.parseInt(this.des.getText().toString());
if (!this.intel.getText().toString().isEmpty())
intel = Integer.parseInt(this.intel.getText().toString());
if (!this.sab.getText().toString().isEmpty())
sab = Integer.parseInt(this.sab.getText().toString());
if(getIntent().getExtras().getBoolean("first_time")) {
if (
!nameString.isEmpty() &&
!classString.isEmpty() &&
!raceString.isEmpty() &&
!classString.equals(Player.classStrings[0]) &&
!raceString.equals(Player.raceStrings[0]) &&
levelInt != 0 &&
maxPgInt != 0 &&
pg != 0 &&
curEff != 0 &&
mCurEff != 0
car != 0 &&
fue != 0 &&
con != 0 &&
des != 0 &&
intel != 0 &&
sab != 0
) {
//first save it all
ed.putString("playerName", nameString);
ed.putString("className", classString);
ed.putString("raceName", raceString);
ed.putInt("level", levelInt);
ed.putInt("maxPg", maxPgInt);
ed.putInt("pg", pg);
ed.putInt("maxCurativeEfforts", mCurEff);
ed.putInt("curativeEfforts", curEff);
ed.putInt("fue", fue);
ed.putInt("car", car);
ed.putInt("int", intel);
ed.putInt("sab", sab);
ed.putInt("con", con);
ed.putInt("des", des);
ed.putBoolean("saved", true);
} else {
return false;
@ -131,10 +144,13 @@ public class Introduction extends ActionBarActivity {
if (!classString.isEmpty()) ed.putString("className", classString);
if (!raceString.isEmpty()) ed.putString("raceName", raceString);
if (levelInt != 0) ed.putInt("level", levelInt);
if (maxPgInt != 0) ed.putInt("maxPg", maxPgInt);
if (pg != 0) ed.putInt("pg", pg);
if (mCurEff != 0) ed.putInt("maxCurativeEfforts", mCurEff);
if (curEff != 0) ed.putInt("curativeEfforts", curEff);
if (fue != 0) ed.putInt("fue", fue);
if (car != 0) ed.putInt("car", car);
if (intel != 0) ed.putInt("int", intel);
if (sab != 0) ed.putInt("sab", sab);
if (con != 0) ed.putInt("con", con);
if (des != 0) ed.putInt("des", des);
}
ed.apply();
return true;

View file

@ -124,6 +124,7 @@ public class MainActivity extends ActionBarActivity
super.onResume();
Log.e("UTIL", "resume");
restoreData();
healthStatusCheck();
updateCurativeString();
}
@ -249,17 +250,27 @@ public class MainActivity extends ActionBarActivity
private void restoreData(){
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
//restore state
if (!p.getBoolean("saved", false)) {
Intent intent = new Intent(this, Introduction.class);
startActivity(intent.putExtra(
"first_time",
!p.getBoolean("saved", false)
));
}
if(player == null) {
player = new Player(
p.getString("playerName", getString(R.string.adventurer_name)),
p.getString("className", getString(R.string.class_name)),
p.getString("raceName", getString(R.string.race_name)),
p.getInt("level", 1),
p.getInt("maxPg", 15),
p.getInt("pg", 15),
p.getInt("maxCurativeEfforts", 5),
p.getInt("curativeEfforts", 5),
new int[6],
new int[] {
p.getInt("fue", 10),
p.getInt("con", 10),
p.getInt("des", 10),
p.getInt("int", 10),
p.getInt("sab", 10),
p.getInt("car", 10),
},
new int[3],
new int[18],
new Power[4]);
@ -280,14 +291,33 @@ public class MainActivity extends ActionBarActivity
((TextView) findViewById(R.id.raceText)).setText(player.getRaceName());
((TextView) findViewById(R.id.classText)).setText(player.getClassName());
((TextView) findViewById(R.id.lvl)).setText(String.valueOf(player.getLevel()));
((Button) findViewById(R.id.pgCurrent)).setText(String.valueOf(player.getPg()));
((TextView) findViewById(R.id.FUE)).setText(
getString(R.string.FUE) + ": " + player.getFue()
);
((TextView) findViewById(R.id.CON)).setText(
getString(R.string.CON) + ": " + player.getCon()
);
((TextView) findViewById(R.id.DES)).setText(
getString(R.string.DES) + ": " + player.getDes()
);
((TextView) findViewById(R.id.INT)).setText(
getString(R.string.INT) + ": " + player.getInt()
);
((TextView) findViewById(R.id.SAB)).setText(
getString(R.string.SAB) + ": " + player.getSab()
);
((TextView) findViewById(R.id.CAR)).setText(
getString(R.string.CAR) + ": " + player.getCar()
);
}
private void saveData() {
getSharedPreferences("basics", MODE_PRIVATE).edit()
.putString("playerName", player.getName())
.putString("className", player.getClassName())
.putString("raceName", player.getRaceName())
.putInt("level", player.getLevel())
.putInt("maxPg", player.getMaxPg())
.putInt("pg", player.getPg())

View file

@ -5,21 +5,24 @@ public class Player {
/**
* Names for the classes
*/
public static final String[] classStrings = new String[] {
"Selecciona una clase","Brujo", "Clérigo", "Señor de la guerra"
public static final String[] classStrings = {
"Clase", "Ardiente", "Brujo", "Buscador", "Clérigo", "Explorador",
"Guerrero", "Mago", "Mente de Batalla", "Monje", "Paladín", "Pícaro", "Psiónico",
"Sacerdote Rúnico", "Señor de la guerra"
};
/**
* Names for the races
*/
public static final String[] raceStrings = new String[] {
"Selecciona una raza", "Enano", "Elfo", "Tiflin", "Humano", "Mediano"
"Raza", "Dracónido", "Eladrín", "Elfo", "Enano", "Gitzherai", "Humanos", "Medianos",
"Mente del Fragmento", "Minotauro", "Salvaje", "Semielfo", "Tiflin"
};
/**
* Values for attack
*/
public static final int FUE = 1, CON = 2, DES = 3, INT = 4, SAB = 5, CAR = 6;
public static final int FUE = 0, CON = 1, DES = 2, INT = 3, SAB = 4, CAR = 5;
/**
* Values for defenses
@ -59,22 +62,58 @@ public class Player {
private int[] atk, def, abilities;
private Power[] powers;
public Player(String name, String className, String raceName, int level, int maxPg, int pg,
int maxCurativeEfforts, int curativeEfforts, int[] atk, int[] def, int[] abilities, Power[] powers){
this.maxPg = maxPg;
this.pg = pg;
public Player(
String name, String className, String raceName,
int level, int[] atk, int[] def, int[] abilities,
Power[] powers
) {
setState();
this.name = name;
this.className = className;
if(className.equals(classStrings[1])){
//Ardiente
} else if (className.equals(classStrings[2])) {
//Brujo
//TODO: Kauron
maxPg = atk[CON] + 12;
maxCurativeEfforts = 6 + atk[CON];
} else if (className.equals(classStrings[3])) {
//Buscador
} else if (className.equals(classStrings[4])) {
//Clérigo
//TODO: Gárafran
} else if (className.equals(classStrings[5])) {
//Explorador
//TODO: Aria Saferi
} else if (className.equals(classStrings[6])) {
//Guerrero
} else if (className.equals(classStrings[7])) {
//Mago
} else if (className.equals(classStrings[8])) {
//Mente de Batalla
} else if (className.equals(classStrings[9])) {
//Monje
} else if (className.equals(classStrings[10])) {
//Paladín
//TODO: Ceaelynna
} else if (className.equals(classStrings[11])) {
//Pícaro
} else if (className.equals(classStrings[12])) {
//Psiónico
} else if (className.equals(classStrings[13])) {
//Sacerdote rúnico
} else {
//Señor de la Guerra
//TODO: Mushu
}
this.raceName = raceName;
this.level = level;
this.atk = atk;
this.def = def;
this.abilities = abilities;
this.powers = powers;
this.maxCurativeEfforts = maxCurativeEfforts;
this.curativeEfforts = curativeEfforts;
}
@ -101,10 +140,18 @@ public class Player {
if(uses && curativeEfforts <= 0) return NOT_CURED;
else {
if(uses && pg < maxPg) curativeEfforts--;
pg += maxPg / 4;
if (pg < 0) {
} else {
pg += maxPg / 4;
}
}
} else {
pg += recovered;
if (pg < 0) {
} else {
pg += recovered;
}
}
setState();
@ -138,4 +185,21 @@ public class Player {
}
}
}
public void setAtk(int[] atk) {this.atk = atk;}
public int[] getAtk() {return atk;}
public void setFue(int fue) {atk[FUE] = fue;}
public void setCon(int con) {atk[CON] = con;}
public void setSab(int sab) {atk[SAB] = sab;}
public void setCar(int car) {atk[CAR] = car;}
public void setDes(int des) {atk[DES] = des;}
public void setInt(int intel) {atk[INT] = intel;}
public int getFue() {return atk[FUE];}
public int getCon() {return atk[CON];}
public int getSab() {return atk[SAB];}
public int getCar() {return atk[CAR];}
public int getDes() {return atk[DES];}
public int getInt() {return atk[INT];}
}

View file

@ -6,114 +6,129 @@
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.ddns.kauron.dungeonmanager.Introduction">
<EditText
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editNameIntro"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="@string/adventurer_name"/>
android:id="@+id/firstLayout"
android:orientation="horizontal">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editRaceIntro"
android:hint="@string/race_name"
android:layout_below="@+id/editNameIntro"
android:layout_toRightOf="@+id/editClassIntro"
android:layout_toEndOf="@+id/editClassIntro" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:layout_weight="0.5"
android:id="@+id/editNameIntro"
android:hint="@string/adventurer_name"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/editClassIntro"
android:layout_below="@+id/editNameIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:hint="@string/class_name" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editLevelIntro"
android:hint="@string/level"
android:layout_weight="1"/>
</LinearLayout>
<EditText
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editLevelIntro"
android:hint="@string/level"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/editNameIntro"
android:layout_alignRight="@+id/editRaceIntro"
android:layout_alignEnd="@+id/editRaceIntro" />
android:orientation="horizontal"
android:id="@+id/secondLayout"
android:layout_below="@+id/firstLayout">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editMaxPgIntro"
android:hint="@string/max_pg"
android:width="70dp"
android:layout_below="@+id/editClassIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/editMaxEffortIntro"
android:layout_toStartOf="@+id/editMaxEffortIntro" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/classSpinner"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editMaxEffortIntro"
android:hint="@string/max_curative_efforts"
android:layout_below="@+id/editRaceIntro"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/raceSpinner"
android:layout_alignTop="@+id/classSpinner" />
</LinearLayout>
<EditText
android:layout_width="wrap_content"
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editPgIntro"
android:width="70dp"
android:hint="@string/pg"
android:layout_below="@+id/editMaxPgIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_toLeftOf="@+id/editEffortIntro"
android:layout_toStartOf="@+id/editEffortIntro" />
android:layout_below="@+id/secondLayout"
android:id="@+id/thirdLayout"
android:columnCount="3">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="10"
android:id="@+id/editEffortIntro"
android:layout_below="@+id/editMaxEffortIntro"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:hint="@string/curative_efforts" />
android:layout_row="0"
android:layout_column="0"
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/classSpinner"
android:layout_below="@+id/editPgIntro"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
android:id="@+id/FUE"
android:hint="@string/FUE" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
android:layout_row="1"
android:layout_column="0"
android:id="@+id/CON"
android:hint="@string/CON" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
android:layout_row="0"
android:layout_column="1"
android:id="@+id/DES"
android:hint="@string/DES" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
android:layout_row="1"
android:layout_column="1"
android:id="@+id/INT"
android:hint="@string/INT" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
android:layout_row="0"
android:layout_column="2"
android:id="@+id/SAB"
android:hint="@string/SAB" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="3"
android:layout_row="1"
android:layout_column="2"
android:id="@+id/CAR"
android:hint="@string/CAR" />
</GridLayout>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/raceSpinner"
android:layout_below="@+id/classSpinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

View file

@ -97,4 +97,78 @@
android:id="@+id/curativeEffortsText"/>
</LinearLayout>
<GridLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/curativeEffortsContainer"
android:id="@+id/thirdLayout"
android:columnCount="3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="0"
android:layout_column="0"
android:id="@+id/FUE"
android:hint="@string/FUE" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="1"
android:layout_column="0"
android:id="@+id/CON"
android:hint="@string/CON" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="0"
android:layout_column="1"
android:id="@+id/DES"
android:hint="@string/DES" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="1"
android:layout_column="1"
android:id="@+id/INT"
android:hint="@string/INT" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="0"
android:layout_column="2"
android:id="@+id/SAB"
android:hint="@string/SAB" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:typeface="monospace"
android:ems="4"
android:layout_row="1"
android:layout_column="2"
android:id="@+id/CAR"
android:hint="@string/CAR" />
</GridLayout>
</RelativeLayout>

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">DungeonManager</string>
<string name="action_cure">Curar</string>
<string name="action_edit_basics">Editar personaje</string>
<string name="action_finish">Hecho</string>
@ -22,10 +21,9 @@
<string name="suffer_damage">Indica el daño sufrido</string>
<string name="title_activity_introduction">Editar personaje</string>
<string name="yes"></string>
<string name="max_curative_efforts">Esfuerzos curativos</string>
<string name="max_curative_efforts">Máx. esfuerzos curativos</string>
<string name="suffer_damage_hint">PG perdidos</string>
<string name="action_undo">Deshacer</string>
<string name="action_calendar_activity">Crear evento</string>
<string name="action_save">Guardar</string>
<string name="action_undo_current_pg">Acción deshecha</string>
<string name="dungeons_and_dragons">Dragones y Mazmorras</string>
@ -41,4 +39,10 @@
<string name="message_reset">Los datos han sido borrados</string>
<string name="reset_confirmation">Todos los datos se perderán irrevocablemente</string>
<string name="reset_confirmation_title">¿Estás seguro?</string>
<string name="CAR">CAR</string>
<string name="CON" translatable="false">CON</string>
<string name="DES" translatable="false">DES</string>
<string name="FUE" translatable="false">FUE</string>
<string name="INT" translatable="false">INT</string>
<string name="SAB" translatable="false">SAB</string>
</resources>

View file

@ -44,4 +44,11 @@
<string name="maxed_curative">You have reached your maximum level of PG</string>
<string name="suffer_damage">Input the damage suffered</string>
<string name="suffer_damage_hint">PG lost</string>
<string name="FUE">FUE</string>
<string name="CON">CON</string>
<string name="DES">DES</string>
<string name="INT">INT</string>
<string name="CAR">CAR</string>
<string name="SAB">SAB</string>
</resources>