Ejemplo n.º 1
0
 public Disturbance(Island argLocation, int argDuration, int argForce)
 {
     location = argLocation;
     duration = argDuration;
     remaingTime = argDuration;
     force = argForce;
 }
 //give a ressource named "name" to "island", with a stock of "quantity"
 //if the ressource didn't exist on "island", it is created
 public void giveRessource(string name, Island island, int quantity)
 {
     Ressource ressource = new Ressource(name, quantity);
     if (island.getRessource(name) == null)  //the island doesn't have this ressource
     {
         island.ressources.Add(new Ressource(name));
         island.getRessource(name).stock = quantity;
     }
     else    //the island has this ressource
     {
         island.getRessource(name).stock += quantity;
     }
 }
Ejemplo n.º 3
0
 //give a stock of "quantity" of the ressource named "name" to "island"
 public void giveRessourceToIsland(string name, int quantity, Island island)
 {
     RessourceManager rm = new RessourceManager();
     int quantityWithdrawn = rm.withdrawRessource(name, this, quantity);
     //we give to "island" the quantity withdrawn from the current island
     if (quantityWithdrawn != 0)
     {
         rm.giveRessource(name, island, quantityWithdrawn);
         System.Diagnostics.Debug.WriteLine("L'ile " + this.id.ToString() + " donne " + quantityWithdrawn.ToString() + " " + name + " à l'ile " + island.id.ToString());
     }
     else
         System.Diagnostics.Debug.WriteLine("La ressource " + name + " n'est plus disponible sur l'ile " + island.id.ToString());
 }
 //withdraw a stock of "quantity" from a ressource named "name" of "island"
 //returns the effectively quantity withdrawn (if stock=5 & quantity=7, it returns 5)
 public int withdrawRessource(string name, Island island, int quantity)
 {
     Ressource ressource = island.getRessource(name);
     if (ressource == null)  //if the ressource doesn't exist on the island
         return 0;
     if (ressource.stock <= quantity)
     {
         int temp = ressource.stock;
         ressource.stock = 0;
         return temp;
     }
     else
     {
         ressource.stock -= quantity;
         return quantity;
     }
 }
Ejemplo n.º 5
0
 //consume the ressourceNeedded and produce the ressourceProduced (only if there was still a stock of ressourceNeedded)
 //method called by an Island, each 10 seconds while the state of the building is 1
 public void consume_produce(Island island)
 {
     RessourceManager rm = new RessourceManager();
     //checks if the ressourceNeeded exists and if there is enough of its stock
     if ((island.getRessource(ressourceNeeded) != null) && (island.getRessource(ressourceNeeded).stock >= consumptionCost))  
     {
         rm.withdrawRessource(ressourceNeeded, island, consumptionCost); //consumption
         rm.giveRessource(ressourceProduced, island, productionCost);    //production
         System.Diagnostics.Debug.WriteLine("Le batiment " + this.name + " utilise " + this.consumptionCost.ToString() + " " + this.ressourceNeeded + " et produit " + this.productionCost.ToString() + " " + this.ressourceProduced + " sur l'ile " + island.id.ToString());
     }    
     else
     {
         System.Diagnostics.Debug.WriteLine("Le batiment " + this.name + " ne peut plus produire de " + this.ressourceProduced + " car il ne reste pas assez de " + ressourceNeeded + " sur l'ile " + island.id.ToString());
     }        
 }