Skip to content
Snippets Groups Projects
Commit 81550c47 authored by Matti Loimaranta's avatar Matti Loimaranta
Browse files

progressiivisesti lapaistava

parent 0566c2cf
No related branches found
No related tags found
No related merge requests found
Showing
with 167 additions and 33 deletions
...@@ -107,7 +107,19 @@ public class City : MonoBehaviour ...@@ -107,7 +107,19 @@ public class City : MonoBehaviour
this.population += v; this.population += v;
} }
private void Update()
{
if (Input.GetKey(KeyCode.S))
{
GameObject go = new GameObject();
Quarry q = go.AddComponent<Quarry>();
AddResource(q, 4000);
AddResource(go.AddComponent<Forest>(), 4000);
AddResource(go.AddComponent<BerryBush>(), 4000);
}
}
/** /**
* Lisaa resurssia r, maaran 'amount' verran (amount >= 0). * Lisaa resurssia r, maaran 'amount' verran (amount >= 0).
* Voidaan lisata maximissaan resurssin maximikapasiteettiin asti, * Voidaan lisata maximissaan resurssin maximikapasiteettiin asti,
...@@ -164,9 +176,10 @@ public class City : MonoBehaviour ...@@ -164,9 +176,10 @@ public class City : MonoBehaviour
for(int k = 0; k<resurssit.Count; k++) for(int k = 0; k<resurssit.Count; k++)
{ {
if (resurssit[k].GetType().Equals(lista[i].GetType())) if (resurssit[k].GetType().Equals(lista[i].GetType()))
resurssit.Remove(poolit[j].GetResource()); resurssit.RemoveAt(k);
} }
Debug.Log(poolit[j].GetAmount());
if (poolit[j].GetAmount() < amount) if (poolit[j].GetAmount() < amount)
{ {
return false; return false;
...@@ -174,7 +187,7 @@ public class City : MonoBehaviour ...@@ -174,7 +187,7 @@ public class City : MonoBehaviour
} }
} }
} }
Debug.Log(resurssit.Count);
return resurssit.Count == 0; return resurssit.Count == 0;
} }
/** /**
...@@ -204,6 +217,7 @@ public class City : MonoBehaviour ...@@ -204,6 +217,7 @@ public class City : MonoBehaviour
} }
private void OnMouseEnter() private void OnMouseEnter()
{ {
Instantiate<GameObject>(shopPreFab); GameObject go = Instantiate<GameObject>(shopPreFab);
go.transform.SetParent(transform);
} }
} }
...@@ -28,6 +28,7 @@ public class ResourcePool : MonoBehaviour ...@@ -28,6 +28,7 @@ public class ResourcePool : MonoBehaviour
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
} }
public void SetResource(Resource r) public void SetResource(Resource r)
{ {
......
...@@ -32,6 +32,7 @@ public class BerryBush : Resource ...@@ -32,6 +32,7 @@ public class BerryBush : Resource
public override void refreshSprite() public override void refreshSprite()
{ {
if (sprites == null) return;
if (getAmount() < 1) if (getAmount() < 1)
{ {
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[5]; gameObject.GetComponent<SpriteRenderer>().sprite = sprites[5];
......
...@@ -22,6 +22,7 @@ public class Forest : Resource ...@@ -22,6 +22,7 @@ public class Forest : Resource
public override void refreshSprite() public override void refreshSprite()
{ {
if (sprites == null) return;
if (getAmount() < 125) if (getAmount() < 125)
{ {
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[7]; gameObject.GetComponent<SpriteRenderer>().sprite = sprites[7];
......
...@@ -15,6 +15,7 @@ public class Quarry : Resource ...@@ -15,6 +15,7 @@ public class Quarry : Resource
public override void refreshSprite() public override void refreshSprite()
{ {
if (sprites == null) return;
if (getAmount() < 100) if (getAmount() < 100)
{ {
gameObject.GetComponent<SpriteRenderer>().sprite = sprites[5]; gameObject.GetComponent<SpriteRenderer>().sprite = sprites[5];
......
...@@ -18,7 +18,6 @@ public class Border : MonoBehaviour ...@@ -18,7 +18,6 @@ public class Border : MonoBehaviour
private void OnMouseEnter() private void OnMouseEnter()
{ {
Debug.Log("Kauppa kiinni");
Destroy(transform.parent.gameObject); Destroy(transform.parent.gameObject);
} }
} }
...@@ -4,6 +4,7 @@ using UnityEngine; ...@@ -4,6 +4,7 @@ using UnityEngine;
public class BuyCapacity : MonoBehaviour public class BuyCapacity : MonoBehaviour
{ {
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
...@@ -20,7 +21,23 @@ public class BuyCapacity : MonoBehaviour ...@@ -20,7 +21,23 @@ public class BuyCapacity : MonoBehaviour
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
Debug.Log("Ostit Tilaa"); City c = transform.root.gameObject.GetComponent<City>();
if (c.IsSufficientResources(createResourceGO(), 50))
{
List<int> cost = new List<int>() { 50, 50, 50 };
c.UseResources(cost);
c.IncreaseCapacity(50);
EventSystem.EventHappened(EventType.UpgradeBuilt);
} }
} }
} }
private List<Resource> createResourceGO() {
GameObject go = new GameObject();
go.AddComponent<Forest>();
go.AddComponent<Quarry>();
go.AddComponent<BerryBush>();
return new List<Resource>(go.GetComponents<Resource>());
}
}
...@@ -23,8 +23,23 @@ public class BuyCity : MonoBehaviour ...@@ -23,8 +23,23 @@ public class BuyCity : MonoBehaviour
private void OnMouseOver() private void OnMouseOver()
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{
City c = transform.root.gameObject.GetComponent<City>();
if (c.population > 200 && c.IsSufficientResources(createResourceGO(), 150))
{ {
Instantiate<GameObject>(endGame); Instantiate<GameObject>(endGame);
} }
} }
} }
private List<Resource> createResourceGO()
{
GameObject go = new GameObject();
go.AddComponent<Forest>();
go.AddComponent<Quarry>();
go.AddComponent<BerryBush>();
return new List<Resource>(go.GetComponents<Resource>());
}
}
...@@ -20,7 +20,26 @@ public class BuyCollector : MonoBehaviour ...@@ -20,7 +20,26 @@ public class BuyCollector : MonoBehaviour
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
Debug.Log("Ostit Tyovoimaa"); City c = transform.root.gameObject.GetComponent<City>();
if (c.IsSufficientResources(createResourceGO(), 50))
{
List<int> cost = new List<int>() { 50, 50, 50 };
c.UseResources(cost);
c.AddCollector();
EventSystem.EventHappened(EventType.UpgradeBuilt);
} }
} }
} }
private List<Resource> createResourceGO()
{
GameObject go = new GameObject();
go.AddComponent<Forest>();
go.AddComponent<Quarry>();
go.AddComponent<BerryBush>();
return new List<Resource>(go.GetComponents<Resource>());
}
}
...@@ -20,9 +20,15 @@ public class BuyEfficiency : MonoBehaviour ...@@ -20,9 +20,15 @@ public class BuyEfficiency : MonoBehaviour
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
Debug.Log("Ostit Tehokkuutta"); List<Resource> resources = new List<Resource>(3);
ResourceEfficiencyUpgrade reu = gameObject.GetComponent<ResourceEfficiencyUpgrade>(); City c = transform.root.gameObject.GetComponent<City>();
reu.UpgradeEfficiency(); if (c.IsSufficientResources(resources, 50))
{
List<int> cost = new List<int>() { 50, 50, 50 };
c.UseResources(cost);
EventSystem.EventHappened(EventType.UpgradeBuilt);
}
} }
} }
} }
...@@ -20,8 +20,27 @@ public class BuyPopulation : MonoBehaviour ...@@ -20,8 +20,27 @@ public class BuyPopulation : MonoBehaviour
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
PopulationUpgrade pop = gameObject.GetComponent<PopulationUpgrade>(); City c = transform.root.gameObject.GetComponent<City>();
pop.UpgradePopulation(); List<int> cost = new List<int>() { 50, 50, 50 };
if (c.IsSufficientResources(createResourceGO(), 50))
{
c.UseResources(cost);
c.AddPopulation(50);
EventSystem.EventHappened(EventType.UpgradeBuilt);
} else
{
Debug.Log("Not enough resources");
}
} }
} }
private List<Resource> createResourceGO()
{
GameObject go = new GameObject();
go.AddComponent<Forest>();
go.AddComponent<Quarry>();
go.AddComponent<BerryBush>();
return new List<Resource>(go.GetComponents<Resource>());
}
} }
...@@ -20,7 +20,24 @@ public class BuySpeed : MonoBehaviour ...@@ -20,7 +20,24 @@ public class BuySpeed : MonoBehaviour
{ {
if (Input.GetMouseButtonDown(1)) if (Input.GetMouseButtonDown(1))
{ {
Debug.Log("Ostit Nopeutta"); City c = transform.root.gameObject.GetComponent<City>();
if (c.IsSufficientResources(createResourceGO(), 50))
{
c.UpgradeWorkerSpeed();
List<int> cost = new List<int>() { 50, 50, 50 };
c.UseResources(cost);
EventSystem.EventHappened(EventType.UpgradeBuilt);
}
} }
} }
private List<Resource> createResourceGO()
{
GameObject go = new GameObject();
go.AddComponent<Forest>();
go.AddComponent<Quarry>();
go.AddComponent<BerryBush>();
return new List<Resource>(go.GetComponents<Resource>());
}
} }
...@@ -19,6 +19,6 @@ public class UpgradeShop : MonoBehaviour ...@@ -19,6 +19,6 @@ public class UpgradeShop : MonoBehaviour
private void OnMouseEnter() private void OnMouseEnter()
{ {
Debug.Log("Kauppa auki");
} }
} }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class UsableResources : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
fileFormatVersion: 2
guid: 132e9ec36ed413a4b868b617846af5e7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
...@@ -23,8 +23,9 @@ public class CollectorUpgrade : Upgrade ...@@ -23,8 +23,9 @@ public class CollectorUpgrade : Upgrade
City city = gameObject.GetComponent<City>(); City city = gameObject.GetComponent<City>();
int currentLevel = city.GetLevel(target); int currentLevel = city.GetLevel(target);
if (currentLevel <= city.GetLevel(UpgradeTargets.city) * maxLevelModifier) if (currentLevel <= maxLevelModifier)
{ {
Debug.Log("Collector Upgraded");
city.UseResources(GetPrices(currentLevel)); city.UseResources(GetPrices(currentLevel));
city.AddCollector(); city.AddCollector();
} }
......
...@@ -39,9 +39,10 @@ public class PopulationUpgrade : Upgrade ...@@ -39,9 +39,10 @@ public class PopulationUpgrade : Upgrade
break; break;
} }
*/ */
if (currentLevel <= city.GetLevel(UpgradeTargets.city) * maxLevelModifier) if (currentLevel <= maxLevelModifier)
{ {
city.UseResources(GetPrices(currentLevel + 1)); city.UseResources(GetPrices(currentLevel + 1));
city.populationLevel++;
city.AddPopulation(currentLevel * 10); city.AddPopulation(currentLevel * 10);
Debug.Log("population upgraded"); Debug.Log("population upgraded");
} }
......
...@@ -22,9 +22,10 @@ public class ResourceCapacityUpgrade : Upgrade ...@@ -22,9 +22,10 @@ public class ResourceCapacityUpgrade : Upgrade
City city = gameObject.GetComponent<City>(); City city = gameObject.GetComponent<City>();
int currentLevel = city.GetLevel(target); int currentLevel = city.GetLevel(target);
if (currentLevel <= city.GetLevel(UpgradeTargets.city) * maxLevelModifier) if (currentLevel <= maxLevelModifier)
{ {
city.UseResources((GetPrices(currentLevel))); city.UseResources((GetPrices(currentLevel)));
city.resourcePoolLevel++;
city.IncreaseCapacity(currentLevel * 100); city.IncreaseCapacity(currentLevel * 100);
Debug.Log("Capacity upgraded"); Debug.Log("Capacity upgraded");
} }
......
...@@ -24,7 +24,7 @@ public class RoadUpgrade : Upgrade ...@@ -24,7 +24,7 @@ public class RoadUpgrade : Upgrade
City city = gameObject.GetComponent<City>(); City city = gameObject.GetComponent<City>();
int currentLevel = (int) road.GetLevel(target); int currentLevel = (int) road.GetLevel(target);
if (currentLevel <= city.GetLevel(UpgradeTargets.city) * maxLevelModifier) if (currentLevel <= maxLevelModifier)
{ {
city.UseResources(GetPrices(currentLevel)); city.UseResources(GetPrices(currentLevel));
road.IncreaseSpeed(1 / currentLevel); road.IncreaseSpeed(1 / currentLevel);
......
...@@ -8,13 +8,6 @@ public abstract class Upgrade : MonoBehaviour ...@@ -8,13 +8,6 @@ public abstract class Upgrade : MonoBehaviour
private float efficiencyLevel = 1; private float efficiencyLevel = 1;
private Dictionary<Resource, int> resources = new Dictionary<Resource, int>()
{
{ null , 1},
{ null , 1},
{ null , 0},
};
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
...@@ -63,10 +56,9 @@ public abstract class Upgrade : MonoBehaviour ...@@ -63,10 +56,9 @@ public abstract class Upgrade : MonoBehaviour
public List<int> GetPrices(float modifier) public List<int> GetPrices(float modifier)
{ {
List<int> prices = new List<int>(); List<int> prices = new List<int>();
foreach(KeyValuePair<Resource, int> key in resources)
{ prices.Add((int) (1 * modifier * 50 * GetEfficiency()));
prices.Add((int) (key.Value * modifier * 50 * GetEfficiency()));
}
return prices; return prices;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment