Skip to content

Commit

Permalink
Merge pull request #9 from subchannel13/v1.1
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
subchannel13 authored Jun 4, 2017
2 parents 0db12ac + 048a880 commit 516036f
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 112 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ gradle-app.setting
.DS_Store
/captures
.externalNativeBuild
.idea/dictionaries/*.xml
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# EnchantedFortress
# Enchanted Fortress

A simple game inspired by Age of Castles. Distribute your population to farming, construction, guard duty and scholarship, survive demon invasion and find the way to banish them forever.

## Story

Dark days are upon your land, twisted people have made a pact with demons, hell gates have been opened and demon kind has started to roam this world. As the time passes more hell gates open and demon army grows stronger and bolder. If they are not stopped the realm will be overrun.

Your scholars speculate if there is a ritual to summon the demons then there must be the one to banish them. Help them perform the ritual and defend them from demons who will try to stop them.

## How to play

Majority of the game revolves around distributing population to following jobs:
* Farmers - increase population growth
* Builders - build city walls
* Soldiers - increase military strength
* Scholars - research improvements and banish demons

As the time (turns) passes demon army strength will grow and when they grow confident enough they will mount an attack. The attacks don't come without the
warning, your people will report how many demons they saw. It's not an accurate number but expect them to have at least that many troops. When the attack comes all of your population participates in the defense, both soldiers and workers. Soldiers are stronger defenders but if you are caught unprepared civilians will do their best to survive. Tall city wall is great way to not get caught unprepared.

Ultimately your success depends on balancing military power and economy. It might be tempting to employ as many people as possible as soldiers but if the attack doesn't come on given turn your economy won't grow fast enough to handle future demon attacks. Early on farming improves the economy the most, more people you have more of them you can employ to construct walls and field as soldiers. Research is another way to improve your military and economy in the long term. All population participates in research but similar to military strength not everyone contribute equally. Scholars (people not assigned to farming, construction and guard duty) generate more research points then others.

Staying barricaded behind the wall will not make you unconquerable, eventually demons will grow powerful enough to overcome any defenses. Banishment ritual is the only way to defeat demons for good. Performing it will gradually close hell gates, making demon army grow slower and once finished will permanently stop demon invasion.

## Support

If you find a bug, please report it on the [issue tracker](https://github.com/subchannel13/EnchantedFortress/issues)

[Donate via PayPal](https://www.paypal.me/IvanKravarscan/5)
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "hr.kravarscan.enchantedfortress"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import hr.kravarscan.enchantedfortress.logic.Technology;

public class GameFragment extends Fragment {
private static final String SaveKey = "GameState";

private Game game = new Game();
private String[] techList = new String[5];
Expand All @@ -42,6 +43,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_game, container, false);

if (savedInstanceState != null) {
this.game.load(savedInstanceState.getDoubleArray(SaveKey));
}

view.findViewById(R.id.farmPlusButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Expand Down Expand Up @@ -141,6 +146,12 @@ public void onDetach() {
listener = null;
}

@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putDoubleArray(SaveKey, this.game.save());
}

private void updateTechList() {
this.techList[0] = getResources().getString(R.string.farmingTech) + techDescription(this.game.farming);
this.techList[1] = getResources().getString(R.string.buildTech) + techDescription(this.game.building);
Expand Down Expand Up @@ -187,7 +198,8 @@ private void updateInfo()
this.endTurnButton.setText(R.string.gameOver);
}
else
this.popInfo.setText(getResources().getString(R.string.population) + ": " + Integer.toString(this.game.population) + "\n" +
this.popInfo.setText(getResources().getString(R.string.turn) + ": " + Integer.toString(this.game.turn) + "\n" +
getResources().getString(R.string.population) + ": " + Integer.toString(this.game.population) + "\n" +
getResources().getString(R.string.walls) + ": " + Integer.toString((int)this.game.walls) + "\n" +
getResources().getString(R.string.scouted) + ": " + Integer.toString(this.game.reportScoutedDemons) + " " + getResources().getString(R.string.demons) +
this.battleInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@

public class HelpFragment extends Fragment {


public HelpFragment() {
// Required empty public constructor
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_help, container, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

public class MainActivity extends FragmentActivity implements MainMenuFragment.OnFragmentInteractionListener, GameFragment.OnFragmentInteractionListener {
Expand All @@ -12,17 +13,25 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

MainMenuFragment mainMenu = new MainMenuFragment();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mainMenu).commit();
if (getSupportFragmentManager().getFragments() == null) {
MainMenuFragment mainMenu = new MainMenuFragment();
getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mainMenu).commit();
}
}

private void switchMainView(Fragment fragment)
{
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
boolean isMain = fragment instanceof MainMenuFragment;
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();

for (int i = 0; isMain && i < manager.getBackStackEntryCount(); i++)
manager.popBackStack();

transaction.replace(R.id.fragment_container, fragment);
if (!(fragment instanceof MainMenuFragment))
if (!isMain)
transaction.addToBackStack(null);

transaction.commit();
}

Expand Down
89 changes: 81 additions & 8 deletions app/src/main/java/hr/kravarscan/enchantedfortress/logic/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@

import java.util.Random;

import hr.kravarscan.enchantedfortress.BuildConfig;

/**
* Copyright 2017 Ivan Kravarščan
* <p>
*
* This file is part of Enchanted Fortress.
* <p>
*
* Enchanted Fortress is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
* Enchanted Fortess is distributed in the hope that it will be useful,
*
* Enchanted Fortress is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* <p>
*
* You should have received a copy of the GNU General Public License
* along with Enchanted Fortress. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -32,7 +34,7 @@ public class Game {
private static final double Mortality = 1 / 50.0;
private static Random rand = new Random();

public int turn = 0;
public int turn = 1;
public int population = 100;
public double walls = 0;
private int demons = 0;
Expand Down Expand Up @@ -119,7 +121,7 @@ public void selectTech(int i) {
}

/*
Derivate values
Derivative values
*/
private int farmers() {
return (int) (this.population * this.farmerSlider / SliderTicks);
Expand Down Expand Up @@ -215,6 +217,9 @@ private void doResearch() {
break;
case 4:
this.demonBanishCost -= (int) researchPoints;
if (this.demonBanishCost < 0)
this.demonBanishCost = 0;

this.demonGates -= (int) (researchPoints / 100);
if (this.demonGates < 0)
this.demonGates = 0;
Expand Down Expand Up @@ -254,13 +259,16 @@ private void doCombat() {
defenderStr = 0;

attackers /= DemonStrength;
this.reportScoutedDemons = (int) (this.reportScoutedDemons * this.demons / (double) (this.demons + attackers) + attackers);
this.demons += attackers / DemonStrength;
if (this.demons < 0)
this.demons = 0;

this.reportVictims = (int) ((this.militaryStrength() - defenderStr) / peopleStr);
this.population -= this.reportVictims;

this.reportScoutedDemons -= this.reportAttackers;
if (this.reportScoutedDemons < 0)
this.reportScoutedDemons = 0;
}

private void spawnDemons() {
Expand Down Expand Up @@ -306,4 +314,69 @@ private void correctSliders() {
private int sliderOverflow() {
return this.farmerSlider + this.builderSlider + this.soldierSlider - (int) SliderTicks;
}

/*
Saving and loading
*/
public double[] save() {
return new double[]
{
BuildConfig.VERSION_CODE,

this.turn,
this.population,
this.walls,
this.demons,
this.demonGates,
this.demonBanishCost,

this.farmerSlider,
this.builderSlider,
this.soldierSlider,
this.selectedTech,

this.farming.level,
this.farming.points,
this.building.level,
this.building.points,
this.soldiering.level,
this.soldiering.points,
this.scholarship.level,
this.scholarship.points,

this.reportAttackers,
this.reportVictims,
this.reportScoutedDemons,
};
}

public void load(double[] data) {
if (data.length != 22 || data[0] != BuildConfig.VERSION_CODE)
return;

this.turn = (int) data[1];
this.population = (int) data[2];
this.walls = data[3];
this.demons = (int) data[4];
this.demonGates = (int) data[5];
this.demonBanishCost = (int) data[6];

this.farmerSlider = (int) data[7];
this.builderSlider = (int) data[8];
this.soldierSlider = (int) data[9];
this.selectedTech = (int) data[10];

this.farming.level = (int) data[11];
this.farming.points = data[12];
this.building.level = (int) data[13];
this.building.points = data[14];
this.soldiering.level = (int) data[15];
this.soldiering.points = data[16];
this.scholarship.level = (int) data[17];
this.scholarship.points = data[18];

this.reportAttackers = (int) data[19];
this.reportVictims = (int) data[20];
this.reportScoutedDemons = (int) data[21];
}
}
Loading

0 comments on commit 516036f

Please sign in to comment.