-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathground.js
More file actions
38 lines (37 loc) · 1.31 KB
/
Copy pathground.js
File metadata and controls
38 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var ground = new Ground(baseX, baseY, xLen * squareWidth, yLen * squareWidth)
ground.init = function () {
this.viewContent.style.position = "absolute";
this.viewContent.style.left = this.x + "px";
this.viewContent.style.top = this.y + "px";
this.viewContent.style.width = this.width + "px";
this.viewContent.style.height = this.height + "px";
this.viewContent.style.backgroundColor = "#0f0";
document.body.appendChild(this.viewContent)
//填充广场
//二维数组
this.squareTable=[]
for(var i = 0; i < yLen; i++){
this.squareTable[i]=[]
for(var j = 0; j < xLen; j++){
if(i==0||i==yLen-1||j==0||j==xLen-1){
//生成障碍物
var newSquare=Squarefactory.create("Stone",j,i,"black")
}else{
//生成地板
var newSquare = Squarefactory.create("Floor",j,i,"#eee")
}
this.squareTable[i][j]=newSquare
this.viewContent.appendChild(newSquare.viewContent)
}
}
}
ground.remove=function(x,y){
this.squareTable[y][x].viewContent.remove();
this.squareTable[y][x]=null;
}
ground.append=function(square){
// console.log(square)
this.squareTable[square.y][square.x] = square;
this.viewContent.appendChild(square.viewContent)
}
ground.init()