#ソースコード
<html> <head> <meta charset="UTF-8"> <title>マインスイーパー</title> </head> <body> <canvas id="block_kuzushi"width="640"height="480"></canvas> </body> </html> <script type="text/javascript"> //定数 var BACKGROUND_COLOR = '#000000' var CVS_WIDTH = 640; var CVS_HEIGHT = 480; var ROW = 9; var COL = 9; var BLOCK_STROKECOLOR = 'Black' //変数 var ctx = null; var blocks = [ ]; var status = 0; //0プレイ中、1クリア、2ゲームオーバ var block_color = 'Blue'; function main (){ var cvs = document.getElementById('MineSweeper'); ctx = cvs.getContext('2d'); ctx.fillStyle = BACKGROUND_COLOR; ctx.fillRect(0, 0, CVS_WIDTH, CVS_HEIGHT); for(var i = 0; i<ROW;i++){ for(var j = 0;j < COL;j++){ blocks[i*COL+j] = { x: 40 + j * 40, y: 40 + i * 20, w: 46, h: 46, isBlock: true }; } } setInterval(function(){ ctx.fillStyle = BLOCK_COLOR; ctx.fillRect(block.x, block.y, block.w, block.h); ctx.strokeStyle = BLOCK_STROKECOLOR; ctx.strokeRect(block.x, block.y, block.w, block.h); for(var i = 0;i < ROW;i++){ for(var j = 0;j < COL;j++){ var block = blocks[i * COL + j]; //ブロックを描画 ctx.fillStyle = BLOCK_COLOR; ctx.fillRect(block.x, block.y, block.w, block.h); ctx.strokeStyle = BLOCK_STROKECOLOR; ctx.strokeRect(block.x, block.y, block.w, block.h); } } },parseInt(1000 / FPS)); } window.onload = function(){ main(); } </script>
#エラー内容
Unable to get property 'getContext' of undefined or null reference
初心者ですお願いします。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。