标签:
1 _Account = {} 2 3 --创建一张借记卡 4 function _Account:new( tb ) 5 local _Tb = tb or {} 6 _Tb._mBalance = _Tb._mBalance or 0 7 setmetatable(_Tb, self) 8 self.__index = self 9 return _Tb 10 end 11 12 --借记卡取款 13 function _Account:desposit( value ) 14 if value > self._mBalance then 15 print("insufficient funds!") 16 return 17 end 18 self._mBalance = self._mBalance - value 19 print(string.format("You Get %s Money!", value)) 20 end 21 22 --存钱 23 function _Account:addBalance(val) 24 local num = val or 0 25 self._mBalance = self._mBalance + num 26 end 27 28 local myAccount_2 = myAccount:new() 29 myAccount_2:addBalance(1000) 30 myAccount_2:desposit(200) 31 32 ------------------------------------------------------- 33 _Credit = _Account:new({_mLimit = 1000}) 34 35 --信用卡取款 36 function _Credit:desposit( value ) 37 if value > self._mBalance + self._mLimit then 38 print("insufficient funds!") 39 return 40 end 41 self._mBalance = self._mBalance - value 42 print(string.format("You Get:%s Money", value)) 43 end 44 45 local cyCredit = _Credit:new() 46 cyCredit:desposit(500)
标签:
原文地址:http://www.cnblogs.com/wrbxdj/p/5379897.html