Initial commit
This commit is contained in:
commit
0677fbf059
70 changed files with 1418 additions and 0 deletions
|
@ -0,0 +1,66 @@
|
|||
package com.ddns.kauron.dungeonmanager;
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
|
||||
public class HealthDialogFragment extends DialogFragment {
|
||||
|
||||
static HealthDialogFragment newInstance(int curativeEfforts) {
|
||||
HealthDialogFragment f = new HealthDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt("curativeEfforts", curativeEfforts);
|
||||
f.setArguments(args);
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
public interface HealthDialogListener {
|
||||
public void curativeEffort(DialogFragment dialog, boolean uses);
|
||||
}
|
||||
|
||||
|
||||
HealthDialogListener mListener;
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
try{
|
||||
mListener = (HealthDialogListener) activity;
|
||||
}catch(ClassCastException e){
|
||||
throw new ClassCastException(activity.toString() + " must implement HealthDialogListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
String message = getString(R.string.new_energies1) +
|
||||
" " + getArguments().getInt("curativeEfforts") + " " +
|
||||
getString(R.string.new_energies2);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
builder.setMessage(message)
|
||||
.setTitle(R.string.new_energies_title)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.curativeEffort(HealthDialogFragment.this, true);
|
||||
}
|
||||
})
|
||||
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
mListener.curativeEffort(HealthDialogFragment.this, false);
|
||||
}
|
||||
})
|
||||
.setNeutralButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
return builder.create();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
package com.ddns.kauron.dungeonmanager;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class Introduction extends ActionBarActivity {
|
||||
|
||||
EditText name, className, raceName, level, maxPg;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_introduction, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_finish) {
|
||||
if(finished()) {
|
||||
this.finish();
|
||||
} else {
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
R.string.missing_info_error,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
//TODO: fix this
|
||||
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();
|
||||
int levelInt = 0, maxPgInt = 0;
|
||||
try {
|
||||
levelInt = Integer.parseInt(level.getText().toString());
|
||||
maxPgInt = Integer.parseInt(level.getText().toString());
|
||||
} catch (Exception e) {}
|
||||
if(getIntent().getExtras().getBoolean("first_time")) {
|
||||
if (!nameString.isEmpty() &&
|
||||
!classString.isEmpty() &&
|
||||
!raceString.isEmpty() &&
|
||||
levelInt != 0 &&
|
||||
maxPgInt != 0) {
|
||||
//first save it all
|
||||
ed.putString("playerName", nameString);
|
||||
ed.putString("className", classString);
|
||||
ed.putString("raceName", raceString);
|
||||
if(p.getInt("pg", Integer.MIN_VALUE) == Integer.MIN_VALUE)
|
||||
ed.putInt("pg", maxPgInt);
|
||||
ed.putInt("level", levelInt);
|
||||
ed.putInt("maxPg", maxPgInt);
|
||||
ed.putBoolean("saved", true);
|
||||
ed.apply();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!nameString.isEmpty()) ed.putString("playerName", nameString);
|
||||
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);
|
||||
ed.apply();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,209 @@
|
|||
package com.ddns.kauron.dungeonmanager;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
public class MainActivity extends ActionBarActivity
|
||||
implements HealthDialogFragment.HealthDialogListener{
|
||||
|
||||
public static final int CURRENT_PG = 1, NULL = 0;
|
||||
|
||||
public Player player;
|
||||
private boolean undo;
|
||||
private int undoObject, undoPreviousValue;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
restoreData();
|
||||
undo = false;
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu (Menu menu) {
|
||||
menu.findItem(R.id.action_undo).setVisible(undo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_cure) {
|
||||
showHealthDialog();
|
||||
return true;
|
||||
} else if (id == R.id.action_edit_basics) {
|
||||
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
|
||||
Intent intent = new Intent(this, Introduction.class);
|
||||
startActivity(intent.putExtra(
|
||||
"first_time",
|
||||
!p.getBoolean("saved", false)
|
||||
));
|
||||
restoreData();
|
||||
return true;
|
||||
} else if (id == R.id.action_undo) {
|
||||
String message = "";
|
||||
if(undoObject == CURRENT_PG){
|
||||
((Button) findViewById(R.id.pgCurrent)).setText(String.valueOf(undoPreviousValue));
|
||||
undoObject = NULL;
|
||||
message = getString(R.string.action_undo_current_pg);
|
||||
}
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
message,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
undo = false;
|
||||
invalidateOptionsMenu();
|
||||
return true;
|
||||
} else if (id == R.id.action_calendar_activity) {
|
||||
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||
intent.setType("vnd.android.cursor.item/event");
|
||||
intent.putExtra("title", R.string.dungeons_and_dragons);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.action_save) {
|
||||
saveData();
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void showHealthDialog(){
|
||||
DialogFragment dialog = HealthDialogFragment.newInstance(player.getCurativeEfforts());
|
||||
dialog.show(getFragmentManager(), "HealthDialogFragment");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void curativeEffort(DialogFragment dialog, boolean uses) {
|
||||
int hasCured = player.recoverPg(Player.USE_CURATIVE_EFFORT, uses);
|
||||
if (hasCured == Player.NOT_CURED) {
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
R.string.no_curative_efforts_error,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
} else {
|
||||
if(hasCured == Player.MAXED){
|
||||
Toast.makeText(
|
||||
getApplicationContext(),
|
||||
R.string.maxed_curative,
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
}
|
||||
healthStatusCheck();
|
||||
}
|
||||
}
|
||||
|
||||
public void onCurrentPgClick(final View view){
|
||||
AlertDialog.Builder alert = new AlertDialog.Builder(this);
|
||||
alert.setTitle(getString(R.string.suffer_damage));
|
||||
|
||||
// Set an EditText view to get user input
|
||||
final EditText input = new EditText(this);
|
||||
input.setInputType(InputType.TYPE_CLASS_NUMBER);
|
||||
input.setHint(R.string.suffer_damage_hint);
|
||||
|
||||
|
||||
alert.setView(input);
|
||||
|
||||
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
Button pg = (Button) findViewById(R.id.pgCurrent);
|
||||
try {
|
||||
int preValue = Integer.parseInt(pg.getText().toString());
|
||||
int damage = Integer.parseInt(input.getText().toString());
|
||||
player.losePg(damage);
|
||||
pg.setText(
|
||||
String.valueOf(player.getPg())
|
||||
);
|
||||
//finished correctly, then apply values to undo's
|
||||
healthStatusCheck();
|
||||
undo = true;
|
||||
undoPreviousValue = preValue;
|
||||
undoObject = CURRENT_PG;
|
||||
invalidateOptionsMenu();
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
});
|
||||
|
||||
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int whichButton) {
|
||||
// Canceled.
|
||||
}
|
||||
});
|
||||
|
||||
alert.show();
|
||||
}
|
||||
|
||||
private void healthStatusCheck(){
|
||||
int status = player.getState();
|
||||
Button pg = (Button) findViewById(R.id.pgCurrent);
|
||||
pg.setText(String.valueOf(player.getPg()));
|
||||
if (status == Player.MUERTO) {
|
||||
pg.setText("");
|
||||
} else if (status == Player.DEBILITADO)
|
||||
pg.setTextColor(Color.RED);
|
||||
else if (status == Player.MALHERIDO)
|
||||
pg.setTextColor(Color.YELLOW);
|
||||
else pg.setTextColor(getResources().getColor(R.color.abc_primary_text_material_dark));
|
||||
}
|
||||
|
||||
|
||||
private void restoreData(){
|
||||
SharedPreferences p = getSharedPreferences("basics", MODE_PRIVATE);
|
||||
//restore state
|
||||
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[3],
|
||||
new int[18],
|
||||
new Power[4]);
|
||||
//set restored values to the respective fields
|
||||
((TextView) findViewById(R.id.nameText)).setText(player.getName());
|
||||
((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.getMaxPg()));
|
||||
}
|
||||
|
||||
private void saveData() {
|
||||
|
||||
}
|
||||
}
|
115
app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java
Normal file
115
app/src/main/java/com/ddns/kauron/dungeonmanager/Player.java
Normal file
|
@ -0,0 +1,115 @@
|
|||
package com.ddns.kauron.dungeonmanager;
|
||||
|
||||
public class Player {
|
||||
/**
|
||||
* Values for attack
|
||||
*/
|
||||
public static final int FUE = 1, CON = 2, DES = 3, INT = 4, SAB = 5, CAR = 6;
|
||||
|
||||
/**
|
||||
* Values for defenses
|
||||
*/
|
||||
public static final int CA = 1, FORT = 2, REF = 3, VOL = 4;
|
||||
|
||||
/**
|
||||
* Values for abilities
|
||||
*/
|
||||
public static final int ACROBACIAS = 1, AGUANTE = 2, ARCANOS = 3, ATLETISMO = 4, DIPLOMACIA = 5,
|
||||
DUNGEONS = 6, ENGAÑAR = 7, HISTORIA = 8, HURTO = 9, INTIMIDAR = 10, NATURALEZA = 11,
|
||||
PERCEPCIÓN = 12, PERSPICACIA = 13, RECURSOS = 14, RELIGIÓN = 15, SANAR = 16, SIGILO = 17;
|
||||
|
||||
/**
|
||||
* Names for the abilities
|
||||
*/
|
||||
public static final String[] abilityString = new String[] {
|
||||
"Acrobacias", "Aguante", "Arcanos", "Atletismo", "Diplomacia", "Dungeons", "Engañar",
|
||||
"Historia", "Hurto", "Intimidar", "Naturaleza", "Percepción", "Perspicacia", "Recursos",
|
||||
"Religión", "Sanar", "Sigilo"
|
||||
};
|
||||
|
||||
/**
|
||||
* Values for the current living state
|
||||
*/
|
||||
public static final int OK = 1, MALHERIDO = 2, DEBILITADO = 3, MUERTO = 4,
|
||||
USE_CURATIVE_EFFORT = -1, CURED = 1, NOT_CURED = 0, MAXED = -1;
|
||||
|
||||
private int pg, maxPg;
|
||||
private int state;
|
||||
private int curativeEfforts, maxCurativeEfforts;
|
||||
private int[] atk, def, abilities;
|
||||
private Power[] powers;
|
||||
private String name, className, raceName;
|
||||
private int level;
|
||||
|
||||
|
||||
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;
|
||||
setState();
|
||||
this.name = name;
|
||||
this.className = className;
|
||||
this.raceName = raceName;
|
||||
this.level = level;
|
||||
this.atk = atk;
|
||||
this.def = def;
|
||||
this.abilities = abilities;
|
||||
this.powers = powers;
|
||||
this.maxCurativeEfforts = maxCurativeEfforts;
|
||||
this.curativeEfforts = curativeEfforts;
|
||||
}
|
||||
|
||||
|
||||
public int getCurativeEfforts() {return curativeEfforts;}
|
||||
public void setCurativeEffort(int curativeEfforts) {this.curativeEfforts = curativeEfforts;}
|
||||
|
||||
public int getLevel() {return level;}
|
||||
|
||||
public int getMaxPg() {return maxPg;}
|
||||
public void setMaxPg(int pg) {this.pg = pg;}
|
||||
|
||||
public int getPg() {return pg;}
|
||||
public void setPg(int pg) {this.pg = pg;}
|
||||
public void losePg(int damage) {
|
||||
pg -= damage;
|
||||
setState();
|
||||
}
|
||||
public int recoverPg(int recovered, boolean uses) {
|
||||
if(recovered == USE_CURATIVE_EFFORT){
|
||||
if(uses && curativeEfforts <= 0) return NOT_CURED;
|
||||
else {
|
||||
if(uses) curativeEfforts--;
|
||||
pg += maxPg / 4;
|
||||
}
|
||||
} else {
|
||||
pg += recovered;
|
||||
}
|
||||
setState();
|
||||
|
||||
if (pg > maxPg) {pg = maxPg; return MAXED;}
|
||||
|
||||
return CURED;
|
||||
}
|
||||
|
||||
public int getState() {return state;}
|
||||
private void setState() {
|
||||
if (pg < maxPg / -2) state = MUERTO;
|
||||
else if (pg < 0) state = DEBILITADO;
|
||||
else if(pg < maxPg / 2) state = MALHERIDO;
|
||||
else state = OK;
|
||||
}
|
||||
|
||||
public String getName() {return name;}
|
||||
public String getClassName() {return className;}
|
||||
public String getRaceName() {return raceName;}
|
||||
|
||||
|
||||
public void rest(boolean length) {
|
||||
if(length) {
|
||||
curativeEfforts = maxCurativeEfforts;
|
||||
for(Power p : powers){
|
||||
if(p != null) p.recover();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
24
app/src/main/java/com/ddns/kauron/dungeonmanager/Power.java
Normal file
24
app/src/main/java/com/ddns/kauron/dungeonmanager/Power.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
package com.ddns.kauron.dungeonmanager;
|
||||
|
||||
public class Power {
|
||||
public static final int DIARIO = 1, A_VOLUNTAD = 2, ENCUENTRO = 3, OPORTUNIDAD = 4;
|
||||
|
||||
private boolean used;
|
||||
private int type;
|
||||
private String name;
|
||||
|
||||
|
||||
public Power(String name, int type){
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
used = false;
|
||||
}
|
||||
|
||||
public String getName(){return name;}
|
||||
public int getType(){return type;}
|
||||
|
||||
public boolean isUsed(){return used;}
|
||||
|
||||
public void use(){used = true;}
|
||||
public void recover(){used = false;}
|
||||
}
|
Reference in a new issue