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

Method getCurrentAsString

code/main/Candies.ts:10–57  ·  view source on GitHub ↗
(totalSize: number = 10)

Source from the content-addressed store, hash-verified

8
9 // Public methods
10 public getCurrentAsString(totalSize: number = 10): string{
11 var n: number = this.getCurrent();
12 var size: number = totalSize;
13
14 var base: string = "";
15 var prefix: string = "";
16 var suffix: string = "";
17 var comment: string = "";
18
19 // We set the base or return right now in some special cases
20 if(n < 0)
21 return "What, negative candies?!";
22 else if(n == 1)
23 return "You have 1 candy";
24 else{
25 if(n == 1337)
26 base = "leet";
27 else
28 base = Algo.numberToStringButNicely(n);
29 }
30
31 // How much space do we still have ?
32 size = totalSize - base.length;
33
34 // We set the suffix
35 if(size >= 8){
36 suffix = " candies";
37
38 // We add a prefix
39 // How much space do we still have ?
40 size = totalSize - base.length - suffix.length;
41
42 // We set the prefix
43 if(size >= 9) prefix = "You have ";
44 else if(size >= 3) prefix = "-> ";
45 }
46 else if(size >= 4) suffix = " cnd";
47 else if(size >= 2) suffix = " c";
48
49 // How much space do we still have ?
50 size = totalSize - base.length - prefix.length - suffix.length;
51
52 // We possibly set a comment
53 if(n == 42 && size >= 4) comment = " \\o/";
54 else if((n == 65535 || n == 314159) && size >= 1) comment = "!";
55
56 return prefix + base + suffix + comment;
57 }
58}

Callers 3

updateAllMethod · 0.45
updateMethod · 0.45

Calls 1

getCurrentMethod · 0.80

Tested by

no test coverage detected