小游戏 1to 50
来源:互联网 发布:android 创建数据库 编辑:程序博客网 时间:2024/05/18 02:43
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
0 0
- 小游戏 1to 50
- 安卓猜数字小游戏1
- Android挂机小游戏1
- UEFI (1)-小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- 小游戏
- iOS手机淘宝加入购物车动画分析
- 【机房系统个人重构】跌跌撞撞也好,开始前进!
- ORA-00314;ORA-00312
- android 网络连接
- 如何用 OS X 的 Xcode 写C语言程序
- 小游戏 1to 50
- leetcoode 3.Longest Substring Without Repeating Characters
- 监听RecyclerView滑动到末端
- 初识 C#
- leetcode83题 题解 翻译 C语言版 Python版
- Binding MySql DataSources in Jboss EAP 7.0
- “Genymotion运行Android模拟器一直卡在开机界面”的解决办法
- 于是就来到第三节_(:зゝ∠)_运算符重载
- html5