--围墙大作战--韩永旗--星空露珠工作室--借鉴圈圈大作战领土模式--667,1,2,3,4,5,6,9,10,11,12,13,14--617,--沙红681-676 673-668--毛毯630-625 622-617local Script {}local id{616,667}local id{1,2,3,4,5,6, 7, 8,9,10,11,12,13,14}local playid{0,0,0,0,0,0,-1,-1, 0,0,0,0,0,0}local row{{-1,0},{0,1},{1,0},{0,-1}}local Ps{}local map{}local mapdata{}local g,h99,99 --大小local x0,y0,z00,7,0 --中心点坐标local s3 --颜色区块local WorldId0local function color0(p) local entercolor{} for k,v in ipairs(playid) do if v0 then entercolor[#entercolor1]k end end local ventercolor[math.random(1,#entercolor)] playid[v]p return v endlocal function destroyblock(x,y,z) Block:DestroyBlock(x, y, z, false, WorldId) endlocal function setblock(x,y,z,id) Block:ReplaceBlock(id, x, y, z, nil, nil, WorldId) endlocal function map0() print(初始化游戏地图数据) local tbl{} for i1,99 do tbl[i]{} for j1,99 do tbl[i][j]0 end end return tbl end--local mapmap0()--local mapdatamap0()local function remap(leavecolor)for i,v in ipairs(map) dofor j,k in ipairs(v) doif mapdate[i][j]leavecolor thenmapdate[i][j]0destroyblock(i-50,7,j-50)endif kleavecolor thenmap[i][j]0setblock(i-50,6,j-50,(math.floor(i/s)math.floor(j/s))%2674)endendendendlocal function add(p)print(获取玩家初始坐标)if #map0 then mapmap0() mapdatemap0() endrepeatx,zmath.random(10,90),math.random(10,90)until (map[x-1][z-1]0 and map[x1][z-1]0 andmap[x-1][z1]0 and map[x1][z1]0 andmap[x][z-1]0 and map[x1][z]0 andmap[x][z1]0 and map[x1][z]0 andmap[x][z]0)print(x,z)Ps[p].run0Ps[p].x,Ps[p].zx,zActor:SetPosition(p,x-50,7,z-50)Ps[p].run0for i-1,1 do for j-1,1 do map[xi][zj]Ps[p].color setblock(xi-50,6,zj-50,Ps[p].color667) end endActor:SetPosition(p,x-50,7,z-50)end--快速生成围墙地形--韩永旗制作function Script:Game_StartGame(g,h)print(绘图)self:ThreadWork(function()map0() end)--local function destroyblock(x,y,z) Block:destroyBlock(x,y,z,false) end--local function setblock(x,y,z,id) Block:setBlockAll(x,y,z,id,0) endlocal count0repeatlocal x,y,zx0(count/g)-math.floor(g/2),y0,z0math.floor(count%h)-math.floor(h/2)for i-1,2 do destroyblock(x,yi,z) endif math.floor(count%h)0 or math.floor(count%h)h-1 or math.floor(count/g)0 or math.floor(count/g)g-1 thensetblock(x,y-1,z,15)setblock(x,y,z,500)setblock(x,y1,z,15)setblock(x,y2,z,500)elseif math.floor(count%h)1 or math.floor(count%h)h-2 or math.floor(count/g)1 or math.floor(count/g)g-2 thensetblock(x,y-1,z,15)elsesetblock(x,y-1,z,(math.floor((math.floor(math.floor((count%h)-2)/s))math.floor(math.floor((count/g)-2)/s))%2674))endcountcount1if count%999999 then self:ThreadWait(0.1) enduntil countg*hend--[[local function chack4()local chacknum{}for i,v in ipairs(tabl) dofor j,k in ipairs(v) doif k1 thenchacknum[#chacknum1]{xi,zj}endendendprint(chacknum)return chacknumend]]local function chack3(color3,tbl,xmin,xmax,zmin,zmax,xend,zend)local function chack0(i,j)tbl[i][j]0for k,v in pairs(row) doif iv[1]xmin and iv[1]xmax and jv[2]zmin and jv[2]zmax thenif tbl[iv[1]][jv[2]]1 thenchack0(iv[1],jv[2])endendendendfor ixmin,xmax doif tbl[i][zmin]1 thenchack0(i,zmin)endif tbl[i][zmax]1 thenchack0(i,zmax)endendprint(上下边)for jzmin,zmax doif tbl[xmin][j]1 thenchack0(xmin,j)endif tbl[xmax][j]1 thenchack0(xmax,j)endendprint(左右边)print(tbl)for i,v0 in pairs(tbl) dofor j,v in pairs(v0) doif v1 thenmap[i][j]color3mapdate[i][j]0threadpool:work(function()destroyblock(i-50,7,j-50)destroyblock(i-50,6,j-50)setblock(i-50,6,j-50,color3667)end)endendendend--框架local function chack1(p,x,z)local xmax,xmin,zmax,zminx,x,z,zlocal chack{}for i,v in ipairs(map) dofor j,k in ipairs(v) doif kPs[p].color then-- chack[#chack1]{i,j}table.insert(chack,{i,j})if ixmax then xmaxi elseif ixmin then xmini endif jzmax then zmaxj elseif jzmin then zminj endendendend--print(map)print(xmin,xmax,zmin,zmax, -(xmin-xmax)1,-(zmin-zmax)1)local tbl{}for ixmin,xmax dotbl[i]{}for jzmin,zmax dotbl[i][j]1endendprint(tbl)print(清重复)for k,v in pairs(chack) do tbl[v[1]][v[2]]0 endprint(tbl)print(绘制区域)chack3(Ps[p].color,tbl,xmin,xmax,zmin,zmax-(xmin-xmax)1,-(zmin-zmax)1)end--threadpool:work(function() touchwall(p,s) end)--玩家移动local function moveadd(p,x,y,z)local PPs[p]local x0,z0x50,z50print(移动)print(x, z)if map[x0][z0]P.color thenprint(回到原位)if mapdate[x0][z0]~P.color thenmapdate[x0][z0]0destroyblock(x,y,z)endif P.num0 thenprint(吃轨迹)print(P.date)for k,v in pairs(P.date) doif mapdate[v.x][v.z]P.color thenmap[v.x][v.z]P.colormapdate[v.x][v.z]0destroyblock(v.x-50,y,v.z-50)setblock(v.x-50,y-1,v.z-50,P.color667)endendP.num,P.date0,{}print(吃闭合)chack1(p,x0,z0)print(优化完成)endelseif map[x0][z0]~P.color and mapdate[x0][z0]~P.color then-- print(累计)P.numP.num1mapdate[x0][z0]P.colortable.insert(P.date,{xx0,zz0})-- print(p,P.num,累计)--print(破坏脚下地毯)destroyblock(x,y,z,false)--print(生成地毯)setblock(x,y,z,P.color616)endendfunction Script: move(p)local isExist Actor:IsExist(p)if not(isExist) then return endlocal x,y,zActor:GetPosition(p)print(移动)local x,y,zmath.floor(x),7,math.floor(z)if x49 or x-49 or z49 or z-49 thenif x~Ps[p].x or z~Ps[p].z thenPs[p].x,Ps[p].zx,z--print(移动,x50,z50)threadpool:work(function() moveadd(p,x,y,z) end)endendself:ThreadWait(0.1)self:move(p)endlocal function Block_DestroyBy(param)local result,idBlock:getBlockID(param.x,param.y-1,param.z)if param.blockid-616~id-667 thenlocal pplayid[param.blockid-616]if p0 then return endlocal PPs[p]if P.num0 thenfor k,v in pairs(P.data) doif mapdata[v.x][v.z]P.color thenmapdata[v.x][v.z]0destroyblock(v.x-50,y,v.z-50)endendP.num,P.data0,{}endendend-- 组件启动时初始化背包UIfunction Script:OnStart()--self:AddTriggerEvent(TriggerEvent.PlayerInputKeyClick, self.OnKeyClick)--self:AddTriggerEvent(TriggerEvent.PlayerClickBlock, self.OnPlayerClickBlock)-- 监听UI按钮点击事件--self:AddTriggerEvent(TriggerEvent.UIButtonClick, self.OnUIButtonClick)self:Game_StartGame(g4,h4)self:AddTriggerEvent(TriggerEvent.GameAnyPlayerLeaveGame,self.GameAnyPlayerLeaveGame)self:AddTriggerEvent(TriggerEvent.GameAnyPlayerEnterGame,self.GameAnyPlayerEnterGame)self:AddTriggerEvent(TriggerEvent.BlockRemove,self.Blockremove)endfunction Script:GameAnyPlayerLeaveGame(e) threadpool:work(function() self:deui(e) end) endfunction Script:deui(e) pe.CurEventParam.TriggerByPlayerplayid[Ps[p].color]0local leavecolorPs[p].colorPs[p]nilremap(leavecolor)endfunction Script:GameAnyPlayerEnterGame(e) threadpool:work(function() self:upui(e) end)endfunction Script:upui(e) print(123, e) local pe.CurEventParam.TriggerByPlayerprint(e)-- 获取玩家昵称local nickname Actor:GetNickName(Player:GetHostUin())local entercolorscolor0(p)Ps[p]{[date]{},[dates]{},[num]0,[nums]0,[color]entercolors,[player]p,[name]nickname,[run]0,[gameover]0,[iconid]nil,}print(Ps)Chat:SendSystemMsg(欢迎玩家: ..nickname..--围墙大作战\n--韩永旗\n--星空露珠工作室制作\n--借鉴圈圈大作战领土模式)add(p)self:ThreadWait(0.2)print(移动)self:move(p)endreturn Script