1
對於一款國際象棋遊戲,我搜索敵方棋子上可能的攻擊者。 董事會代表是通過多維數組完成的。 board[i][j]
,其中i =行和j是列(如此8x8),並且該值是該片本身。分配數組值不工作?
當攻擊者可以搜索我想創建一個新的數組aPossibleAttackers[i][j]
var aPossibleAttackers = []; // create array
var ti,tj; // temp row/col
我做所有可能的方向(0-7)的搜索和查找第一塊我見面。那麼方向和距離是已知的。然後我計算這是哪個字段,並且想要將對應的值從board[i][j]
複製到aPossibleAttackers[i][j]
。雖然這不起作用。
代碼:
alert(veld(attackerRow,attackerCol) + " pos att op veld " + veld((attackerRow + (i * rowStep)), (attackerCol + (i * colStep))));
aPossibleAttackers[search_dir] = i; // searchdirection and distance, OK
ti = attackerRow + (i * rowStep); // OK
tj = attackerCol + (i * colStep); // OK
//aPossibleAttackers[ti][tj] = board[ti][tj]; // not possible????
alert("test2 ti= " + ti + " tj=" + tj + " ?? " + aPossibleAttackers);
我在做什麼錯? board[i][j]
確實存在,否則我不會找到一塊。
出了什麼問題'aPossibleAttackers [TI] [TJ] =板[TI] [TJ]'? –
在errorconsole我得到:Tijdstempel:20-1-2013 17時45分54秒 的F out:類型錯誤:無法轉換未定義反對 Bronbestand:HTTP://www.xxxxxxxxxxxx/javascript.js 蔥:2021 – Terradon
那會暗示「aPossibleAttackers [ti]'或」board [ti]'是未初始化的。 –