Created
January 16, 2013 20:28
-
-
Save rvandervort/4550607 to your computer and use it in GitHub Desktop.
10 x 10 battleship board in canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
</head> | |
<body> | |
<canvas id="opponent_board" width="800" height="800"></canvas> | |
<script type="text/javascript"> | |
var canvas = document.getElementById('opponent_board'); | |
var context = canvas.getContext("2d"); | |
var dim = 40; | |
context.beginPath(); | |
// Vertical Captions | |
for (var y = 1; y <= 10; y++) { | |
context.fillStyle = '#000000'; | |
context.font = "bold 18px sans-serif"; | |
context.testBaseLine = "bottom"; | |
context.fillText(y, 10, y * dim + 24); | |
} | |
// Horizontal Captions | |
for (var x = 1; x <= 10; x++) { | |
context.fillStyle = '#000000'; | |
context.font = "bold 18px sans-serif"; | |
context.testBaseLine = "bottom"; | |
context.fillText(x, x * dim + 14, 20); | |
} | |
for (var x = 1; x <= 10; x++) { | |
for (var y = 1; y <= 10; y++) { | |
context.rect(x * dim, y * dim, dim, dim); | |
context.lineWidth = 2; | |
context.strokeStyle = '#a0a0a0'; | |
context.stroke(); | |
} | |
} | |
function highlight_cell(context, x, y, dim) { | |
context.beginPath(); | |
context.rect(x * dim + 1, y * dim + 1, dim - 2, dim - 2); | |
context.fillStyle = "#84BDA6"; | |
context.fill(); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment