【問題】8パズル 問3
問2まででロジックは完成しているので
今日からUI周りの問題です。
TODOを実装し、パネルを表示せよ。
<!DOCTYPE html> <style> .puzzle { width: 300px; height:300px; position: absolute; background: #888; } .puzzle>div { background: #ff8; position: absolute; width: 100px; height: 100px; text-align: center; border: inset 1px #888; } </style> <div class="puzzle"> <div id="pannel_1" style="left:100px;top: 0px;">1</div> <div id="pannel_2" style="left:200px;top: 0px;">2</div> <div id="pannel_3" style="left: 0px;top:100px;">3</div> <div id="pannel_4" style="left:100px;top:100px;">4</div> <div id="pannel_5" style="left:200px;top:100px;">5</div> <div id="pannel_6" style="left: 0px;top:200px;">6</div> <div id="pannel_7" style="left:100px;top:200px;">7</div> <div id="pannel_8" style="left:200px;top:200px;">8</div> </div> <script> /** * パネルの値から位置を取得する * * @param ary2d {number[][]} 8パズルのパネルを表す配列。空の場所には0が入る。ary2d[y][x]なことに気をつけよう。 * @param value {number} 検索する値 * @return { {x:number, y:number} } 位置を表すオブジェクト */ function findPos(ary2d, value) { // TODO: 実装する 問2の回答 } /** * パネルを表示する * * @param ary2d {number[][]} 8パズルのパネルを表す配列。空の場所には0が入る。ary2d[y][x]なことに気をつけよう。 */ function draw(ary2d) { // TODO: 実装する // ヒント:findPos()を使う } var ary2d = [ [1, 2, 0], [3, 4, 5], [6, 7, 8] ]; // 表示する draw(ary2d); </script>