diff --git a/web/src/App.vue b/web/src/App.vue index c6b7f10..7afd6f4 100644 --- a/web/src/App.vue +++ b/web/src/App.vue @@ -40,7 +40,7 @@ export default { \ No newline at end of file diff --git a/web/src/assets/background.png b/web/src/assets/images/background.png similarity index 100% rename from web/src/assets/background.png rename to web/src/assets/images/background.png diff --git a/web/src/assets/scripts/AcGameObject.js b/web/src/assets/scripts/AcGameObject.js new file mode 100644 index 0000000..b2da0e5 --- /dev/null +++ b/web/src/assets/scripts/AcGameObject.js @@ -0,0 +1,71 @@ +const AC_GAME_OBJECTS = []; + +// 基类 +export class AcGameObject +{ + constructor(){ + //添加对象 + AC_GAME_OBJECTS.push(this); + //时间间隔 + this.timedelta = 0; + //没有执行过start函数 + this.has_called_satrt = false; + } + + start(){//只在开始执行一次 + + } + + update(){//除了第一次,每一帧执行一次 + + } + + on_destroy(){// 删除前执行一次 + + } + + destroy(){//删除时执行 + this.on_destroy(); + + //删除对象 + for(let i in AC_GAME_OBJECTS){ + const obj = AC_GAME_OBJECTS[i]; + if(obj === this) + { + AC_GAME_OBJECTS.splice(i); + break; + } + } + } +} + + + + +//上一秒执行的时刻 +let last_timestamp; + +const step = timestamp => { + //针对所有对象 + for(let obj of AC_GAME_OBJECTS) + { + if(obj.has_called_satrt===false)//执行start + { + obj.start();//调用的是子类的start() + obj.has_called_satrt=true; + } + else //执行update + { + obj.update();//调用的是子类的update() + obj.timedelta = timestamp - last_timestamp;//当前-之前 + } + } + last_timestamp = timestamp; + + //【迭代】浏览器每一秒会迭代60次 + requestAnimationFrame(step); + +} + +//浏览器刷新 -> 执行一次 +requestAnimationFrame(step); \ No newline at end of file diff --git a/web/src/assets/scripts/GameMap.js b/web/src/assets/scripts/GameMap.js new file mode 100644 index 0000000..409b42c --- /dev/null +++ b/web/src/assets/scripts/GameMap.js @@ -0,0 +1,139 @@ + +import { AcGameObject } from "./AcGameObject"; +import { Wall } from "./Wall"; + +export class GameMap extends AcGameObject +{ + //画布+父元素 + constructor(ctx,parent) + { + super(); + this.ctx = ctx;//画布 + this.parent = parent;//父元素 + this.L = 0;//小正方形的边长 + + this.rows = 13; + this.cols = 13; + + this.walls=[]; + + this.inner_walls_count = 20; + } + + check_connectivity(g,sx,sy,tx,ty) + { + if(sx==tx&&sy==ty)return true; + g[sx][sy]=true; + let dx=[-1,0,1,0],dy=[0,1,0,-1]; + for(let i=0;i<4;i++) + { + let x = sx + dx[i],y = sy + dy[i]; + if(g[x][y]==false && this.check_connectivity(g,x,y,tx,ty))return true; + } + return false; + } + + create_wall(){ + + //初始化【没有墙 false】 + const g=[] + for(let r=0;r 然后flex居中排布 + this.ctx.fillRect(c*this.L,r*this.L,this.L,this.L); + } + } + // //测试 + // this.ctx.fillStyle = "red"; + // this.ctx.fillRect(0,0,this.ctx.canvas.width,this.ctx.canvas.height); + } +} \ No newline at end of file diff --git a/web/src/assets/scripts/Wall.js b/web/src/assets/scripts/Wall.js new file mode 100644 index 0000000..d438600 --- /dev/null +++ b/web/src/assets/scripts/Wall.js @@ -0,0 +1,32 @@ +import { AcGameObject } from "./AcGameObject"; + +export class Wall extends AcGameObject{ + //传入 行 列 地图 + constructor(r,c,gamemap){ + super(); + + this.r = r; + this.c = c; + this.gamemap = gamemap; + this.color = "#B37266"; + } + + start(){ + + } + + update(){ + this.render(); + } + + //渲染 + render(){ + //获取地图中 小格长度 画板 + const L = this.gamemap.L; + const ctx = this.gamemap.ctx; + + ctx.fillStyle = this.color; + ctx.fillRect(this.c*L,this.r*L, L, L); + } + +} \ No newline at end of file diff --git a/web/src/components/GameMap.vue b/web/src/components/GameMap.vue new file mode 100644 index 0000000..07685d2 --- /dev/null +++ b/web/src/components/GameMap.vue @@ -0,0 +1,42 @@ + + + + + \ No newline at end of file diff --git a/web/src/components/PlayGround.vue b/web/src/components/PlayGround.vue new file mode 100644 index 0000000..50068a6 --- /dev/null +++ b/web/src/components/PlayGround.vue @@ -0,0 +1,27 @@ + + + + + \ No newline at end of file diff --git a/web/src/views/pk/PkIndexView.vue b/web/src/views/pk/PkIndexView.vue index 21bd895..8f4e974 100644 --- a/web/src/views/pk/PkIndexView.vue +++ b/web/src/views/pk/PkIndexView.vue @@ -1,15 +1,13 @@