Added a test to my scene where we can end a turn and see the hunger being affected.

Added some functions to the Stats script.
Added the HungerScript to manage the hunger bars.
This commit is contained in:
Michael Turcotte 2015-08-13 17:40:12 -04:00
parent 47f8963dab
commit be73c8fdc8
4 changed files with 1188 additions and 24 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class HungerScript : MonoBehaviour {
public Slider sliderZombie;
public Slider sliderHumans;
private Stats stats;
// Use this for initialization
void Start()
{
stats = GameObject.Find("Stats").gameObject.GetComponent<Stats>();
sliderHumans.maxValue = stats.MaxHungerHuman;
sliderZombie.maxValue = stats.MaxHungerZombies;
sliderHumans.value = sliderHumans.maxValue;
sliderZombie.value = sliderZombie.maxValue;
}
// Update is called once per frame
void Update () {
sliderHumans.maxValue = stats.MaxHungerHuman;
sliderZombie.maxValue = stats.MaxHungerZombies;
sliderHumans.value = stats.AmountOfHHunger;
sliderZombie.value = stats.AmountOfZHunger;
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ac127753a81f3c64a861325eb9c87672
timeCreated: 1439493965
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -4,10 +4,24 @@ using System;
public class Stats : MonoBehaviour public class Stats : MonoBehaviour
{ {
#region constants
private readonly int HOUSE_SUPPLY_CAP = 10;
private readonly int HUMANS_PER_HOUSE = 2;
private readonly int HUNGER_PER_ZOMBIE = 100;
private readonly int HUNGER_PER_HUMAN = 100;
private readonly int HUNGER_DEDUCT_PER_DAY_H = 25;
private readonly int HUNGER_DEDUCT_PER_DAY_Z = 10;
#endregion
#region attributes #region attributes
private int nbTurns; private int nbTurns;
private int maxHungerHuman;
private int maxHungerZombies;
private int amountOfRock; private int amountOfRock;
private int amountOfWood; private int amountOfWood;
private int amountOfCorpse; private int amountOfCorpse;
@ -51,6 +65,18 @@ public class Stats : MonoBehaviour
set { nbHumanHouses = value; } set { nbHumanHouses = value; }
} }
public int MaxHungerHuman
{
get { return maxHungerHuman; }
set { maxHungerHuman = value; }
}
public int MaxHungerZombies
{
get { return maxHungerZombies; }
set { maxHungerZombies = value; }
}
public int AmountZombieHouse public int AmountZombieHouse
{ {
get { return nbZombieHouses; } get { return nbZombieHouses; }
@ -223,10 +249,11 @@ public class Stats : MonoBehaviour
} }
#endregion #endregion
/*
public Stats(int nbRock, int nbWood, int nbCorpse, int nbMeat, int nbHumans, int nbZombies) public Stats(int nbRock, int nbWood, int nbCorpse, int nbMeat, int nbHumans, int nbZombies)
{ {
resetStats(nbRock, nbWood, nbCorpse, nbMeat, nbHumans, nbZombies, 5, 5, 5, 5); resetStats(nbRock, nbWood, nbCorpse, nbMeat, nbHumans, nbZombies, 5, 5, 5, 5);
} }*/
public void resetStats(int nbRock, int nbWood, int nbCorpse, int nbMeat, int nbHumans, int nbZombies, public void resetStats(int nbRock, int nbWood, int nbCorpse, int nbMeat, int nbHumans, int nbZombies,
int nbOfWoodByZombie, int nbOfRockByZombie, int nbOfMeatByZombie, int nbOfCorpseByZombie) int nbOfWoodByZombie, int nbOfRockByZombie, int nbOfMeatByZombie, int nbOfCorpseByZombie)
@ -246,8 +273,13 @@ public class Stats : MonoBehaviour
NbZombieAssigneCorpse = 0; NbZombieAssigneCorpse = 0;
NbZombieAssigneMeat = 0; NbZombieAssigneMeat = 0;
AmountOfZombiesAvail = AmountOfZombies; AmountOfZombiesAvail = AmountOfZombies;
AmountOfHHunger = 250 * AmountOfHumans;
AmountOfZHunger = 500 * AmountOfZombies;
//Init Hunger
setMaxHungerHumans();
setMaxHungerZombies();
AmountOfHHunger = maxHungerHuman;
AmountOfZHunger = MaxHungerZombies;
} }
private void applyStatModifications() private void applyStatModifications()
@ -260,12 +292,12 @@ public class Stats : MonoBehaviour
private void advanceTurn() private void advanceTurn()
{ {
nbTurns++; NbTurns++;
} }
private bool isHumanMaxCapacity() private bool isHumanMaxCapacity()
{ {
int cap = nbHumanHouses * 10; int cap = nbHumanHouses * HOUSE_SUPPLY_CAP;
if (AmountOfHumans > cap) if (AmountOfHumans > cap)
return true; return true;
else else
@ -274,7 +306,7 @@ public class Stats : MonoBehaviour
private bool isZombieMaxCapacity() private bool isZombieMaxCapacity()
{ {
int cap = nbZombieHouses * 10; int cap = nbZombieHouses * HOUSE_SUPPLY_CAP;
if (AmountOfZombies > cap) if (AmountOfZombies > cap)
return true; return true;
else else
@ -284,9 +316,9 @@ public class Stats : MonoBehaviour
public void endTurn() public void endTurn()
{ {
if (!isHumanMaxCapacity()) if (!isHumanMaxCapacity())
AmountOfHumans += (2 * AmountHumanHouse); //AmountOfHumans += (HUMANS_PER_HOUSE * AmountHumanHouse);
if (isZombieMaxCapacity()) if (isZombieMaxCapacity())
AmountOfZombies -= AmountOfZombies % (AmountZombieHouse * 10); //AmountOfZombies -= AmountOfZombies % (AmountZombieHouse * HOUSE_SUPPLY_CAP);
applyStatModifications(); applyStatModifications();
calculateHunger(); calculateHunger();
advanceTurn(); advanceTurn();
@ -294,8 +326,18 @@ public class Stats : MonoBehaviour
private void calculateHunger() private void calculateHunger()
{ {
AmountOfHHunger -= 10 * AmountOfHumans; AmountOfHHunger -= HUNGER_DEDUCT_PER_DAY_H * AmountOfHumans;
AmountOfZHunger -= 50 * AmountOfZombies; AmountOfZHunger -= HUNGER_DEDUCT_PER_DAY_Z * AmountOfZombies;
}
private void setMaxHungerHumans()
{
MaxHungerHuman = AmountOfHumans * HUNGER_PER_HUMAN;
}
private void setMaxHungerZombies()
{
MaxHungerZombies = AmountOfZombies * HUNGER_PER_ZOMBIE;
} }
public String displayStats() public String displayStats()
@ -336,7 +378,7 @@ public class Stats : MonoBehaviour
// Use this for initialization // Use this for initialization
void Start () { void Start () {
resetStats(3, 6, 7, 8, 4, 1, 5, 5, 5, 5); resetStats(3, 6, 7, 8, 4, 1, 1, 5, 5, 5);
} }
// Update is called once per frame // Update is called once per frame