if (this.name != undefined) { //clicked a non-empty if (holding == null) { //PICK U0 } else { //SWAP } //clicked a non-empty tile while maybe holding something. //so we'll pick up what we clicked while putting down what was held. var previousHeld = null; grabbedName = this.name; if (holding != null) { //hexes[puzzleTiles[holding][0]][puzzleTiles[holding][1]].name = grabbedName; previousHeld = hexes[puzzleTiles[holding][0]][puzzleTiles[holding][1]]; previousHeld.name = grabbedName; //hexes[puzzleTiles[holding][0]][puzzleTiles[holding][1]].draw(c); this.name = holding; holding = null; } else { holding = grabbedName; } puzzleTiles[this.name][0] = this.column; puzzleTiles[this.name][1] = this.row; if (previousHeld != null) previousHeld.draw(c); this.draw(c); sayIfWon(c); return; }