├── 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 | --
每个节点都可以含有子节点 |
节点含有周期性回调的方法(Schedule, Unschedule) |
可以含有动作(cc.Action) |