0基础lua学习(二十)Lua单例



代码如下:


local GameLogic = {}


function GameLogic:new(o)  
    o = o or {}  
    setmetatable(o,self)  
    self.__index = self  
    return o  
end  

function GameLogic:Instance()  
    if self.instance == nil then  
        self.instance = self:new()  
    end  
    print(self.instance)
    return self.instance  
end 


function GameLogic:init()
    self.v_gezi = {}
    zs1 = {}
	zs1.fenshu = 15
	zs1.zhuid = 4  
	self.v_gezi[1] = zs1

    zs2 = {}
	zs2.fenshu = 50
	zs2.zhuid = 8
	self.v_gezi[2] =zs2

end
function GameLogic:getRandPro()
    return 2
end
function GameLogic:getluckPro(gold)
    return 10
end




return GameLogic


你可能感兴趣的:(#,[,Lua,])