├── README.md ├── res ├── background.caf ├── background.mp3 ├── background.ogg ├── card │ └── pic │ │ ├── a1_10.png │ │ ├── a1_11.png │ │ ├── a1_12.png │ │ ├── a1_13.png │ │ ├── a1_14.png │ │ ├── a1_15.png │ │ ├── a1_3.png │ │ ├── a1_4.png │ │ ├── a1_5.png │ │ ├── a1_6.png │ │ ├── a1_7.png │ │ ├── a1_8.png │ │ ├── a1_9.png │ │ ├── a2_10.png │ │ ├── a2_11.png │ │ ├── a2_12.png │ │ ├── a2_13.png │ │ ├── a2_14.png │ │ ├── a2_15.png │ │ ├── a2_3.png │ │ ├── a2_4.png │ │ ├── a2_5.png │ │ ├── a2_6.png │ │ ├── a2_7.png │ │ ├── a2_8.png │ │ ├── a2_9.png │ │ ├── a3_10.png │ │ ├── a3_11.png │ │ ├── a3_12.png │ │ ├── a3_13.png │ │ ├── a3_14.png │ │ ├── a3_15.png │ │ ├── a3_3.png │ │ ├── a3_4.png │ │ ├── a3_5.png │ │ ├── a3_6.png │ │ ├── a3_7.png │ │ ├── a3_8.png │ │ ├── a3_9.png │ │ ├── a4_10.png │ │ ├── a4_11.png │ │ ├── a4_12.png │ │ ├── a4_13.png │ │ ├── a4_14.png │ │ ├── a4_15.png │ │ ├── a4_3.png │ │ ├── a4_4.png │ │ ├── a4_5.png │ │ ├── a4_6.png │ │ ├── a4_7.png │ │ ├── a4_8.png │ │ ├── a4_9.png │ │ ├── a5_16.png │ │ ├── a5_17.png │ │ ├── bg.png │ │ ├── cardbg1.png │ │ └── menu │ │ ├── menu_item_end_disabled.png │ │ ├── menu_item_end_normal.png │ │ ├── menu_item_end_selected.png │ │ ├── menu_item_pause_disabled.png │ │ ├── menu_item_pause_normal.png │ │ ├── menu_item_pause_selected.png │ │ ├── menu_item_start_disabled.png │ │ ├── menu_item_start_normal.png │ │ └── menu_item_start_selected.png ├── crop.png ├── dog.png ├── effect1.wav ├── farm.jpg ├── fonts │ └── Marker Felt.ttf ├── land.png ├── menu1.png └── menu2.png └── src ├── CardScene.lua ├── GameScene.lua ├── LordCardScene.lua ├── TestScene.lua ├── TexasHoldemPokerScene.lua ├── ender ├── init.lua ├── test │ ├── TestCase.lua │ └── utils │ │ ├── ArrayUtilTest.lua │ │ └── StringUtilTest.lua └── utils │ ├── ArrayUtil.lua │ ├── AudioUtil.lua │ ├── CCDirectorUtil.lua │ ├── CCLayerUtil.lua │ ├── CCMenuUtil.lua │ ├── CCNodeUtil.lua │ ├── CCSceneUtil.lua │ ├── CCSpriteUtil.lua │ ├── ColorUtil.lua │ ├── EventUtil.lua │ └── StringUtil.lua ├── game └── entity │ ├── Card.lua │ └── init.lua └── main.lua /README.md: -------------------------------------------------------------------------------- 1 | StudyCocosLuaGame 2 | ================= 3 | 4 | 学习cocos2d-x lua游戏编程 5 | 6 | 本工程旨在学习cocos2d-x lua游戏编程的基本知识,完成一些列框架工具的搭建 7 | 8 | 工具类放置在文件目录"ender/utils"下面 9 | 测试框架放置在文件目录"ender/test"下面 10 | -------------------------------------------------------------------------------- /res/background.caf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/background.caf -------------------------------------------------------------------------------- /res/background.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/background.mp3 -------------------------------------------------------------------------------- /res/background.ogg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/background.ogg -------------------------------------------------------------------------------- /res/card/pic/a1_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_10.png -------------------------------------------------------------------------------- /res/card/pic/a1_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_11.png -------------------------------------------------------------------------------- /res/card/pic/a1_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_12.png -------------------------------------------------------------------------------- /res/card/pic/a1_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_13.png -------------------------------------------------------------------------------- /res/card/pic/a1_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_14.png -------------------------------------------------------------------------------- /res/card/pic/a1_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_15.png -------------------------------------------------------------------------------- /res/card/pic/a1_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_3.png -------------------------------------------------------------------------------- /res/card/pic/a1_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_4.png -------------------------------------------------------------------------------- /res/card/pic/a1_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_5.png -------------------------------------------------------------------------------- /res/card/pic/a1_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_6.png -------------------------------------------------------------------------------- /res/card/pic/a1_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_7.png -------------------------------------------------------------------------------- /res/card/pic/a1_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_8.png -------------------------------------------------------------------------------- /res/card/pic/a1_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a1_9.png -------------------------------------------------------------------------------- /res/card/pic/a2_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_10.png -------------------------------------------------------------------------------- /res/card/pic/a2_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_11.png -------------------------------------------------------------------------------- /res/card/pic/a2_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_12.png -------------------------------------------------------------------------------- /res/card/pic/a2_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_13.png -------------------------------------------------------------------------------- /res/card/pic/a2_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_14.png -------------------------------------------------------------------------------- /res/card/pic/a2_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_15.png -------------------------------------------------------------------------------- /res/card/pic/a2_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_3.png -------------------------------------------------------------------------------- /res/card/pic/a2_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_4.png -------------------------------------------------------------------------------- /res/card/pic/a2_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_5.png -------------------------------------------------------------------------------- /res/card/pic/a2_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_6.png -------------------------------------------------------------------------------- /res/card/pic/a2_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_7.png -------------------------------------------------------------------------------- /res/card/pic/a2_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_8.png -------------------------------------------------------------------------------- /res/card/pic/a2_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a2_9.png -------------------------------------------------------------------------------- /res/card/pic/a3_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_10.png -------------------------------------------------------------------------------- /res/card/pic/a3_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_11.png -------------------------------------------------------------------------------- /res/card/pic/a3_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_12.png -------------------------------------------------------------------------------- /res/card/pic/a3_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_13.png -------------------------------------------------------------------------------- /res/card/pic/a3_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_14.png -------------------------------------------------------------------------------- /res/card/pic/a3_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_15.png -------------------------------------------------------------------------------- /res/card/pic/a3_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_3.png -------------------------------------------------------------------------------- /res/card/pic/a3_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_4.png -------------------------------------------------------------------------------- /res/card/pic/a3_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_5.png -------------------------------------------------------------------------------- /res/card/pic/a3_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_6.png -------------------------------------------------------------------------------- /res/card/pic/a3_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_7.png -------------------------------------------------------------------------------- /res/card/pic/a3_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_8.png -------------------------------------------------------------------------------- /res/card/pic/a3_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a3_9.png -------------------------------------------------------------------------------- /res/card/pic/a4_10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_10.png -------------------------------------------------------------------------------- /res/card/pic/a4_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_11.png -------------------------------------------------------------------------------- /res/card/pic/a4_12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_12.png -------------------------------------------------------------------------------- /res/card/pic/a4_13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_13.png -------------------------------------------------------------------------------- /res/card/pic/a4_14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_14.png -------------------------------------------------------------------------------- /res/card/pic/a4_15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_15.png -------------------------------------------------------------------------------- /res/card/pic/a4_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_3.png -------------------------------------------------------------------------------- /res/card/pic/a4_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_4.png -------------------------------------------------------------------------------- /res/card/pic/a4_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_5.png -------------------------------------------------------------------------------- /res/card/pic/a4_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_6.png -------------------------------------------------------------------------------- /res/card/pic/a4_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_7.png -------------------------------------------------------------------------------- /res/card/pic/a4_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_8.png -------------------------------------------------------------------------------- /res/card/pic/a4_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a4_9.png -------------------------------------------------------------------------------- /res/card/pic/a5_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a5_16.png -------------------------------------------------------------------------------- /res/card/pic/a5_17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/a5_17.png -------------------------------------------------------------------------------- /res/card/pic/bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/bg.png -------------------------------------------------------------------------------- /res/card/pic/cardbg1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/cardbg1.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_end_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_end_disabled.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_end_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_end_normal.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_end_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_end_selected.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_pause_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_pause_disabled.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_pause_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_pause_normal.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_pause_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_pause_selected.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_start_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_start_disabled.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_start_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_start_normal.png -------------------------------------------------------------------------------- /res/card/pic/menu/menu_item_start_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/card/pic/menu/menu_item_start_selected.png -------------------------------------------------------------------------------- /res/crop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/crop.png -------------------------------------------------------------------------------- /res/dog.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/dog.png -------------------------------------------------------------------------------- /res/effect1.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/effect1.wav -------------------------------------------------------------------------------- /res/farm.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/farm.jpg -------------------------------------------------------------------------------- /res/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /res/land.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/land.png -------------------------------------------------------------------------------- /res/menu1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/menu1.png -------------------------------------------------------------------------------- /res/menu2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Veon8o8/StudyCocosLuaGame/499f87d6d13acdd08cf58781bb03d8f96df16ea3/res/menu2.png -------------------------------------------------------------------------------- /src/CardScene.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 菜单场景(局部变量). 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module CardScene 10 | local CardScene = class("CardScene",function() 11 | return cc.Scene:create() 12 | end); 13 | 14 | function CardScene.create() 15 | local scene = CardScene.new() 16 | scene:addChild(scene:createlayerTable()); 17 | scene:addChild(scene:createLayerMenu()); 18 | return scene; 19 | end 20 | 21 | 22 | function CardScene:ctor() 23 | self.visibleSize = cc.Director:getInstance():getVisibleSize(); 24 | self.origin = cc.Director:getInstance():getVisibleOrigin(); 25 | self.schedulerID = nil; 26 | end 27 | 28 | function CardScene:playBgMusic() 29 | local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3"); 30 | cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true); 31 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav"); 32 | cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath); 33 | end 34 | 35 | -- create farm 36 | function CardScene:createlayerTable() 37 | local layerTable = cc.Layer:create() 38 | 39 | -- 屏幕中心 40 | local location = { 41 | x = self.origin.x + self.visibleSize.width / 2, 42 | y = self.origin.y + self.visibleSize.height / 2 43 | }; 44 | 45 | -- 添加牌桌背景 46 | local bg = cc.Sprite:create("card/pic/bg.png"); 47 | -- 总是放置的中心位置, Cocos总是以左下角为坐标原点 48 | bg:setPosition(location.x, location.y); 49 | print("背景宽度: " .. bg:getTexture():getPixelsWide()) 50 | print("背景高度: " .. bg:getTexture():getPixelsHigh()) 51 | layerTable:addChild(bg) 52 | 53 | -- 将所有的牌铺在桌面上(1: 梅花, 2: 方片, 3: 红心, 4: 黑桃, 5: 大小王) 54 | local startX = 60 55 | local startY = 200 56 | for i = 1, 5 do 57 | for j = 3, 17 do 58 | if (i < 5 and j < 16) or (i >= 5 and j >= 16) then 59 | local card = cc.Sprite:create("card/pic/a" .. i .. "_" .. j .. ".png") 60 | card:setPosition(startX + (j - 3) * 60, startY + (i - 1) * 80) 61 | layerTable:addChild(card) 62 | end 63 | end 64 | end 65 | 66 | return layerTable 67 | end 68 | 69 | -- create menu 70 | function CardScene:createLayerMenu() 71 | 72 | local layerMenu = cc.Layer:create(); 73 | 74 | -- 屏幕中心 75 | local location = { 76 | x = self.origin.x + self.visibleSize.width / 2, 77 | y = self.origin.y + self.visibleSize.height / 2 78 | }; 79 | 80 | local color = ColorUtil.createFromInt(0xFFFF00); 81 | 82 | 83 | -- 创建一个文字菜单 84 | local startMenuItemLocation = { 85 | x = location.x, 86 | y = location.y + 280 + 40 87 | }; 88 | local pauseMenuItemLocation = { 89 | x = location.x, 90 | y = location.y + 280 91 | }; 92 | local endMenuItemLocation = { 93 | x = location.x, 94 | y = location.y + 280 - 40 95 | }; 96 | function startMenuItemCallback(sender) 97 | print("点击了文字斗地主"); 98 | -- 场景切换 99 | -- local trasitionScene = CCSceneUtil.getTransition(CCSceneUtil.CROSS_FADE, "LordCardScene", 1); 100 | local trasitionScene = CCSceneUtil.getTransition(CCSceneUtil.FADE, "LordCardScene", 1); 101 | CCDirectorUtil.gotoScene(trasitionScene); 102 | end 103 | function pauseMenuItemCallback(sender) 104 | print("点击了文字暂停"); 105 | end 106 | function endMenuItemCallback(sender) 107 | print("点击了文字结束"); 108 | end 109 | 110 | local startMenuItem = CCMenuUtil.createMenuItemFont( 111 | "斗地主", color, startMenuItemLocation, startMenuItemCallback); 112 | local pauseMenuItem = CCMenuUtil.createMenuItemFont( 113 | "暂停", color, pauseMenuItemLocation, pauseMenuItemCallback); 114 | local endMenuItem = CCMenuUtil.createMenuItemFont( 115 | "结束", color, endMenuItemLocation, endMenuItemCallback); 116 | 117 | layerMenu:addChild(CCMenuUtil.createMenu({x=0,y=0}, startMenuItem, pauseMenuItem, endMenuItem)); 118 | 119 | 120 | -- 创建一个Sprite菜单 121 | local startMenuItemLocation1 = { 122 | x = location.x - 480, 123 | y = location.y + 280 + 42 124 | }; 125 | local pauseMenuItemLocation1 = { 126 | x = location.x - 480, 127 | y = location.y + 280 128 | }; 129 | local endMenuItemLocation1 = { 130 | x = location.x - 480, 131 | y = location.y + 280 - 42 132 | }; 133 | function startMenuItemCallback1(sender) 134 | print("点击了文字开始"); 135 | end 136 | function pauseMenuItemCallback1(sender) 137 | print("点击了文字暂停"); 138 | end 139 | function endMenuItemCallback1(sender) 140 | print("点击了文字结束"); 141 | end 142 | 143 | local startMenuItem1 = CCMenuUtil.createMenuItemSprite( 144 | "card/pic/menu/menu_item_start", color, startMenuItemLocation1, startMenuItemCallback1); 145 | local pauseMenuItem1 = CCMenuUtil.createMenuItemSprite( 146 | "card/pic/menu/menu_item_pause", color, pauseMenuItemLocation1, pauseMenuItemCallback1); 147 | local endMenuItem1 = CCMenuUtil.createMenuItemSprite( 148 | "card/pic/menu/menu_item_end", color, endMenuItemLocation1, endMenuItemCallback1); 149 | 150 | layerMenu:addChild(CCMenuUtil.createMenu({x=0,y=0}, startMenuItem1, pauseMenuItem1, endMenuItem1)); 151 | 152 | 153 | -- 创建一个Image菜单 154 | local startMenuItemLocation2 = { 155 | x = location.x - 280, 156 | y = location.y + 280 + 42 157 | }; 158 | local pauseMenuItemLocation2 = { 159 | x = location.x - 280, 160 | y = location.y + 280 161 | }; 162 | local endMenuItemLocation2 = { 163 | x = location.x - 280, 164 | y = location.y + 280 - 42 165 | }; 166 | function startMenuItemCallback2(sender) 167 | print("点击了文字开始"); 168 | end 169 | function pauseMenuItemCallback2(sender) 170 | print("点击了文字暂停"); 171 | end 172 | function endMenuItemCallback2(sender) 173 | print("点击了文字结束"); 174 | end 175 | 176 | local startMenuItem2 = CCMenuUtil.createMenuItemSprite( 177 | "card/pic/menu/menu_item_start", color, startMenuItemLocation2, startMenuItemCallback2); 178 | local pauseMenuItem2 = CCMenuUtil.createMenuItemSprite( 179 | "card/pic/menu/menu_item_pause", color, pauseMenuItemLocation2, pauseMenuItemCallback2); 180 | local endMenuItem2 = CCMenuUtil.createMenuItemSprite( 181 | "card/pic/menu/menu_item_end", color, endMenuItemLocation2, endMenuItemCallback2); 182 | 183 | layerMenu:addChild(CCMenuUtil.createMenu({x=0,y=0}, startMenuItem2, pauseMenuItem2, endMenuItem2)); 184 | 185 | return layerMenu 186 | end 187 | 188 | return CardScene; 189 | -------------------------------------------------------------------------------- /src/GameScene.lua: -------------------------------------------------------------------------------- 1 | 2 | local GameScene = class("GameScene",function() 3 | return cc.Scene:create() 4 | end) 5 | 6 | function GameScene.create() 7 | local scene = GameScene.new() 8 | scene:addChild(scene:createLayerFarm()) 9 | scene:addChild(scene:createLayerMenu()) 10 | return scene 11 | end 12 | 13 | 14 | function GameScene:ctor() 15 | self.visibleSize = cc.Director:getInstance():getVisibleSize() 16 | self.origin = cc.Director:getInstance():getVisibleOrigin() 17 | self.schedulerID = nil 18 | end 19 | 20 | function GameScene:playBgMusic() 21 | local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3") 22 | cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true) 23 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") 24 | cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath) 25 | end 26 | 27 | function GameScene:creatDog() 28 | local frameWidth = 105 29 | local frameHeight = 95 30 | 31 | -- create dog animate 32 | local textureDog = cc.Director:getInstance():getTextureCache():addImage("dog.png") 33 | local rect = cc.rect(0, 0, frameWidth, frameHeight) 34 | local frame0 = cc.SpriteFrame:createWithTexture(textureDog, rect) 35 | rect = cc.rect(frameWidth, 0, frameWidth, frameHeight) 36 | local frame1 = cc.SpriteFrame:createWithTexture(textureDog, rect) 37 | 38 | local spriteDog = cc.Sprite:createWithSpriteFrame(frame0) 39 | spriteDog:setPosition(self.origin.x, self.origin.y + self.visibleSize.height / 4 * 3) 40 | spriteDog.isPaused = false 41 | 42 | local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5) 43 | local animate = cc.Animate:create(animation); 44 | spriteDog:runAction(cc.RepeatForever:create(animate)) 45 | 46 | -- moving dog at every frame 47 | local function tick() 48 | if spriteDog.isPaused then return end 49 | local x, y = spriteDog:getPosition() 50 | if x > self.origin.x + self.visibleSize.width then 51 | x = self.origin.x 52 | else 53 | x = x + 1 54 | end 55 | 56 | spriteDog:setPositionX(x) 57 | end 58 | 59 | self.schedulerID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick, 0, false) 60 | 61 | return spriteDog 62 | end 63 | 64 | -- create farm 65 | function GameScene:createLayerFarm() 66 | local layerFarm = cc.Layer:create() 67 | -- add in farm background 68 | local bg = cc.Sprite:create("farm.jpg") 69 | bg:setPosition(self.origin.x + self.visibleSize.width / 2 + 80, self.origin.y + self.visibleSize.height / 2) 70 | layerFarm:addChild(bg) 71 | 72 | -- add land sprite 73 | for i = 0, 3 do 74 | for j = 0, 1 do 75 | local spriteLand = cc.Sprite:create("land.png") 76 | spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) 77 | layerFarm:addChild(spriteLand) 78 | end 79 | end 80 | 81 | -- add crop 82 | local frameCrop = cc.SpriteFrame:create("crop.png", cc.rect(0, 0, 105, 95)) 83 | for i = 0, 3 do 84 | for j = 0, 1 do 85 | local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop); 86 | spriteCrop:setPosition(210 + j * 180 - i % 2 * 90, 40 + i * 95 / 2) 87 | layerFarm:addChild(spriteCrop) 88 | end 89 | end 90 | 91 | -- add moving dog 92 | local spriteDog = self:creatDog() 93 | layerFarm:addChild(spriteDog) 94 | 95 | -- handing touch events 96 | local touchBeginPoint = nil 97 | local function onTouchBegan(touch, event) 98 | local location = touch:getLocation() 99 | --cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y) 100 | touchBeginPoint = {x = location.x, y = location.y} 101 | spriteDog.isPaused = true 102 | -- CCTOUCHBEGAN event must return true 103 | return true 104 | end 105 | 106 | local function onTouchMoved(touch, event) 107 | local location = touch:getLocation() 108 | --cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y) 109 | if touchBeginPoint then 110 | local cx, cy = layerFarm:getPosition() 111 | layerFarm:setPosition(cx + location.x - touchBeginPoint.x, 112 | cy + location.y - touchBeginPoint.y) 113 | touchBeginPoint = {x = location.x, y = location.y} 114 | end 115 | end 116 | 117 | local function onTouchEnded(touch, event) 118 | local location = touch:getLocation() 119 | --cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y) 120 | touchBeginPoint = nil 121 | spriteDog.isPaused = false 122 | end 123 | 124 | local listener = cc.EventListenerTouchOneByOne:create() 125 | listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) 126 | listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) 127 | listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) 128 | local eventDispatcher = layerFarm:getEventDispatcher() 129 | eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layerFarm) 130 | 131 | local function onNodeEvent(event) 132 | if "exit" == event then 133 | cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.schedulerID) 134 | end 135 | end 136 | layerFarm:registerScriptHandler(onNodeEvent) 137 | 138 | return layerFarm 139 | end 140 | 141 | -- create menu 142 | function GameScene:createLayerMenu() 143 | 144 | local layerMenu = cc.Layer:create() 145 | local menuPopup, menuTools, effectID 146 | 147 | local function menuCallbackClosePopup() 148 | -- stop test sound effect 149 | cc.SimpleAudioEngine:getInstance():stopEffect(effectID) 150 | menuPopup:setVisible(false) 151 | end 152 | 153 | local function menuCallbackOpenPopup() 154 | -- loop test sound effect 155 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") 156 | effectID = cc.SimpleAudioEngine:getInstance():playEffect(effectPath) 157 | menuPopup:setVisible(true) 158 | end 159 | 160 | -- add a popup menu 161 | local menuPopupItem = cc.MenuItemImage:create("menu2.png", "menu2.png") 162 | menuPopupItem:setPosition(0, 0) 163 | menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) 164 | menuPopup = cc.Menu:create(menuPopupItem) 165 | menuPopup:setPosition(self.origin.x + self.visibleSize.width / 2, self.origin.y + self.visibleSize.height / 2) 166 | menuPopup:setVisible(false) 167 | layerMenu:addChild(menuPopup) 168 | 169 | -- add the left-bottom "tools" menu to invoke menuPopup 170 | local menuToolsItem = cc.MenuItemImage:create("menu1.png", "menu1.png") 171 | menuToolsItem:setPosition(0, 0) 172 | menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) 173 | menuTools = cc.Menu:create(menuToolsItem) 174 | local itemWidth = menuToolsItem:getContentSize().width 175 | local itemHeight = menuToolsItem:getContentSize().height 176 | menuTools:setPosition(self.origin.x + itemWidth/2, self.origin.y + itemHeight/2) 177 | layerMenu:addChild(menuTools) 178 | 179 | return layerMenu 180 | end 181 | 182 | return GameScene 183 | -------------------------------------------------------------------------------- /src/LordCardScene.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | -- Ender Utils 6 | require "game.entity.init" 7 | 8 | ------------------------------------------------------------------------------- 9 | -- 斗地主场景(局部变量). 10 | -- 作者: Andrew Yuan
11 | -- 时间: 2014-12-06. 12 | -- @module LordCardScene 13 | local LordCardScene = class("LordCardScene",function() 14 | return cc.Scene:create(); 15 | end) 16 | 17 | -- 本地变量 18 | local layerTable; 19 | -- 牌对象, 使用table进行存储. 20 | local card = {}; 21 | -- 图片资源 22 | local cardBitmap = {}; 23 | 24 | ------------------------------------------------------------------------------- 25 | -- 创建斗地主游戏场景, 包含牌桌和菜单. 26 | -- @function [parent=#LordCardScene] create 27 | -- @return #LordCardScene 28 | function LordCardScene.create() 29 | initBitmap(); 30 | local scene = LordCardScene.new(); 31 | scene:addChild(scene:createlayerTable()); 32 | scene:addChild(scene:createLayerMenu()); 33 | return scene; 34 | end 35 | 36 | ------------------------------------------------------------------------------- 37 | -- 创建斗地主游戏场景, 包含牌桌和菜单. 38 | -- @function [parent=#LordCardScene] create 39 | -- @return #LordCardScene 40 | function initBitmap() 41 | print("初始化精灵对象"); 42 | local count = 0; 43 | for i = 1, 4 do 44 | for j = 3, 15 do 45 | -- 根据名字找出ID 46 | local name = "a" .. i .. "_" .. j; 47 | local spriteCard = cc.Sprite:create("card/pic/" .. name .. ".png"); 48 | cardBitmap[count] = spriteCard; 49 | -- card[count] = Card.ctor(spriteCard.width, spriteCard.height, spriteCard); 50 | -- card[count].setName(name); 51 | count = count + 1; 52 | end 53 | end 54 | -- Android中的实现.. 55 | -- int count=0; 56 | -- for (int i = 1; i <= 4; i++) { 57 | -- for (int j = 3; j <= 15; j++) { 58 | -- //根据名字找出ID 59 | -- String name = "a" + i + "_" + j; 60 | -- ApplicationInfo appInfo = getContext().getApplicationInfo(); 61 | -- int id = getResources().getIdentifier(name, "drawable", 62 | -- appInfo.packageName); 63 | -- cardBitmap[count] = BitmapFactory.decodeResource(getResources(), 64 | -- id); 65 | -- card[count] = new Card(cardBitmap[count].getWidth(),cardBitmap[count].getHeight(), cardBitmap[count]); 66 | -- //设置Card的名字 67 | -- card[count].setName(name); 68 | -- count++; 69 | -- } 70 | -- } 71 | end 72 | 73 | ------------------------------------------------------------------------------- 74 | -- 构造函数. 75 | -- @function [parent=#LordCardScene] ctor 76 | function LordCardScene:ctor() 77 | self.visibleSize = cc.Director:getInstance():getVisibleSize(); 78 | self.origin = cc.Director:getInstance():getVisibleOrigin(); 79 | self.schedulerID = nil; 80 | end 81 | 82 | ------------------------------------------------------------------------------- 83 | -- 创建一个牌桌场景. 84 | -- @function [parent=#LordCardScene] createlayerTable 85 | -- @return #cc.Layer 86 | function LordCardScene:createlayerTable() 87 | 88 | layerTable = cc.Layer:create(); 89 | 90 | -- 屏幕中心 91 | local location = { 92 | x = self.origin.x + self.visibleSize.width / 2, 93 | y = self.origin.y + self.visibleSize.height / 2 94 | }; 95 | 96 | -- 添加牌桌背景 97 | local bg = cc.Sprite:create("card/pic/bg.png"); 98 | -- 总是放置的中心位置, Cocos总是以左下角为坐标原点 99 | bg:setPosition(location.x, location.y); 100 | print("背景宽度: " .. bg:getTexture():getPixelsWide()); 101 | print("背景高度: " .. bg:getTexture():getPixelsHigh()); 102 | layerTable:addChild(bg); 103 | 104 | return layerTable; 105 | end 106 | 107 | ------------------------------------------------------------------------------- 108 | -- 创建一个菜单场景. 109 | -- @function [parent=#LordCardScene] createLayerMenu 110 | -- @return #cc.Layer 111 | function LordCardScene:createLayerMenu() 112 | 113 | local layerMenu = cc.Layer:create(); 114 | 115 | -- 屏幕中心 116 | local screenCenter = { 117 | x = self.origin.x + self.visibleSize.width / 2, 118 | y = self.origin.y + self.visibleSize.height / 2 119 | }; 120 | 121 | local color = cc.c3b(0xFF,0xFF,0); 122 | 123 | -- 创建一个Image菜单 124 | function startMenuItemCallback(sender) 125 | print("点击了文字开始"); 126 | layerMenu:removeAllChildren(); 127 | -- TODO: 开始发牌. 128 | self:deal(); 129 | end 130 | 131 | local startMenuItem2 = CCMenuUtil.createMenuItemSprite( 132 | "card/pic/menu/menu_item_start", color, screenCenter, startMenuItemCallback); 133 | 134 | layerMenu:addChild(CCMenuUtil.createMenu({x=0,y=0}, startMenuItem2)); 135 | 136 | return layerMenu; 137 | 138 | end 139 | 140 | ------------------------------------------------------------------------------- 141 | -- 发牌. 142 | -- @function [parent=#LordCardScene] deal 143 | -- @return #cc.Layer 144 | function LordCardScene:deal() 145 | print("发牌"); 146 | 147 | for idx = 1, 10 do 148 | local spriteCard = cc.Sprite:create("card/pic/a1_"..(idx + 3)..".png"); 149 | spriteCard:setPosition(400 + idx * 20, 30); 150 | layerTable:addChild(spriteCard); 151 | local cardMoveToAction = cc.MoveTo:create(0.6 + idx * 0.04, {x = 500 + idx * 20, y = 60}); 152 | spriteCard:runAction(cardMoveToAction); 153 | end 154 | end 155 | 156 | return LordCardScene 157 | -------------------------------------------------------------------------------- /src/TestScene.lua: -------------------------------------------------------------------------------- 1 | -- 单元测试框架, 用于测试游戏中可能使用的工具类方法, 包括 2 | -- StringUtil 3 | -- ArrayUtil 4 | 5 | require "ender.test.TestCase" 6 | 7 | require "ender.test.utils.StringUtilTest" 8 | require "ender.test.utils.ArrayUtilTest" 9 | 10 | local TestScene = class("TestScene",function() 11 | return cc.Scene:create() 12 | end) 13 | 14 | function TestScene.create() 15 | local scene = TestScene.new() 16 | scene:addChild(scene:createLayerFarm()) 17 | 18 | StringUtilTest:new().run() 19 | ArrayUtilTest:new().run() 20 | return scene 21 | end 22 | 23 | 24 | function TestScene:ctor() 25 | self.visibleSize = cc.Director:getInstance():getVisibleSize() 26 | self.origin = cc.Director:getInstance():getVisibleOrigin() 27 | self.schedulerID = nil 28 | end 29 | 30 | -- create farm 31 | function TestScene:createLayerFarm() 32 | local layerFarm = cc.Layer:create() 33 | -- add in farm background 34 | local bg = cc.Sprite:create("farm.jpg") 35 | bg:setPosition(self.origin.x + self.visibleSize.width / 2 + 80, self.origin.y + self.visibleSize.height / 2) 36 | layerFarm:addChild(bg) 37 | 38 | return layerFarm 39 | end 40 | 41 | return TestScene 42 | -------------------------------------------------------------------------------- /src/TexasHoldemPokerScene.lua: -------------------------------------------------------------------------------- 1 | 2 | local TexasHoldemPokerScene = class("TexasHoldemPokerScene",function() 3 | return cc.Scene:create() 4 | end) 5 | 6 | function TexasHoldemPokerScene.create() 7 | local scene = TexasHoldemPokerScene.new() 8 | scene:addChild(scene:createlayerTable()) 9 | scene:addChild(scene:createLayerMenu()) 10 | return scene 11 | end 12 | 13 | 14 | function TexasHoldemPokerScene:ctor() 15 | self.visibleSize = cc.Director:getInstance():getVisibleSize() 16 | self.origin = cc.Director:getInstance():getVisibleOrigin() 17 | self.schedulerID = nil 18 | end 19 | 20 | function TexasHoldemPokerScene:playBgMusic() 21 | local bgMusicPath = cc.FileUtils:getInstance():fullPathForFilename("background.mp3") 22 | cc.SimpleAudioEngine:getInstance():playMusic(bgMusicPath, true) 23 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") 24 | cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath) 25 | end 26 | 27 | function TexasHoldemPokerScene:creatDog() 28 | local frameWidth = 105 29 | local frameHeight = 95 30 | 31 | -- create dog animate 32 | local textureDog = cc.Director:getInstance():getTextureCache():addImage("dog.png") 33 | local rect = cc.rect(0, 0, frameWidth, frameHeight) 34 | local frame0 = cc.SpriteFrame:createWithTexture(textureDog, rect) 35 | rect = cc.rect(frameWidth, 0, frameWidth, frameHeight) 36 | local frame1 = cc.SpriteFrame:createWithTexture(textureDog, rect) 37 | 38 | local spriteDog = cc.Sprite:createWithSpriteFrame(frame0) 39 | spriteDog:setPosition(self.origin.x, self.origin.y + self.visibleSize.height / 4 * 3) 40 | spriteDog.isPaused = false 41 | 42 | local animation = cc.Animation:createWithSpriteFrames({frame0,frame1}, 0.5) 43 | local animate = cc.Animate:create(animation); 44 | spriteDog:runAction(cc.RepeatForever:create(animate)) 45 | 46 | -- moving dog at every frame 47 | local function tick() 48 | if spriteDog.isPaused then return end 49 | local x, y = spriteDog:getPosition() 50 | if x > self.origin.x + self.visibleSize.width then 51 | x = self.origin.x 52 | else 53 | x = x + 1 54 | end 55 | 56 | spriteDog:setPositionX(x) 57 | end 58 | 59 | self.schedulerID = cc.Director:getInstance():getScheduler():scheduleScriptFunc(tick, 0, false) 60 | 61 | return spriteDog 62 | end 63 | 64 | -- create farm 65 | function TexasHoldemPokerScene:createlayerTable() 66 | local layerTable = cc.Layer:create() 67 | -- 添加牌桌背景 68 | local bg = cc.Sprite:create("card/pic/bg.png") 69 | -- 总是放置的中心位置, Cocos总是以左下角为坐标原点 70 | bg:setPosition(self.origin.x + self.visibleSize.width / 2, self.origin.y + self.visibleSize.height / 2) 71 | print("背景宽度: " .. bg:getTexture():getPixelsWide()) 72 | print("背景高度: " .. bg:getTexture():getPixelsHigh()) 73 | layerTable:addChild(bg) 74 | 75 | -- 将所有的牌铺在桌面上(1: 梅花, 2: 方片, 3: 红心, 4: 黑桃, 5: 大小王) 76 | local startX = 60 77 | local startY = 200 78 | for i = 1, 5 do 79 | for j = 3, 17 do 80 | if (i < 5 and j < 16) or (i >= 5 and j >= 16) then 81 | local card = cc.Sprite:create("card/pic/a" .. i .. "_" .. j .. ".png") 82 | card:setPosition(startX + (j - 3) * 80, startY + (i - 1) * 100) 83 | layerTable:addChild(card) 84 | end 85 | end 86 | end 87 | 88 | -- -- add land sprite 89 | -- for i = 0, 3 do 90 | -- for j = 0, 1 do 91 | -- local spriteLand = cc.Sprite:create("land.png") 92 | -- spriteLand:setPosition(200 + j * 180 - i % 2 * 90, 10 + i * 95 / 2) 93 | -- layerTable:addChild(spriteLand) 94 | -- end 95 | -- end 96 | -- 97 | -- -- add crop 98 | -- local frameCrop = cc.SpriteFrame:create("crop.png", cc.rect(0, 0, 105, 95)) 99 | -- for i = 0, 3 do 100 | -- for j = 0, 1 do 101 | -- local spriteCrop = cc.Sprite:createWithSpriteFrame(frameCrop); 102 | -- spriteCrop:setPosition(210 + j * 180 - i % 2 * 90, 40 + i * 95 / 2) 103 | -- layerTable:addChild(spriteCrop) 104 | -- end 105 | -- end 106 | -- 107 | -- -- add moving dog 108 | -- local spriteDog = self:creatDog() 109 | -- layerTable:addChild(spriteDog) 110 | -- 111 | -- handing touch events 112 | local touchBeginPoint = nil 113 | local function onTouchBegan(touch, event) 114 | local location = touch:getLocation() 115 | --cclog("onTouchBegan: %0.2f, %0.2f", location.x, location.y) 116 | touchBeginPoint = {x = location.x, y = location.y} 117 | -- spriteDog.isPaused = true 118 | -- CCTOUCHBEGAN event must return true 119 | return true 120 | end 121 | 122 | local function onTouchMoved(touch, event) 123 | local location = touch:getLocation() 124 | --cclog("onTouchMoved: %0.2f, %0.2f", location.x, location.y) 125 | if touchBeginPoint then 126 | local cx, cy = layerTable:getPosition() 127 | layerTable:setPosition(cx + location.x - touchBeginPoint.x, 128 | cy + location.y - touchBeginPoint.y) 129 | touchBeginPoint = {x = location.x, y = location.y} 130 | end 131 | end 132 | 133 | local function onTouchEnded(touch, event) 134 | local location = touch:getLocation() 135 | --cclog("onTouchEnded: %0.2f, %0.2f", location.x, location.y) 136 | touchBeginPoint = nil 137 | -- spriteDog.isPaused = false 138 | end 139 | 140 | local listener = cc.EventListenerTouchOneByOne:create() 141 | listener:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) 142 | listener:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) 143 | listener:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) 144 | local eventDispatcher = layerTable:getEventDispatcher() 145 | eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layerTable) 146 | -- 147 | -- local function onNodeEvent(event) 148 | -- if "exit" == event then 149 | -- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.schedulerID) 150 | -- end 151 | -- end 152 | -- layerTable:registerScriptHandler(onNodeEvent) 153 | 154 | return layerTable 155 | end 156 | 157 | -- create menu 158 | function TexasHoldemPokerScene:createLayerMenu() 159 | 160 | local layerMenu = cc.Layer:create() 161 | -- local menuPopup, menuTools, effectID 162 | -- 163 | -- local function menuCallbackClosePopup() 164 | -- -- stop test sound effect 165 | -- cc.SimpleAudioEngine:getInstance():stopEffect(effectID) 166 | -- menuPopup:setVisible(false) 167 | -- end 168 | -- 169 | -- local function menuCallbackOpenPopup() 170 | -- -- loop test sound effect 171 | -- local effectPath = cc.FileUtils:getInstance():fullPathForFilename("effect1.wav") 172 | -- effectID = cc.SimpleAudioEngine:getInstance():playEffect(effectPath) 173 | -- menuPopup:setVisible(true) 174 | -- end 175 | -- 176 | -- -- add a popup menu 177 | -- local menuPopupItem = cc.MenuItemImage:create("menu2.png", "menu2.png") 178 | -- menuPopupItem:setPosition(0, 0) 179 | -- menuPopupItem:registerScriptTapHandler(menuCallbackClosePopup) 180 | -- menuPopup = cc.Menu:create(menuPopupItem) 181 | -- menuPopup:setPosition(self.origin.x + self.visibleSize.width / 2, self.origin.y + self.visibleSize.height / 2) 182 | -- menuPopup:setVisible(false) 183 | -- layerMenu:addChild(menuPopup) 184 | -- 185 | -- -- add the left-bottom "tools" menu to invoke menuPopup 186 | -- local menuToolsItem = cc.MenuItemImage:create("menu1.png", "menu1.png") 187 | -- menuToolsItem:setPosition(0, 0) 188 | -- menuToolsItem:registerScriptTapHandler(menuCallbackOpenPopup) 189 | -- menuTools = cc.Menu:create(menuToolsItem) 190 | -- local itemWidth = menuToolsItem:getContentSize().width 191 | -- local itemHeight = menuToolsItem:getContentSize().height 192 | -- menuTools:setPosition(self.origin.x + itemWidth/2, self.origin.y + itemHeight/2) 193 | -- layerMenu:addChild(menuTools) 194 | 195 | return layerMenu 196 | end 197 | 198 | return TexasHoldemPokerScene 199 | -------------------------------------------------------------------------------- /src/ender/init.lua: -------------------------------------------------------------------------------- 1 | 2 | -- utils 3 | require "ender.utils.StringUtil" 4 | require "ender.utils.ArrayUtil" 5 | require "ender.utils.AudioUtil" 6 | require "ender.utils.EventUtil" 7 | -- require "ender/utils/EventUtil" 的写法也是可以的 8 | require "ender.utils.ColorUtil" 9 | 10 | -- cc界面相关工具 11 | require "ender.utils.CCSpriteUtil" 12 | require "ender.utils.CCMenuUtil" 13 | require "ender.utils.CCDirectorUtil" 14 | require "ender.utils.CCSceneUtil" 15 | -------------------------------------------------------------------------------- /src/ender/test/TestCase.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 测试用例的基类. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module TestCase 10 | TestCase = class("TestCase") 11 | 12 | testResult = true 13 | gTestClass = "" 14 | gTestMethod = "" 15 | gTestInfo = "" 16 | gTestLineInfo = "" 17 | 18 | function TestCase:new(o) 19 | o = o or {} 20 | setmetatable(o, self) 21 | self.__index = self 22 | return o 23 | end 24 | 25 | function TestCase.setup() 26 | end 27 | 28 | function TestCase.tearDown() 29 | end 30 | 31 | function TestCase.runOneTest(testClass, testMethod, func) 32 | gTestClass = testClass 33 | gTestMethod = testMethod 34 | gTestInfo = gTestClass.."."..gTestMethod.."()" 35 | testResult = true 36 | func() 37 | if testResult then 38 | print("[SUCCESS] "..gTestInfo) 39 | end 40 | end 41 | 42 | ------------------------------------------------------------------------------- 43 | -- 断言实际值是否等于期望值. 44 | -- @function [parent=#TestCase] assertEquals 45 | -- @param #any expected 期望值 46 | -- @param #any actual 实际值 47 | function assertEquals(expected, actual) 48 | local traceTable = StringUtil.split(debug.traceback(), "\n") 49 | local infoTable = StringUtil.split(StringUtil.trim(traceTable[3]), ":") 50 | gTestLineInfo = gTestInfo .. "-line[" .. infoTable[2] .. "]" 51 | if "table" == type(expected) and "table" == type(actual) then 52 | assertEqualsArray(expected, actual) 53 | elseif expected ~= actual then 54 | print(string.format("[FAIL] expected: %s, but actual: %s -- %s", expected, actual, gTestLineInfo)) 55 | testResult = false 56 | end 57 | end 58 | 59 | ------------------------------------------------------------------------------- 60 | -- 断言两个数组是否相等. 61 | -- @function [parent=#TestCase] assertEqualsArray 62 | -- @param #any expected 期望数组 63 | -- @param #any actual 实际数组 64 | function assertEqualsArray(expected, actual) 65 | local eLength = table.getn(expected); 66 | local aLength = table.getn(actual); 67 | if eLength ~= aLength then 68 | print(string.format("[FAIL] expected length: %d, but actual length: %d -- %s", eLength, aLength, gTestLineInfo)) 69 | testResult = false 70 | else 71 | for i=1, eLength do 72 | if expected[i] ~= actual[i] then 73 | print(string.format("[FAIL] expected[%d]: %s, but actual[%d]: %s -- %s", i, expected[i], i, actual[i], gTestLineInfo)) 74 | testResult = false 75 | end 76 | end 77 | end 78 | end 79 | 80 | return TestCase -------------------------------------------------------------------------------- /src/ender/test/utils/ArrayUtilTest.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 测试数组的单元测试用例. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module ArrayUtilTest 10 | ArrayUtilTest = class("ArrayUtilTest", function() 11 | return TestCase:new() 12 | end) 13 | 14 | function ArrayUtilTest.run() 15 | print(" start ArrayUtilTest") 16 | TestCase.runOneTest("ArrayUtilTest", "testSize", ArrayUtilTest.testSize) 17 | TestCase.runOneTest("ArrayUtilTest", "testMax", ArrayUtilTest.testMax) 18 | TestCase.runOneTest("ArrayUtilTest", "testMin", ArrayUtilTest.testMin) 19 | TestCase.runOneTest("ArrayUtilTest", "testFill", ArrayUtilTest.testFill) 20 | TestCase.runOneTest("ArrayUtilTest", "testInit", ArrayUtilTest.testInit) 21 | TestCase.runOneTest("ArrayUtilTest", "testSort", ArrayUtilTest.testSort) 22 | TestCase.runOneTest("ArrayUtilTest", "testToString", ArrayUtilTest.testToString) 23 | print(" end ArrayUtilTest\n") 24 | print("--------------------------------------------------------------------------------\n") 25 | end 26 | 27 | ------------------------------------------------------------------------------- 28 | -- Test for ArrayUtil.size(input). 29 | -- @function [parent=#ArrayUtilTest] testSize 30 | function ArrayUtilTest.testSize() 31 | assertEquals(5, ArrayUtil.size({1,2,3,4,5})); 32 | assertEquals(3, ArrayUtil.size({"abcd","234","dfe4"})); 33 | end 34 | 35 | ------------------------------------------------------------------------------- 36 | -- Test for ArrayUtil.max(input). 37 | -- @function [parent=#ArrayUtilTest] testMax 38 | function ArrayUtilTest.testMax() 39 | assertEquals(6, ArrayUtil.max({1,2,3,6,5})); 40 | assertEquals(90, ArrayUtil.max({12,30,90,44})); 41 | end 42 | 43 | ------------------------------------------------------------------------------- 44 | -- Test for ArrayUtil.min(input). 45 | -- @function [parent=#ArrayUtilTest] testMin 46 | function ArrayUtilTest.testMin() 47 | assertEquals(1, ArrayUtil.min({1,2,3,6,5})); 48 | assertEquals(12, ArrayUtil.min({12,30,90,44})); 49 | end 50 | 51 | ------------------------------------------------------------------------------- 52 | -- Test for ArrayUtil.fill(input, val). 53 | -- @function [parent=#ArrayUtilTest] testFill 54 | function ArrayUtilTest.testFill() 55 | assertEquals({1,1,1}, ArrayUtil.fill({1,2,3}, 1)); 56 | assertEquals({2,2,2,2,2}, ArrayUtil.fill({1,2,3,4,5}, 2)); 57 | assertEquals({1,2,5,5,5}, ArrayUtil.fill({1,2,3,4,5}, 5, 3)); 58 | assertEquals({1,2,5,5,6}, ArrayUtil.fill({1,2,3,4,6}, 5, 3, 4)); 59 | assertEquals({1,2,5,5,5}, ArrayUtil.fill({1,2,3,4,6}, 5, 3, 10)); 60 | end 61 | 62 | ------------------------------------------------------------------------------- 63 | -- Test for ArrayUtil.init(input, val). 64 | -- @function [parent=#ArrayUtilTest] testInit 65 | function ArrayUtilTest.testInit() 66 | assertEquals({1,1,1}, ArrayUtil.init({}, 1, 3)); 67 | assertEquals({"abc","abc","abc"}, ArrayUtil.init({}, "abc", 3)); 68 | assertEquals({1,1,1,1,1}, ArrayUtil.init({}, 1, 5)); 69 | end 70 | 71 | ------------------------------------------------------------------------------- 72 | -- Test for ArrayUtil.sort(input). 73 | -- @function [parent=#ArrayUtilTest] testSort 74 | function ArrayUtilTest.testSort() 75 | assertEquals({1,2,3}, ArrayUtil.sort({1,3,2})); 76 | assertEquals({1,1,2,3,5,6}, ArrayUtil.sort({1,3,2,6,5,1})); 77 | assertEquals({"a","b","v"}, ArrayUtil.sort({"a","v","b"})); 78 | end 79 | 80 | ------------------------------------------------------------------------------- 81 | -- Test for ArrayUtil.toString(input). 82 | -- @function [parent=#ArrayUtilTest] testToString 83 | function ArrayUtilTest.testToString() 84 | assertEquals("1,3,2", ArrayUtil.toString({1,3,2})); 85 | assertEquals("a,v,b", ArrayUtil.toString({"a","v","b"})); 86 | end 87 | 88 | return ArrayUtilTest -------------------------------------------------------------------------------- /src/ender/test/utils/StringUtilTest.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 测试字符串的单元测试用例. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module StringUtilTest 10 | StringUtilTest = class("StringUtilTest", function() 11 | return TestCase:new() 12 | end) 13 | 14 | function StringUtilTest.run() 15 | print(" start StringUtilTest") 16 | TestCase.runOneTest("StringUtilTest", "testLength", StringUtilTest.testLength) 17 | TestCase.runOneTest("StringUtilTest", "testTrim", StringUtilTest.testTrim) 18 | TestCase.runOneTest("StringUtilTest", "testUpper", StringUtilTest.testUpper) 19 | TestCase.runOneTest("StringUtilTest", "testLower", StringUtilTest.testLower) 20 | TestCase.runOneTest("StringUtilTest", "testIndexOf", StringUtilTest.testIndexOf) 21 | TestCase.runOneTest("StringUtilTest", "testLastIndexOf", StringUtilTest.testLastIndexOf) 22 | TestCase.runOneTest("StringUtilTest", "testSplit", StringUtilTest.testSplit) 23 | TestCase.runOneTest("StringUtilTest", "testSubstring", StringUtilTest.testSubstring) 24 | print(" end StringUtilTest\n") 25 | print("--------------------------------------------------------------------------------\n") 26 | end 27 | 28 | ------------------------------------------------------------------------------- 29 | -- Test for StringUtil.length(input). 30 | -- @function [parent=#StringUtilTest] testLength 31 | function StringUtilTest.testLength() 32 | assertEquals(3, StringUtil.length("abc")); 33 | assertEquals(4, StringUtil.length("abcd")); 34 | end 35 | 36 | ------------------------------------------------------------------------------- 37 | -- Test for StringUtil.trim(input). 38 | -- @function [parent=#StringUtilTest] testTrim 39 | function StringUtilTest.testTrim() 40 | assertEquals("abc", StringUtil.trim(" abc ")); 41 | assertEquals("abcd", StringUtil.trim(" abcd ")); 42 | end 43 | 44 | ------------------------------------------------------------------------------- 45 | -- TODO: Test for StringUtil.upper(input). 46 | -- @function [parent=#StringUtilTest] testUpper 47 | function StringUtilTest.testUpper() 48 | assertEquals("ABCD", StringUtil.upper("aBcD")); 49 | assertEquals("1ABCD2", StringUtil.upper("1abcd2")); 50 | end 51 | 52 | ------------------------------------------------------------------------------- 53 | -- TODO: Test for StringUtil.lower(input). 54 | -- @function [parent=#StringUtilTest] testLower 55 | function StringUtilTest.testLower() 56 | assertEquals("abcd", StringUtil.lower("aBcD")); 57 | assertEquals("1abcd2", StringUtil.lower("1ABCD2")); 58 | end 59 | 60 | ------------------------------------------------------------------------------- 61 | -- Test for StringUtil.indexOf(input, subString). 62 | -- @function [parent=#StringUtilTest] testIndexOf 63 | function StringUtilTest.testIndexOf(input, subString) 64 | assertEquals(2, StringUtil.indexOf("abcabc", "bc")); 65 | assertEquals(3, StringUtil.indexOf("abcbcbcbc", "cb")); 66 | end 67 | 68 | ------------------------------------------------------------------------------- 69 | -- Test for StringUtil.lastIndexOf(input, subString). 70 | -- @function [parent=#StringUtilTest] testLastIndexOf 71 | function StringUtilTest.testLastIndexOf() 72 | assertEquals(5, StringUtil.lastIndexOf("abcabc", "bc")); 73 | assertEquals(7, StringUtil.lastIndexOf("abcbcbcbc", "cb")); 74 | end 75 | 76 | ------------------------------------------------------------------------------- 77 | -- Test for StringUtil.split(szFullString, szSeparator). 78 | -- @function [parent=#StringUtilTest] testSplit 79 | function StringUtilTest.testSplit() 80 | local arr = StringUtil.split("abc,abd,abf,avt", ",") 81 | assertEquals(4, table.getn(arr)); 82 | assertEquals("abc", arr[1]); 83 | assertEquals("abd", arr[2]); 84 | assertEquals("abf", arr[3]); 85 | assertEquals("avt", arr[4]); 86 | end 87 | 88 | ------------------------------------------------------------------------------- 89 | -- Test for StringUtil.substring(input, startIndex, endIndex). 90 | -- @function [parent=#StringUtilTest] testSubstring 91 | function StringUtilTest.testSubstring() 92 | assertEquals("bca", StringUtil.substring("abcabc", 2, 4)); 93 | assertEquals("cbcb", StringUtil.substring("abcbcbcbc", 5, 8)); 94 | end 95 | 96 | return StringUtilTest -------------------------------------------------------------------------------- /src/ender/utils/ArrayUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 数组工具. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module ArrayUtil 10 | ArrayUtil = class("ArrayUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 返回table的大小. 14 | -- @function [parent=#ArrayUtil] size 15 | -- @param #table input 需要操作的数组 16 | -- @return #int 数组的大小 17 | function ArrayUtil.size(input) 18 | return table.getn(input) 19 | end 20 | 21 | ------------------------------------------------------------------------------- 22 | -- 返回table的最大元素(只能对数值进行操作). 23 | -- @function [parent=#ArrayUtil] max 24 | -- @param #table input 需要操作的数组 25 | -- @return #int 最大元素的值 26 | function ArrayUtil.max(input) 27 | return math.max(unpack(input)) 28 | end 29 | 30 | ------------------------------------------------------------------------------- 31 | -- 返回table的最小元素(只能对数值进行操作). 32 | -- @function [parent=#ArrayUtil] max 33 | -- @param #table input 需要操作的数组 34 | -- @return #int 最小元素的值 35 | function ArrayUtil.min(input) 36 | return math.min(unpack(input)) 37 | end 38 | 39 | ------------------------------------------------------------------------------- 40 | -- 填充table的每一个元素为val. 41 | -- @function [parent=#ArrayUtil] fill 42 | -- @param #table input 需要操作的数组 43 | -- @param #any val 需要填充的值 44 | -- @param #int startIndex 开始的索引(可选) 45 | -- @param #int endIndex 结束的索引(可选) 46 | -- @return #table 填充后的数组 47 | function ArrayUtil.fill(input, val, startIndex, endIndex) 48 | if startIndex ~= nil then 49 | if endIndex ~= nil then 50 | -- 固定数组长度不做扩展 51 | endIndex = math.min(table.getn(input), endIndex) 52 | for i = startIndex, endIndex do 53 | input[i] = val 54 | end 55 | else 56 | for i=startIndex, table.getn(input) do 57 | input[i] = val 58 | end 59 | end 60 | else 61 | for i=1, table.getn(input) do 62 | input[i] = val 63 | end 64 | end 65 | return input 66 | end 67 | 68 | ------------------------------------------------------------------------------- 69 | -- 初始化table的每一个元素为val, 填充长度为n. 70 | -- @function [parent=#ArrayUtil] init 71 | -- @param #table input 需要操作的数组 72 | -- @param #any val 需要填充的值 73 | -- @param #int n 填充的数量 74 | -- @return #table 填充后的数组 75 | function ArrayUtil.init(input, val, n) 76 | for i=1, n do 77 | input[i] = val 78 | end 79 | return input 80 | end 81 | 82 | ------------------------------------------------------------------------------- 83 | -- 排序输出table. 可排序字符串数组(字典排序) 84 | -- @function [parent=#ArrayUtil] sort 85 | -- @param #table input 需要操作的数组 86 | -- @return #table 排序后的数组 87 | function ArrayUtil.sort(input) 88 | table.sort(input) 89 | return input 90 | end 91 | 92 | ------------------------------------------------------------------------------- 93 | -- 输出表示table的字符串 94 | -- @function [parent=#ArrayUtil] toString 95 | -- @param #table input 需要操作的数组 96 | -- @return #string 数组的字符串表示, 以","分隔 97 | function ArrayUtil.toString(input) 98 | local ret = "" 99 | for i = 1, table.getn(input) do 100 | if i > 1 then 101 | ret = ret .. "," 102 | end 103 | ret = ret .. input[i] 104 | end 105 | return ret 106 | end 107 | 108 | return ArrayUtil; -------------------------------------------------------------------------------- /src/ender/utils/AudioUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 声音工具,包装Cocos2d播放声音的方法. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module AudioUtil 10 | AudioUtil = class("AudioUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 播放一段音乐. 14 | -- @function [parent=#AudioUtil] playMusic 15 | -- @param #string filename 声音文件的路径 16 | -- @param #boolean bLoop 是否循环播放 17 | function AudioUtil.playMusic(filename, bLoop) 18 | local musicPath = cc.FileUtils:getInstance():fullPathForFilename(filename); 19 | cc.SimpleAudioEngine:getInstance():playMusic(musicPath, bLoop); 20 | end 21 | 22 | ------------------------------------------------------------------------------- 23 | -- 预先加载音效. 24 | -- @function [parent=#AudioUtil] preloadEffect 25 | -- @param #string filename 声音文件的路径 26 | function AudioUtil.preloadEffect(filename) 27 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename(filename); 28 | cc.SimpleAudioEngine:getInstance():preloadEffect(effectPath); 29 | end 30 | 31 | ------------------------------------------------------------------------------- 32 | -- 播放音效. 33 | -- @function [parent=#AudioUtil] playEffect 34 | -- @param #string filename 声音文件的路径 35 | function AudioUtil.playEffect(filename) 36 | local effectPath = cc.FileUtils:getInstance():fullPathForFilename(filename); 37 | effectID = cc.SimpleAudioEngine:getInstance():playEffect(effectPath); 38 | end 39 | 40 | return AudioUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCDirectorUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 导演工具. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module CCDirectorUtil 10 | CCDirectorUtil = class("CCDirectorUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 场景切换. 14 | -- @function [parent=#CCDirectorUtil] createMenu 15 | -- @param #string sceneName 场景名字 16 | function CCDirectorUtil.gotoScene(sceneName) 17 | print("数据类型: " .. type(sceneName)); 18 | local gameScene = nil; 19 | if type(sceneName) == "string" then 20 | gameScene = require(sceneName).create(); 21 | elseif type(sceneName) == "userdata" then 22 | gameScene = sceneName; 23 | end 24 | 25 | if gameScene ~= nil then 26 | if cc.Director:getInstance():getRunningScene() then 27 | cc.Director:getInstance():replaceScene(gameScene); 28 | else 29 | cc.Director:getInstance():runWithScene(gameScene); 30 | end 31 | end 32 | end 33 | 34 | return CCDirectorUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCLayerUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 层工具,包装Cocos2d中处理层的相关方法,... 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-25. 9 | -- @module CCLayerUtil 10 | CCLayerUtil = class("CCLayerUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 创建精灵(Sprite), 指定位置(如果提供location参数). 14 | -- ERROR: 无法在此方法内正确创建Sprite. 15 | -- @function [parent=#CCLayerUtil] create 16 | -- @param #string fileName 创建Sprite的文件路径 17 | -- @param #table location 形如{x=*,y=*}的table 18 | function CCLayerUtil.create(fileName, location) 19 | local mySprite = cc.Sprite:create(fileName); 20 | mySprite:setPosition(location.x, location.y); 21 | return mySprite; 22 | end 23 | 24 | return CCLayerUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCMenuUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 菜单工具. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module CCMenuUtil 10 | CCMenuUtil = class("CCMenuUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 创建菜单. 14 | -- @function [parent=#CCMenuUtil] createMenu 15 | -- @param #string position 文字坐标 16 | -- @return #cc.Menu 菜单 17 | function CCMenuUtil.createMenu(position, ...) 18 | local menu=cc.Menu:create(...); --初始化菜单 19 | menu:setPosition(position.x, position.y); --设置菜单坐标 20 | return menu; 21 | end 22 | 23 | ------------------------------------------------------------------------------- 24 | -- 创建一个字符型的菜单项. 25 | -- @function [parent=#CCMenuUtil] createMenuItemFont 26 | -- @param #string text 文字内容 27 | -- @param #color4table color 字体颜色cc.c3b(R, G, B)或cc.c4b(A, R, G, B) 28 | -- @param #string position 文字坐标 29 | -- @param #string callback 菜单响应事件 30 | -- @return #cc.MenuItemFont 字符型的菜单项 31 | function CCMenuUtil.createMenuItemFont(text, color, position, callback) 32 | local menuItem=cc.MenuItemFont:create(text); --初始化菜单项 33 | menuItem:setString(text); --设置文字内容 34 | menuItem:setColor(color); --设置字体颜色 35 | menuItem:setPosition(position.x, position.y); --设置文字坐标 36 | menuItem:registerScriptTapHandler(callback); --设置菜单响应事件 37 | return menuItem; 38 | end 39 | 40 | ------------------------------------------------------------------------------- 41 | -- 创建一个Sprite型的菜单项. 42 | -- @function [parent=#CCMenuUtil] createMenuItemSprite 43 | -- @param #string filename 菜单项图片背景文件名前缀 44 | -- @param #string color 颜色cc.c3b(R, G, B)或cc.c4b(A, R, G, B) 45 | -- @param #string position 文字坐标 46 | -- @param #string callback 菜单响应事件 47 | -- @return #cc.MenuItemFont 字符型的菜单项 48 | function CCMenuUtil.createMenuItemSprite(text, color, position, callback) 49 | local normalSprite = cc.Sprite:create(text .. "_normal.png"); 50 | local selectedSprite = cc.Sprite:create(text .. "_selected.png"); 51 | -- TODO: 找到disabledSprite的使用场景 52 | local disabledSprite = cc.Sprite:create(text .. "_disabled.png"); 53 | local menuItem = cc.MenuItemSprite:create( --初始化菜单项 54 | normalSprite, selectedSprite, disabledSprite); 55 | menuItem:setColor(color); --设置字体颜色 56 | menuItem:setPosition(position.x, position.y); --设置文字坐标 57 | menuItem:registerScriptTapHandler(callback); --设置菜单响应事件 58 | return menuItem; 59 | end 60 | 61 | ------------------------------------------------------------------------------- 62 | -- 创建一个Image型的菜单项. 63 | -- @function [parent=#CCMenuUtil] createMenuItemImage 64 | -- @param #string filename 菜单项图片背景文件名前缀 65 | -- @param #string color 颜色cc.c3b(R, G, B)或cc.c4b(A, R, G, B) 66 | -- @param #string position 文字坐标 67 | -- @param #string callback 菜单响应事件 68 | -- @return #cc.MenuItemFont 字符型的菜单项 69 | function CCMenuUtil.createMenuItemImage(text, color, position, callback) 70 | local normalImage = text .. "_normal.png"; 71 | local selectedImage = text .. "_selected.png"; 72 | -- TODO: 找到disabledSprite的使用场景 73 | local disabledImage = text .. "_disabled.png"; 74 | local menuItem = cc.MenuItemImage:create( --初始化菜单项 75 | normalImage, selectedImage, disabledImage); 76 | menuItem:setColor(color); --设置字体颜色 77 | menuItem:setPosition(position.x, position.y); --设置文字坐标 78 | menuItem:registerScriptTapHandler(callback); --设置菜单响应事件 79 | return menuItem; 80 | end 81 | 82 | return CCMenuUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCNodeUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 节点工具,包装Cocos2d节点处理的相关方法. 7 | -- cc.Node主要功能: 8 | -- 9 | -- 10 | -- 11 | -- 12 | --
每个节点都可以含有子节点
节点含有周期性回调的方法(Schedule, Unschedule)
可以含有动作(cc.Action)
13 | -- 作者: Andrew Yuan
14 | -- 时间: 2014-12-25. 15 | -- @module CCNodeUtil 16 | CCNodeUtil = class("CCNodeUtil"); 17 | 18 | ------------------------------------------------------------------------------- 19 | -- 创建节点(Node), 指定位置(如果提供location参数). 20 | -- @function [parent=#CCNodeUtil] create 21 | -- @param #table location 形如{x=*,y=*}的table 22 | function CCNodeUtil.create(location) 23 | local myNode = cc.Node:create(); 24 | myNode:setPosition(location.x, location.y); 25 | return myNode; 26 | end 27 | 28 | return CCNodeUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCSceneUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 场景工具,包装Cocos2d中场景相关方法,... 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-25. 9 | -- @module CCSceneUtil 10 | CCSceneUtil = class("CCSceneUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 创建一个逐渐过渡到目标颜色的切换动画. 14 | -- @field [parent=#CCSceneUtil] #string FADE 15 | CCSceneUtil.FADE = "fade"; 16 | ------------------------------------------------------------------------------- 17 | -- 创建一个逐渐透明的过渡动画. 18 | -- @field [parent=#CCSceneUtil] #string CROSS_FADE 19 | CCSceneUtil.CROSS_FADE = "cross_fade"; 20 | 21 | ------------------------------------------------------------------------------- 22 | -- 获取指定类型的场景转换包装. 23 | -- @function [parent=#CCSceneUtil] getTransition 24 | -- @param #string type 场景切换的类型 25 | -- @param #string sceneName 场景名 26 | -- @param #float duration 场景切换的持续时间 27 | function CCSceneUtil.getTransition(type, sceneName, duration, ...) 28 | local nextScene = require(sceneName).create(); 29 | local trasitionScene = nil; 30 | -- 参考网址: http://blog.csdn.net/liuhong135541/article/details/24375915. 31 | if type == CCSceneUtil.FADE then 32 | trasitionScene = cc.TransitionFade:create(duration, nextScene); 33 | elseif type == CCSceneUtil.CROSS_FADE then 34 | trasitionScene = cc.TransitionCrossFade:create(duration, nextScene); 35 | -- elseif type == CCSceneUtil.FADE then 36 | end 37 | return trasitionScene; 38 | end 39 | 40 | return CCSceneUtil; -------------------------------------------------------------------------------- /src/ender/utils/CCSpriteUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 精灵工具,包装Cocos2d精灵相关方法. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module CCSpriteUtil 10 | CCSpriteUtil = class("CCSpriteUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 创建精灵(Sprite), 指定位置(如果提供location参数). 14 | -- ERROR: 无法在此方法内正确创建Sprite. 15 | -- @function [parent=#CCSpriteUtil] create 16 | -- @param #string fileName 创建Sprite的文件路径 17 | -- @param #table location 形如{x=*,y=*}的table 18 | function CCSpriteUtil.create(fileName, location) 19 | local mySprite = cc.Sprite:create(fileName); 20 | mySprite:setPosition(location.x, location.y); 21 | return mySprite; 22 | end 23 | 24 | return CCSpriteUtil; -------------------------------------------------------------------------------- /src/ender/utils/ColorUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 颜色工具,通过不同的参数来创建颜色. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-25. 9 | -- @module ColorUtil 10 | ColorUtil = class("ColorUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 通过int参数创建颜色. 14 | -- 注意: cc.c4b(r, g, b, a);中最后一个参数是alpha(透明度). 15 | -- @function [parent=#ColorUtil] createFromInt 16 | -- @param #int intValue 32位的int颜色值. 17 | -- @return #color4btable 带透明色信息的颜色表 18 | function ColorUtil.createFromInt(intValue) 19 | local color = nil; 20 | local a,r,g,b; 21 | local left = intValue; 22 | a, left = ColorUtil.mod(left, 2^24); 23 | r, left = ColorUtil.mod(left, 2^16); 24 | g, b = ColorUtil.mod(left, 2^8); 25 | print(string.format("a:%d, r:%d, g:%d, b:%d", a, r, g, b)); 26 | color = cc.c4b(r, g, b, a); 27 | return color; 28 | end 29 | 30 | ------------------------------------------------------------------------------- 31 | -- 返回两个整数值, 第一个是商, 第二个是余数. 32 | -- @function [parent=#ColorUtil] mod 33 | -- @param #int v1 除数. 34 | -- @param #int v2 被除数. 35 | function ColorUtil.mod(v1, v2) 36 | local r1 = math.modf(v1 / v2); 37 | local r2 = v1 % v2; 38 | return r1, r2; 39 | end 40 | 41 | return ColorUtil; -------------------------------------------------------------------------------- /src/ender/utils/EventUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 事件工具,包装Cocos2d事件相关方法:事件注册,... 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module EventUtil 10 | EventUtil = class("EventUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 注册一组事件到指定的Cocos2D层. 14 | -- @function [parent=#EventUtil] register 15 | -- @param #cc.Layer layer Cocos2D层 16 | -- @param #table eventTable 事件对 17 | function EventUtil.register(layer, eventTable) 18 | local listener = cc.EventListenerTouchOneByOne:create(); 19 | for i=1, table.getn(eventTable) do 20 | listener:registerScriptHandler(eventTable[i][1], eventTable[i][2]); 21 | end 22 | local eventDispatcher = layer:getEventDispatcher(); 23 | eventDispatcher:addEventListenerWithSceneGraphPriority(listener, layer); 24 | end 25 | 26 | ------------------------------------------------------------------------------- 27 | -- 返回触摸点的位置{x,y}. 28 | -- @function [parent=#EventUtil] getLocation 29 | -- @param touch 30 | function EventUtil.getLocation(touch) 31 | local location = touch:getLocation(); 32 | -- print(string.format("onTouchMoved: %0.2f, %0.2f", location.x, location.y)); 33 | return location; 34 | end 35 | 36 | return EventUtil; -------------------------------------------------------------------------------- /src/ender/utils/StringUtil.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息. 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 字符串工具. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-06. 9 | -- @module StringUtil 10 | StringUtil = class("StringUtil"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 返回input字符串的长度. 14 | -- @function [parent=#StringUtil] length 15 | -- @param #string input 需要操作的字符串 16 | -- @return #int 字符串的长度 17 | function StringUtil.length(input) 18 | return string.len(input) 19 | end 20 | 21 | ------------------------------------------------------------------------------- 22 | -- 返回被截取前后空白的input字符串. (来源于网络,无修改) 23 | -- @function [parent=#StringUtil] trim 24 | -- @param #string str 需要操作的字符串 25 | -- @return #string 被截取前后空白的input字符串 26 | function StringUtil.trim(s) 27 | local from = s:match"^%s*()" 28 | return from > #s and "" or s:match(".*%S", from) 29 | end 30 | 31 | ------------------------------------------------------------------------------- 32 | -- TODO: 返回转换为大写的字符串. (来源于网络,无修改) 33 | -- @function [parent=#StringUtil] upper 34 | -- @param #string str 需要操作的字符串 35 | -- @return #string 转换为大写的字符串 36 | function StringUtil.upper(str) 37 | local len = string.len(str) 38 | local str_tmp = "" 39 | for i = 1, len do 40 | local ch = string.sub(str, i, i) 41 | if ch >= 'a' and ch <= 'z' then 42 | ch = string.char(string.byte(ch) - 32) 43 | end 44 | str_tmp = str_tmp .. ch 45 | end 46 | return str_tmp 47 | end 48 | 49 | ------------------------------------------------------------------------------- 50 | -- TODO: 返回转换为小写的字符串. (来源于网络,无修改) 51 | -- @function [parent=#StringUtil] lower 52 | -- @param #string str 需要操作的字符串 53 | -- @return #string 转换为小写的字符串 54 | function StringUtil.lower(str) 55 | local len = string.len(str) 56 | local str_tmp = "" 57 | for i = 1, len do 58 | local ch = string.sub(str, i, i) 59 | if ch >= 'A' and ch <= 'Z' then 60 | ch = string.char(string.byte(ch) + 32) 61 | end 62 | str_tmp = str_tmp .. ch 63 | end 64 | return str_tmp 65 | end 66 | 67 | ------------------------------------------------------------------------------- 68 | -- 返回subString在input中第一次出现的位置. 69 | -- @function [parent=#StringUtil] indexOf 70 | -- @param #string input 需要操作的字符串 71 | -- @param #string subString 需要查找的子串 72 | -- @return #int 子字符串第一次出现的索引位置 73 | function StringUtil.indexOf(input, subString) 74 | -- 新的知识点: 虚变量的使用 75 | startIndex, _ = string.find(input, subString) 76 | return startIndex 77 | end 78 | 79 | ------------------------------------------------------------------------------- 80 | -- 返回subString在input中最后一次出现的位置. 81 | -- @function [parent=#StringUtil] lastIndexOf 82 | -- @param #string input 需要操作的字符串 83 | -- @param #string subString 需要查找的子串 84 | -- @return #int 子字符串最后一次出现的索引位置 85 | function StringUtil.lastIndexOf(input, subString) 86 | local startIndex = 0 87 | repeat 88 | startIndex, _ = string.find(input, subString, startIndex + 1) 89 | until string.find(input, subString, startIndex + 1) == nil -- 对nil的判断使用 XXX -= nil会报错 90 | return startIndex 91 | end 92 | 93 | ------------------------------------------------------------------------------- 94 | -- 用szSeparator将szFullString分隔开来成为字符串数组 95 | -- @function [parent=#StringUtil] split 96 | -- @param #string szFullString 需要操作的字符串 97 | -- @param #string szSeparator 分隔符号 98 | -- @return #int 分隔后的字符串数组 99 | function StringUtil.split(szFullString, szSeparator) 100 | local nFindStartIndex = 1 101 | local nSplitIndex = 1 102 | local nSplitArray = {} 103 | while true do 104 | local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex) 105 | if not nFindLastIndex then 106 | nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString)) 107 | break 108 | end 109 | nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1) 110 | nFindStartIndex = nFindLastIndex + string.len(szSeparator) 111 | nSplitIndex = nSplitIndex + 1 112 | end 113 | return nSplitArray 114 | end 115 | 116 | ------------------------------------------------------------------------------- 117 | -- 获取子字符串 118 | -- @function [parent=#StringUtil] substring 119 | -- @param #string input 需要操作的字符串 120 | -- @param #int startIndex 子字符串开始的位置 121 | -- @param #int endIndex 子字符串结束的位置 122 | -- @return #string 分隔后的字符串数组 123 | function StringUtil.substring(input, startIndex, endIndex) 124 | return string.sub(input, startIndex, endIndex) 125 | end 126 | 127 | return StringUtil; -------------------------------------------------------------------------------- /src/game/entity/Card.lua: -------------------------------------------------------------------------------- 1 | --[[ 2 | 版权信息 3 | ]]-- 4 | 5 | ------------------------------------------------------------------------------- 6 | -- 实体: 一张牌. 7 | -- 作者: Andrew Yuan
8 | -- 时间: 2014-12-25. 9 | -- @module Card 10 | Card = class("Card"); 11 | 12 | ------------------------------------------------------------------------------- 13 | -- 牌的x坐标. 14 | -- @field [parent=#Card] #float x 15 | Card.x = 0; 16 | ------------------------------------------------------------------------------- 17 | -- 牌的y坐标. 18 | -- @field [parent=#Card] #float y 19 | Card.y = 0; 20 | ------------------------------------------------------------------------------- 21 | -- 牌的宽度. 22 | -- @field [parent=#Card] #float width 23 | Card.width = 0; 24 | ------------------------------------------------------------------------------- 25 | -- 牌的高度. 26 | -- @field [parent=#Card] #float height 27 | Card.height = 0; 28 | ------------------------------------------------------------------------------- 29 | -- 牌的精灵对象. 30 | -- @field [parent=#Card] #userdata bitmap 31 | Card.bitmap = nil; 32 | ------------------------------------------------------------------------------- 33 | -- 牌的名字. 34 | -- @field [parent=#Card] #string name 35 | Card.name = ""; 36 | ------------------------------------------------------------------------------- 37 | -- 是否背面. 38 | -- @field [parent=#Card] #boolean rear 39 | Card.rear = false; 40 | ------------------------------------------------------------------------------- 41 | -- 是否被点击. 42 | -- @field [parent=#Card] #boolean clicked 43 | Card.clicked = false; 44 | 45 | -- TODO: 实现牌对象的OOP 46 | function Card:new(o) 47 | o = o or {}; 48 | setmetatable(o, self); 49 | self.__index = self; 50 | return o; 51 | end 52 | 53 | ------------------------------------------------------------------------------- 54 | -- 定义 Card 的构造函数. 55 | -- @function [parent=#Card] ctor 56 | -- @param #float width 牌的宽度设置 57 | -- @param #float height 牌的高度设置 58 | -- @param #float bitmap 牌的精灵设置 59 | function Card:ctor(width, height, bitmap) 60 | self.width = width; 61 | self.height = height; 62 | self.bitmap = bitmap; 63 | end 64 | 65 | ------------------------------------------------------------------------------- 66 | -- 设置牌的位置. 67 | -- @function [parent=#Card] setLocation 68 | -- @param #float x 场景切换的类型 69 | -- @param #float y 场景名 70 | function Card.setLocation(x, y) 71 | self.x = x; 72 | self.y = y; 73 | end 74 | 75 | ------------------------------------------------------------------------------- 76 | -- 设置牌的名字. 77 | -- @function [parent=#Card] setName 78 | -- @param #string name 牌的名字 79 | function Card.setName(name) 80 | self.name = name; 81 | end 82 | 83 | ------------------------------------------------------------------------------- 84 | -- 得到牌的原始区域. 85 | -- @function [parent=#Card] getSRC 86 | -- @return #cc.rect 87 | function Card.getSRC() 88 | return cc.rect(0, 0, width, width); 89 | end 90 | 91 | ------------------------------------------------------------------------------- 92 | -- 得到牌的目标区域. 93 | -- @function [parent=#Card] getDST 94 | -- @return #cc.rect 95 | function Card.getDST() 96 | return cc.rect(x, y, x + width, y + width); 97 | end 98 | 99 | return Card; -------------------------------------------------------------------------------- /src/game/entity/init.lua: -------------------------------------------------------------------------------- 1 | 2 | -- utils 3 | require "game.entity.Card" 4 | -------------------------------------------------------------------------------- /src/main.lua: -------------------------------------------------------------------------------- 1 | 2 | cc.FileUtils:getInstance():addSearchPath("src") 3 | cc.FileUtils:getInstance():addSearchPath("res") 4 | 5 | -- CC_USE_DEPRECATED_API = true 6 | require "cocos.init" 7 | 8 | -- Ender Utils 9 | require "ender.init" 10 | 11 | -- 控制变量, 是否使用单元测试 12 | local isUnitTestMode = false 13 | 14 | -- cclog 15 | local cclog = function(...) 16 | print(string.format(...)) 17 | end 18 | 19 | -- for CCLuaEngine traceback 20 | function __G__TRACKBACK__(msg) 21 | cclog("----------------------------------------") 22 | cclog("LUA ERROR: " .. tostring(msg) .. "\n") 23 | cclog(debug.traceback()) 24 | cclog("----------------------------------------") 25 | return msg 26 | end 27 | 28 | local function main() 29 | collectgarbage("collect") 30 | -- avoid memory leak 31 | collectgarbage("setpause", 100) 32 | collectgarbage("setstepmul", 5000) 33 | 34 | -- initialize director 35 | local director = cc.Director:getInstance() 36 | 37 | --turn on display FPS 38 | -- director:setDisplayStats(true) 39 | 40 | --set FPS. the default value is 1.0/60 if you don't call this 41 | director:setAnimationInterval(1.0 / 60) 42 | 43 | -- cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(480, 320, 0) 44 | cc.Director:getInstance():getOpenGLView():setDesignResolutionSize(1280, 720, 0) 45 | 46 | if isUnitTestMode then 47 | --create test scene 48 | CCDirectorUtil.gotoScene("TestScene") 49 | else 50 | --create game scene 51 | -- CCDirectorUtil.gotoScene("GameScene") 52 | CCDirectorUtil.gotoScene("CardScene") 53 | -- gameScene:playBgMusic() 54 | end 55 | 56 | end 57 | 58 | 59 | local status, msg = xpcall(main, __G__TRACKBACK__) 60 | if not status then 61 | error(msg) 62 | end 63 | --------------------------------------------------------------------------------