Skip to content

Instantly share code, notes, and snippets.

@slior

slior/drawing.js Secret

Created November 11, 2020 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slior/4c0b049047825136fa5124abf492e86f to your computer and use it in GitHub Desktop.
Save slior/4c0b049047825136fa5124abf492e86f to your computer and use it in GitHub Desktop.
Mancala (8879f316085b5d4511274c429e6015d6bbe6dbfc) - adding highlights
function createHighlights(cellCount)
{
...
let w = (_boardWidthInCells -2)* CELL_SIZE;
let t = TOP_LEFT.y;
let l = TOP_LEFT.x + CELL_SIZE;
let boardHeightInCells = 3;
p1Highlight = new fabric.Line([l,t,l+w,t],{selectable:false,stroke:'red',strokeWidth:3})
p2Highlight = new fabric.Line([l,t+(boardHeightInCells*CELL_SIZE),l+w,t+(boardHeightInCells*CELL_SIZE)],{selectable:false,stroke:'red',strokeWidth:3})
...
}
function toggleHighlights(canvas,player)
{
requires(player == 1 || player == 2,"Invalid player when switching highlights")
switch (player)
{
case 1 :
canvas.add(p1Highlight);
canvas.remove(p2Highlight);
break;
case 2 :
canvas.add(p2Highlight);
canvas.remove(p1Highlight);
break;
}
}
_initializeBoardDrawing()
{
...
toggleHighlights(cnvs,this.player.number)
}
togglePlayer()
{
...
this.canvas.ifPresent( cnvs => {
toggleHighlights(cnvs,this.player.number);
})
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment