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

Method putInCauldron

code/main/Cauldron.ts:319–377  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

317 }
318
319 private putInCauldron(): void{
320 // Used to know if we will have to update and return
321 var updateAndReturn: boolean = false;
322
323 // Parse the inputs and put them in two variables
324 var candies: number = (this.candiesInput == ""? 0 : parseInt(this.candiesInput));
325 var lollipops: number = (this.lollipopsInput == ""? 0 : parseInt(this.lollipopsInput));
326
327 // Reset the comments
328 this.candiesInputComment = null;
329 this.lollipopsInputComment = null;
330
331 // If the candies are incorrect, set the comment and return
332 if(isNaN(candies)){
333 this.candiesInputComment = "(this isn't a number!)";
334 updateAndReturn = true;
335 }
336 else if(candies < 0){
337 this.candiesInputComment = "(must be positive)";
338 updateAndReturn = true;
339 }
340 else if(candies > this.getGame().getCandies().getCurrent()){
341 this.candiesInputComment = "(not enough candies)";
342 updateAndReturn = true;
343 }
344
345 // If the lollipops are incorrect, set the comment and return
346 if(isNaN(lollipops)){
347 this.lollipopsInputComment = "(this isn't a number!)";
348 updateAndReturn = true;
349 }
350 else if(lollipops < 0){
351 this.lollipopsInputComment = "(must be positive)";
352 updateAndReturn = true;
353 }
354 else if(lollipops > this.getGame().getLollipops().getCurrent()){
355 this.lollipopsInputComment = "(not enough lollipops)";
356 updateAndReturn = true;
357 }
358
359 // If we have to update and return, well, we do that
360 if(updateAndReturn){
361 this.update();
362 this.getGame().updatePlace();
363 return;
364 }
365 // Else, we put the candies & lollipops in the cauldron
366 else{
367 // Take the candies & lollipops
368 this.getGame().getCandies().add(-candies);
369 this.getGame().getLollipops().add(-lollipops);
370 // Put all the stuff
371 this.getGame().getCandiesInCauldron().add(candies);
372 this.getGame().getLollipopsInCauldron().add(lollipops);
373 // Update
374 this.update(false, false);
375 this.getGame().updatePlace();
376 }

Callers

nothing calls this directly

Calls 9

updateMethod · 0.95
getCurrentMethod · 0.80
updatePlaceMethod · 0.80
getCandiesInCauldronMethod · 0.80
addMethod · 0.65
getCandiesMethod · 0.45
getGameMethod · 0.45
getLollipopsMethod · 0.45

Tested by

no test coverage detected