我实际上是IT Programmation的法国学生,我的项目是制作战舰游戏,当我编写功能AI时,它会告诉我一个错误,我该如何阻止这个错误?这是函数的代码:
private function tourIA(){
var position = new List<Int>();
for(i in 0...(Std.parseInt(Math.pow(dimensions,2)))position.add(i);
var pos = Std.random(length(position);
var cellule = position[pos];
var x = cellule%dimensions;
var y = Math.floor(cellule);
var n : Navire = mer.chercherNavire(x , y);
if (n != null) {
mer.montrerNavire(n);
}
else{
mer.placerCroix(mer, position, dimension);
}
}
Run Code Online (Sandbox Code Playgroud)
错误已开启 var cellule = position[pos];