我創建了一個小型遊戲,我在其中創建了一個正方形的表格,並且第一個點擊了左下角的一個元素丟失了。選擇表格中的最後一個元素
我在編輯程序中左下角[point:(1,1)] square的問題。我的目標是有一個綠色廣場,在我的.CSS標記#poison
#poison {
width: 5em;
height: 5em;
padding: 0;
background-size: 5em 5em;
background-image: url("http://imgur.com/6Apk8Rk");
}
出現,而不是常規的棕色方形我目前輸出。
我不確定如何用#poison正方形替換左下角的正方形。
這裏是我用來創建表的JS函數。
function makeTable(x, y) {
var gameTable = document.getElementById('gameTable'),
poison = document.getElementById('poison');
gameTable.innerHTML = null;
var table = [];
//creates rows
for (let i = 0; i < x; i += 1) {
var row = document.createElement('tr');
//appends each row to the table
gameTable.appendChild(row);
//store the amount of iterations in array trow
var tRow = [];
table[i] = tRow;
//create columns (cells)
for (let j = 0; j < y; j += 1) {
let cell = document.createElement('td'); //td defines a cell
//set x,y coordinates
cell.pos = { x: i, y: j };
//stores table values into cell
table[i][j] = cell;
//if you click the bottom left piece of chocolate..
if (i === x - 1 && j === 0) {
cell.onclick = function() {
//..restart the game
restartGame();
}
//else, behave normally
} else {
cell.onclick = function() {
cellClick(cell);
}
}
//append cells to the table
row.appendChild(cell);
}
}
}
下面是相關的HTML被要求:
<fieldset id="RowColbox">
<label>
<span>Rows:</span>
<input name="Cols" id="cols" type="number" value="3"/>
</label>
<label>
<span>Columns:</span>
<input name="Rows" id="rows" type="number" value="4"/>
</label>
<button id="addDimensions" type="button">create</button>
</fieldset>
<table id="gameTable">
</table>
Here是我的代碼在它的全部。
請添加HTML –
添加了相關的HTML,全部可以在我在原崗位鏈接找到 – user3335607