SpencerTSterling / CatClicker

0 stars 0 forks source link

Refactor the purchasing building logic #10

Closed SpencerTSterling closed 8 months ago

SpencerTSterling commented 8 months ago

The Clicker building functions as it is supposed to - when purchased, it decreases Total Kitties and increases the CpS.

Right now, when the player clicks the building box for the Clicker (called clickerBox), it triggers a function clickClicker(). In this function, first a constant value newTotalKitties is created, which uses a function from the Buildings class (updatedTotalKitties()) to calculate the total amount of Kitties minus the cost of the building being purchased.

Then the buyBuilding() function is called - originally this function calculated the newTotalKitties value - but was refactored because it would progress the building's level and price BEFORE its price was subtracted from Total Kitties, which sometimes resulted in negative values for Total Kitties. So now you pass in totalKittiesNum and the function calculates if the Player can afford the building, then increases the level value and recalculates the cost, else they get a console log message saying they do not have enough Kitties to buy the building.

As of now, the function should no longer have the the totalKittiesNum passed in (purchase logic should happen in index.js), and should only increase the level and cost of the building being purchased. It should be renamed to something else related to the building's level progression. This is related to the other concept - where once a building's level equals its original base price, the next building succession is unlocked (i.e once 10 Clickers are purchased, then Treat Bag is unlocked).