diff --git a/Candied.c b/Candied.c new file mode 100644 index 0000000..daeb5d8 --- /dev/null +++ b/Candied.c @@ -0,0 +1,78 @@ +var candies = { + + // Variables + nbrOwned : 0, + nbrEaten : 0, + nbrThrown : 0, + nbrTotal : 0, // The total number we earned in all times + candiesPerSecond : 100000000000, + + // Functions + onload : function(){ + candies.setNbrOwned(0); // We first have 0 candies + }, + + eat : function(){ + this.setNbrEaten(this.nbrEaten + this.nbrOwned); + this.setNbrOwned(0); + }, + + setNbrTotal : function(value){ + this.nbrTotal = value; + }, + + setNbrOwned : function(value){ + // If this is an increase, we increase nbr total too + if(value > this.nbrOwned){ + this.setNbrTotal(this.nbrTotal + value - this.nbrOwned); + } + + this.nbrOwned = value; + if(this.nbrOwned != 1) htmlInteraction.setInnerHtml("candies", "You have " + this.nbrOwned + " candies!"); + else htmlInteraction.setInnerHtml("candies", "You have 1 candy!"); + buttons.checkCandies(); + shop.check(); + cauldron.updateActionsInfoOnPage(); + }, + + setNbrEaten : function(value){ + this.nbrEaten = value; + if(this.nbrEaten != 1) htmlInteraction.setInnerHtml("candies_eaten", "You have eaten " + this.nbrEaten + " candies!"); + else htmlInteraction.setInnerHtml("candies_eaten", "You have eaten 1 candy!"); + htmlInteraction.setElementVisibility("candies_eaten", true); + }, + + setCandiesPerSecond : function(value){ + this.candiesPerSecond = value; + }, + + setNbrThrown : function(value){ + this.nbrThrown = value; + + // We choose which smiley we want to add at the end of the sentence + if(this.nbrThrown <= 10) smiley = "."; + else if(this.nbrThrown <= 20) smiley = "..."; + else if(this.nbrThrown <= 30) smiley = "...?"; + else if(this.nbrThrown <= 40) smiley = "...? :|"; + else if(this.nbrThrown <= 50) smiley = "...? :/"; + else if(this.nbrThrown <= 60) smiley = "...? :("; + else if(this.nbrThrown <= 70) smiley = "...? :["; + else if(this.nbrThrown <= 80) smiley = "...? :{"; + else if(this.nbrThrown <= 90) smiley = "...? :'("; + else smiley = "...? (;_;)"; + + darkMode.check(); + + if(this.nbrThrown != 1) htmlInteraction.setInnerHtml("candies_thrown", "You threw " + this.nbrThrown + " candies on the ground" + smiley); + else htmlInteraction.setInnerHtml("candies_thrown", "You threw 1 candy on the ground" + smiley); + htmlInteraction.setElementVisibility("candies_thrown", true); + }, + + throw10Candies : function(){ + if(this.nbrOwned >= 10){ // If we have at least 10 candies + this.setNbrOwned(this.nbrOwned - 10); + this.setNbrThrown(this.nbrThrown + 10); + } + } + +};