local MyButton = require("app.layer.MyButton")
local gameWin = require("app.layer.gameWin")
local gamelost = require("app.layer.gamelost")
local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
local GameLayer = class("GameLayer", function()
return display.newColorLayer(cc.c4b(0,0,0,255))
end)
function GameLayer:ctor()
self.tiemLab = cc.ui.UILabel.new({
UILabelType = 2, text = "00:00", size = 30})
:align(display.CENTER, display.cx, display.cy + 300)
:addTo(self)
self:setNodeEventEnabled(true)
self.data = {}
self.data2 = {}
self.isEnd = false
self.time = 0
local button = cc.ui.UIPushButton.new({} )
button:setButtonLabel(cc.ui.UILabel.new({
UILabelType = 2, text = "返回", size = 30}))
button:setPosition(display.width - 30,display.height - 50)
self:addChild(button)
button:onButtonClicked(handler(self, self.buttonCallback))
local button = cc.ui.UIPushButton.new({} )
button:setButtonLabel(cc.ui.UILabel.new({
UILabelType = 2, text = "开始", size = 30}))
button:setPosition(30,display.height - 50)
self:addChild(button)
button:onButtonClicked(handler(self, self.buttonBegin))
end
function GameLayer:buttonBegin()
local num = tostring(os.time()):reverse():sub(1, 6)
print(num)
print(tostring(os.time()):reverse())
math.randomseed(num)
for i = 1 , 10000 do
local num = math.random(1,25)
-- print(num)
self.data[#self.data + 1] = num
for k = 1 , #self.data -1 do
if num == self.data[k] then
table.remove(self.data)
break
end
end
if #self.data >= 25 then
break
end
end
for i = 1 , 10000 do
local num = math.random(26,50)
-- print(num)
self.data2[#self.data2 + 1] = num
for k = 1 , #self.data2 -1 do
if num == self.data2[k] then
table.remove(self.data2)
break
end
end
if #self.data2 >= 25 then
break
end
end
local MyButton = MyButton.new(self.data , 1 , handler(self, self.updataCallback))
self:addChild(MyButton)
MyButton:setPosition(0, 0)
self.buttonlayer = MyButton
self.Schedule = scheduler.scheduleGlobal(handler(self, self.updataLabel),0.1)
end
function GameLayer:updataLabel()
self.time = self.time + 0.1
local str = self:getTimeStringBySeconds(self.time)
self.tiemLab:setString(str)
end
function GameLayer:getTimeStringBySeconds(_second)
_second = _second or 0
local day = math.floor( _second/ (3600 * 24) )
_second = _second % (3600 * 24)
local hour = math.floor( _second / 3600 )
_second = _second % 3600
local min = math.floor( _second / 60 )
_second = _second % 60
local sec = _second
local timeStr = string.format("%.2d:%.2d:%.2d",hour,min,sec)
if day and day > 0 then
timeStr = string.format("%dd ",day) .. timeStr
end
return timeStr
end
function GameLayer:buttonCallback()
self:removeFromParent()
end
function GameLayer:updataCallback()
if self.isEnd then
local layer = gameWin.new(self.time)
display.getRunningScene():addChild(layer)
self:removeFromParent()
end
if self.buttonlayer then
self.buttonlayer:removeFromParent()
local MyButton = MyButton.new(self.data2 , 26 ,handler(self, self.updataCallback))
self:addChild(MyButton)
MyButton:setPosition(0, 0)
self.buttonlayer = MyButton
self.isEnd = true
end
end
function GameLayer:onEnter()
end
function GameLayer:onExit()
end
function GameLayer:onCleanup()
if self.Schedule then
scheduler.unscheduleGlobal(self.Schedule)
self.Schedule = nil
end
end
return GameLayer
local gameWin = require("app.layer.gameWin")
local gamelost = require("app.layer.gamelost")
local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")
local GameLayer = class("GameLayer", function()
return display.newColorLayer(cc.c4b(0,0,0,255))
end)
function GameLayer:ctor()
self.tiemLab = cc.ui.UILabel.new({
UILabelType = 2, text = "00:00", size = 30})
:align(display.CENTER, display.cx, display.cy + 300)
:addTo(self)
self:setNodeEventEnabled(true)
self.data = {}
self.data2 = {}
self.isEnd = false
self.time = 0
local button = cc.ui.UIPushButton.new({} )
button:setButtonLabel(cc.ui.UILabel.new({
UILabelType = 2, text = "返回", size = 30}))
button:setPosition(display.width - 30,display.height - 50)
self:addChild(button)
button:onButtonClicked(handler(self, self.buttonCallback))
local button = cc.ui.UIPushButton.new({} )
button:setButtonLabel(cc.ui.UILabel.new({
UILabelType = 2, text = "开始", size = 30}))
button:setPosition(30,display.height - 50)
self:addChild(button)
button:onButtonClicked(handler(self, self.buttonBegin))
end
function GameLayer:buttonBegin()
local num = tostring(os.time()):reverse():sub(1, 6)
print(num)
print(tostring(os.time()):reverse())
math.randomseed(num)
for i = 1 , 10000 do
local num = math.random(1,25)
-- print(num)
self.data[#self.data + 1] = num
for k = 1 , #self.data -1 do
if num == self.data[k] then
table.remove(self.data)
break
end
end
if #self.data >= 25 then
break
end
end
for i = 1 , 10000 do
local num = math.random(26,50)
-- print(num)
self.data2[#self.data2 + 1] = num
for k = 1 , #self.data2 -1 do
if num == self.data2[k] then
table.remove(self.data2)
break
end
end
if #self.data2 >= 25 then
break
end
end
local MyButton = MyButton.new(self.data , 1 , handler(self, self.updataCallback))
self:addChild(MyButton)
MyButton:setPosition(0, 0)
self.buttonlayer = MyButton
self.Schedule = scheduler.scheduleGlobal(handler(self, self.updataLabel),0.1)
end
function GameLayer:updataLabel()
self.time = self.time + 0.1
local str = self:getTimeStringBySeconds(self.time)
self.tiemLab:setString(str)
end
function GameLayer:getTimeStringBySeconds(_second)
_second = _second or 0
local day = math.floor( _second/ (3600 * 24) )
_second = _second % (3600 * 24)
local hour = math.floor( _second / 3600 )
_second = _second % 3600
local min = math.floor( _second / 60 )
_second = _second % 60
local sec = _second
local timeStr = string.format("%.2d:%.2d:%.2d",hour,min,sec)
if day and day > 0 then
timeStr = string.format("%dd ",day) .. timeStr
end
return timeStr
end
function GameLayer:buttonCallback()
self:removeFromParent()
end
function GameLayer:updataCallback()
if self.isEnd then
local layer = gameWin.new(self.time)
display.getRunningScene():addChild(layer)
self:removeFromParent()
end
if self.buttonlayer then
self.buttonlayer:removeFromParent()
local MyButton = MyButton.new(self.data2 , 26 ,handler(self, self.updataCallback))
self:addChild(MyButton)
MyButton:setPosition(0, 0)
self.buttonlayer = MyButton
self.isEnd = true
end
end
function GameLayer:onEnter()
end
function GameLayer:onExit()
end
function GameLayer:onCleanup()
if self.Schedule then
scheduler.unscheduleGlobal(self.Schedule)
self.Schedule = nil
end
end
return GameLayer