MCPcopy Create free account
hub / github.com/candybox2/candybox2.github.io / buySelectedItem

Method buySelectedItem

code/main/SecondHouse.ts:74–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72 }
73
74 private buySelectedItem(): void{
75 // If we have enough candies to buy it
76 if(this.getGame().getCandies().getCurrent() >= this.items[this.selectedItemIndex].getPrice()){
77 // We pay the price
78 this.getGame().getCandies().add(-this.items[this.selectedItemIndex].getPrice());
79 // We tell the item that we just bought it
80 this.items[this.selectedItemIndex].buy();
81 // No more selected item
82 this.selectedItemIndex = null;
83 // We update
84 this.update();
85 this.getGame().updatePlace();
86 }
87 }
88
89 private clickedOnItem(index: number): void{
90 // Set the currently selected item index

Callers

nothing calls this directly

Calls 8

updateMethod · 0.95
getCurrentMethod · 0.80
getPriceMethod · 0.80
updatePlaceMethod · 0.80
addMethod · 0.65
getCandiesMethod · 0.45
getGameMethod · 0.45
buyMethod · 0.45

Tested by

no test coverage detected