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

Method drawTicTacToeBoard

code/main/ATree.ts:46–86  ·  view source on GitHub ↗
(addButtons: boolean = true, x: number = 19, y: number = 23)

Source from the content-addressed store, hash-verified

44 }
45
46 private drawTicTacToeBoard(addButtons: boolean = true, x: number = 19, y: number = 23): void{
47 // If the board isn't null
48 if(this.ticTacToeBoard != null){
49 // Draw the board background
50 this.renderArea.drawArray(Database.getAscii("places/aTree/ticTacToeBoard"), x+7, y+5);
51
52 // Iterate over the board to draw signs && add buttons
53 for(var i = 0; i < 5; i++){
54 for(var j = 0; j < 5; j++){
55 // Draw the sign or add the button, depending on the sign
56 switch(this.ticTacToeBoard[i][j]){
57 // There's already a sign : draw the sign
58 case ATreeTicTacToeSign.X:
59 this.renderArea.drawArray(Database.getAscii("places/aTree/ticTacToeX"), x+i*7+3, y+j*4+3);
60 break;
61 case ATreeTicTacToeSign.O:
62 this.renderArea.drawArray(Database.getAscii("places/aTree/ticTacToeO"), x+i*7+2, y+j*4+2);
63 break;
64 // There's no sign yet : draw the button
65 case ATreeTicTacToeSign.NO_SIGN:
66 if(addButtons){
67 // Iterate over the lines on which we need to add the buttons
68 for(var yButton = y+j*4+1; yButton <= y+j*4+4; yButton++){
69 // If we're outside the board : add a ninja button
70 if(i == 0 || i == 4 || j == 0 || j == 4){
71 this.renderArea.addAsciiNinjaButton(x+i*7+1, x+i*7+7, yButton, "aTreeTicTacToeBoardButton" + i + "_" + j);
72 }
73 // Else, we're inside the board : add a regular button
74 else{
75 this.renderArea.addAsciiButton(x+i*7+1, x+i*7+7, yButton, "aTreeTicTacToeBoardButton" + i + "_" + j);
76 }
77 }
78 // Add the link
79 this.renderArea.addLinkCall(".aTreeTicTacToeBoardButton" + i + "_" + j, new CallbackCollection(this.playTicTacToeSign.bind(this, i, j)));
80 }
81 break;
82 }
83 }
84 }
85 }
86 }
87
88 private nextStep(): void{
89 // We change the step

Callers 1

updateMethod · 0.95

Calls 6

drawArrayMethod · 0.80
getAsciiMethod · 0.80
addAsciiNinjaButtonMethod · 0.80
addAsciiButtonMethod · 0.80
addLinkCallMethod · 0.80
bindMethod · 0.80

Tested by

no test coverage detected