public override GameObject[,] InitiateMatrix(string str) { GameObject[,] mat = new GameObject[nbRow, nbCol]; Vector3 center = new Vector3(ResourceMatrix.tileSize * ResourceMatrix.nbCol / 2, ResourceMatrix.tileSize * ResourceMatrix.nbRow / 2, 0); for (int i = 0; i < GameMatrix.nbRow; i++) { for (int j = 0; j < GameMatrix.nbCol; j++) { if (char.Equals(str [i * nbCol + j], 'p')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resPlant); } else if (char.Equals(str [i * nbCol + j], 'w')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resWater); } else if (char.Equals(str [i * nbCol + j], 'o')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resWood); } else if (char.Equals(str [i * nbCol + j], 'b')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resBottle); } else if (char.Equals(str [i * nbCol + j], 'e')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resElectricity); } else if (char.Equals(str [i * nbCol + j], 'u')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resPollution); } else if (char.Equals(str [i * nbCol + j], 'r')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, resRadioactivity); } else { mat [i, j] = GameElement.InstantiateGameObject(i, j, resNull); } } } return(mat); }
public void Produce() { GameObject obj = res.GetObject(coo.indexR, coo.indexC); if (obj != null) { if (string.Equals(obj.tag, prefabResource.tag) && !string.Equals(obj.tag, "radioactivityWaste") && !string.Equals(obj.tag, "electricity")) { // La ressource sur le terrain est la meme que la ressource produite par le terrain, donc on stack la nouvelle ressource sur celle deja presente obj.GetComponent <QuantityUnit> ().StackUnit(); } else if (string.Equals(obj.tag, "none")) { // On a une ressource nulle sur le terrain. On la remplace par une ressource produite. Destroy(obj); GameElement.InstantiateGameObject(coo.indexR, coo.indexC, prefabResource); } } }
public override GameObject[,] InitiateMatrix(string str) { GameObject[,] mat = new GameObject[GameMatrix.nbRow, GameMatrix.nbCol]; for (int i = 0; i < GameMatrix.nbRow; i++) { for (int j = 0; j < GameMatrix.nbCol; j++) { if (char.Equals(str [i * nbCol + j], 'f')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndForest); } else if (char.Equals(str [i * nbCol + j], 'p')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndPlain); } else if (char.Equals(str [i * nbCol + j], 'i')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndInfested); } else if (char.Equals(str [i * nbCol + j], 'c')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndCity); } else if (char.Equals(str [i * nbCol + j], 'r')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndRiver); } else if (char.Equals(str [i * nbCol + j], 'e')) { mat [i, j] = GameElement.InstantiateGameObject(i, j, gndEnergyCentral); } else { Debug.Log("ne fait rien, bizarre"); } } } return(mat); }
public void Infection() { GameObject ground = gnd.GetObject(coo.indexR, coo.indexC); if (ground != null) { if (!string.Equals(ground.tag, "infestedGnd") && !string.Equals(ground.tag, "city") && !string.Equals(ground.tag, "central")) { if (ground.GetComponent <Production> () != null) { // Si le sol produisait quelque chose, on fait en sorte qu'il ne produit plus rien desormais. // On supprime son handler de l'event OnClock ground.GetComponent <Production> ().StopProduction(); } // On remplace l'ancien sol par un sol contamine. Destroy(ground); GameObject newGround = GameElement.InstantiateGameObject(coo.indexR, coo.indexC, infestedGround); gnd.SetObject(coo.indexR, coo.indexC, newGround); } } }
private void Consume() { Debug.Log("on consomme"); GameObject resource = res.GetObject(coo.indexR, coo.indexC); if (string.Equals(resource.tag, "plant")) { int qtt = resource.GetComponent <QuantityUnit> ().Quantity; if (resource.GetComponent <Radioactive> () == null) { happiness += qtt * ResourcesStat.happinessPlant; hunger += qtt * ResourcesStat.hungerPlant; health += qtt * ResourcesStat.healthPlant; } else { happiness += qtt * ResourcesStat.happinessRadioactivePlant; hunger += qtt * ResourcesStat.hungerRadioactivePlant; health += qtt * ResourcesStat.healthRadioactivePlant; } } else if (string.Equals(resource.tag, "water")) { int qtt = resource.GetComponent <QuantityUnit> ().Quantity; if (resource.GetComponent <Radioactive> () == null) { happiness += qtt * ResourcesStat.happinessWater; hunger += qtt * ResourcesStat.hungerWater; health += qtt * ResourcesStat.healthWater; } else { happiness += qtt * ResourcesStat.happinessRadioactiveWater; hunger += qtt * ResourcesStat.hungerRadioactiveWater; health += qtt * ResourcesStat.healthRadioactiveWater; } } else if (string.Equals(resource.tag, "electricity")) { happiness += ResourcesStat.happinessElectricity; hunger += ResourcesStat.hungerElectricity; health += ResourcesStat.healthElectricity; } if (Random.value < 0.3f) // 30% de chances de générer un déchet { if (string.Equals(res.GetObject(coo.indexR + 1, coo.indexC).tag, "none")) { Destroy(res.GetObject(coo.indexR + 1, coo.indexC)); GameElement.InstantiateGameObject(coo.indexR + 1, coo.indexC, resourceWaste); } else if (string.Equals(res.GetObject(coo.indexR - 1, coo.indexC).tag, "none")) { Destroy(res.GetObject(coo.indexR - 1, coo.indexC)); GameElement.InstantiateGameObject(coo.indexR - 1, coo.indexC, resourceWaste); } else if (string.Equals(res.GetObject(coo.indexR, coo.indexC + 1).tag, "none")) { Destroy(res.GetObject(coo.indexR, coo.indexC + 1)); GameElement.InstantiateGameObject(coo.indexR, coo.indexC + 1, resourceWaste); } else { Destroy(res.GetObject(coo.indexR, coo.indexC - 1)); GameElement.InstantiateGameObject(coo.indexR, coo.indexC - 1, resourceWaste); } } Destroy(res.GetObject(coo.indexR, coo.indexC)); GameElement.InstantiateGameObject(coo.indexR, coo.indexC, resourceNull); Debug.Log("hap : " + happiness + "; hung : " + hunger + "; heal : " + health); }