--加入触摸
function game:chumo()
-- body
local colorLayer=display.newColorLayer(ccc4(23,222,21,0))
self:addChild(colorLayer, 0)
-- 触摸事件
colorLayer:setTouchSwallowEnabled(true)
colorLayer:setTouchEnabled(true)
colorLayer:setTouchMode(cc.TOUCH_MODE_ONE_BY_ONE)
--cc.TOUCH_MODE_ALL_AT_ONCE 是多点触摸
--注册触摸事件
colorLayer:addNodeEventListener(cc.NODE_TOUCH_EVENT, function(event)
        local  movee=true 
   if event.name == "began" then
print("beganMask")
return true
   elseif event.name == "moved" then
            movee=false 
local x1 = event.x
print(x1)
local y1 = event.y
local x2 = event.prevX
local y2 = event.prevY
print(x2)
local x = x1 - x2
local y = y1 - y2
if xiaobing:getPositionX() + x > 10 and xiaobing:getPositionX() + x <480 and xiaobing:getPositionY() + y > 0 and xiaobing:getPositionY() + y < 300 then
xiaobing:setPosition(ccp(xiaobing:getPositionX() + x, xiaobing:getPositionY() + y))
end
elseif event.name == "ended" then
            if  movee  then 
              self:addBullet()


                for k,v  in pairs(Bulletarray) do 
            --local aa=ccp(event.x, event.y)
               local aa=ccp(event.x-xiaobing:getPositionX(),event.y-xiaobing:getPositionY())
               local  movest=CCMoveBy:create(2,aa)
                    local foreverstt=CCRepeatForever:create(movest)
               v:runAction(foreverstt)
                end
            end
   return true
end
   return false
end)
end
 -------------------------------------以下是新的更新jason数据的----------------------------------------------
function write_content( fileName,content )
  local f = assert(io.open(fileName, 'w'))
  f:write(content)
  f:close()
end


function getFile(file_name)
  print(file_name)
  local f = assert(io.open(file_name, 'r'))
  local string = f:read("*all")
  f:close()
  return string
end


function serialize(obj)  
    local lua = ""  
    local t = type(obj)  
    if t == "number" then  
        lua = lua .. obj  
    elseif t == "boolean" then  
        lua = lua .. tostring(obj)  
    elseif t == "string" then  
        lua = lua .. string.format("%q", obj)  
    elseif t == "table" then  
        lua = lua .. "{\n"  
    for k, v in pairs(obj) do  
        lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n"  
    end  
    local metatable = getmetatable(obj)  
        if metatable ~= nil and type(metatable.__index) == "table" then  
        for k, v in pairs(metatable.__index) do  
            lua = lua .. "[" .. serialize(k) .. "]=" .. serialize(v) .. ",\n"  
        end  
    end  
        lua = lua .. "}"  
    elseif t == "nil" then  
        return nil  
    else  
        error("can not serialize a " .. t .. " type.")  
    end  
    return lua  
end  
function unserialize(lua)  
    local t = type(lua)  
    if t == "nil" or lua == "" then  
        return nil  
    elseif t == "number" or t == "string" or t == "boolean" then  
        lua = tostring(lua)  
    else  
        error("can not unserialize a " .. t .. " type.")  
    end  
    lua = "return " .. lua  
    local func = loadstring(lua)  
    if func == nil then  
        return nil  
    end  
    return func()  
end  
function game:filecopy1(source,destination)
     local stt=getFile(source)
     write_content(destination,stt)
end


function game:JasonParseChapter(Chapternumber)
   -------------------------文件拷贝开始-------------------------
   CCFileUtils:sharedFileUtils():addSearchPath("res/")
   local  number=Chapternumber
   local filename="chapter1.txt"
   print(filename)
   local  path = CCFileUtils:sharedFileUtils():fullPathForFilename(filename)
   print(path)
   print("已经打印路径了")
   local  nowpath=CCFileUtils:sharedFileUtils():getWritablePath()
      destination=nowpath ..filename
    --"chapter1.txt"
   if io.exists(destination)  then 
    print("这个文件是存在的")
   else
    print("这个文件是不存在的,快快执行拷贝吧")
    print(path)
    print("上面是当前地址")
    print(destination)
    print("上面是目的地址")
    self:filecopy1(path,destination)
    print("执行拷贝完成,快去看看吧")
   end
   ------------------------文件拷贝结束-------------------------
   ------------------------文件拷贝完成,成功后进行解析-----------
    --解析关卡表的数值


       local chapter_str=getFile(destination)


        self.chapter_table = unserialize(chapter_str)
        chapter={}
        for k,v in pairs(self.chapter_table) do
        if k == "Level_1" then
       chapter.Level_1={}
       chapter.Level_1.LevelNumber=v.LevelNumber
       print("我要看看这个数的格式")


      chapter.Level_1.Unlock=v.Unlock
      chapter.Level_1.starNumber=v.starNumber

      chapter.Level_1.HighestScore=v.HighestScore

}