Commits

Colin Copeland committed 9a326a4

fix row/column x/y pairing

Comments (0)

Files changed (1)

tic-tac-toe/media/game.js

 
 function draw(ctx, x, y) {
     console.log('draw', ctx, x, y);
-    region_x = Math.floor(x / box_size);
-    region_y = Math.floor(y / box_size);
-    mark(ctx, region_x, region_y);
+    col = Math.floor(x / box_size);
+    row = Math.floor(y / box_size);
+    mark(ctx, row, col);
 }
 
 function mark(ctx, row, col) {
     console.log('mark', row, col);
-    var x = row * box_size + line_size;
-    var y = col * box_size + line_size;
     var game = new TicTacToe(board);
     if (game.space_is_free(row, col)) {
         game.move(row, col, turn);
         ctx.fillStyle = colors[turn];
+        var x = col * box_size + line_size;
+        var y = row * box_size + line_size;
         ctx.fillRect(x, y, box_size - line_size, box_size - line_size);
     }
     board = game.board;