├── .gitignore ├── Classes ├── AIChessboardController.cpp ├── AIChessboardController.h ├── AIController.cpp ├── AIController.h ├── AIGameScene.cpp ├── AIGameScene.h ├── AppDelegate.cpp ├── AppDelegate.h ├── AppMacros.h ├── AudioManager.cpp ├── AudioManager.h ├── BaseController.cpp ├── BaseController.h ├── C2DXShareSDK │ ├── Android │ │ ├── JSON │ │ │ ├── CCJSONConverter.cpp │ │ │ ├── CCJSONConverter.h │ │ │ ├── CCJSONData.h │ │ │ └── cJSON │ │ │ │ ├── cJSON.c │ │ │ │ └── cJSON.h │ │ ├── ShareSDKUtils.cpp │ │ └── ShareSDKUtils.h │ ├── C2DXShareSDK.cpp │ ├── C2DXShareSDK.h │ ├── C2DXShareSDKTypeDef.h │ └── ios │ │ ├── C2DXiOSShareSDK.h │ │ └── C2DXiOSShareSDK.mm ├── Chessboard.cpp ├── Chessboard.h ├── ChessboardChecker.cpp ├── ChessboardChecker.h ├── ChessboardController.cpp ├── ChessboardController.h ├── ChessboardProtocol.cpp ├── ChessboardProtocol.h ├── FixMoveAIChessboardController.cpp ├── FixMoveAIChessboardController.h ├── FixMoveAIGameScene.cpp ├── FixMoveAIGameScene.h ├── FixTimeAIChessboardController.cpp ├── FixTimeAIChessboardController.h ├── FixTimeAIGameScene.cpp ├── FixTimeAIGameScene.h ├── GameScene.cpp ├── GameScene.h ├── HelpController.cpp ├── HelpController.h ├── HelpScene.cpp ├── HelpScene.h ├── ImageButton.cpp ├── ImageButton.h ├── LogoView.cpp ├── LogoView.h ├── MenuController.cpp ├── MenuController.h ├── Message.h ├── Model.cpp ├── Model.h ├── MoveBoard.cpp ├── MoveBoard.h ├── PieceView.cpp ├── PieceView.h ├── ResultView.cpp ├── ResultView.h ├── RotFlowerParticle.cpp ├── RotFlowerParticle.h ├── StartController.cpp ├── StartController.h ├── StartScene.cpp ├── StartScene.h ├── Tag.h ├── TimeBoard.cpp └── TimeBoard.h ├── README.md ├── Resources ├── AllSprites.plist ├── AllSprites.png ├── ShareSDK.xml ├── audio │ ├── click.WAV │ ├── create.WAV │ ├── eat.WAV │ ├── move.WAV │ └── next_round.WAV ├── fonts │ └── Marker Felt.ttf └── star.png ├── proj.android ├── .classpath ├── .cproject ├── .project ├── .settings │ ├── org.eclipse.core.resources.prefs │ └── org.eclipse.jdt.core.prefs ├── AndroidManifest.xml ├── README.md ├── ant.properties ├── assets │ ├── AllSprites.plist │ ├── AllSprites.png │ ├── ShareSDK.xml │ ├── audio │ │ ├── click.WAV │ │ ├── create.WAV │ │ ├── eat.WAV │ │ ├── move.WAV │ │ └── next_round.WAV │ ├── fonts │ │ └── Marker Felt.ttf │ └── star.png ├── bin │ ├── AndroidManifest.xml │ ├── R.txt │ ├── classes │ │ └── edu │ │ │ └── nju │ │ │ └── four │ │ │ ├── BuildConfig.class │ │ │ ├── Four.class │ │ │ ├── R$attr.class │ │ │ ├── R$drawable.class │ │ │ ├── R$string.class │ │ │ └── R.class │ └── jarlist.cache ├── build.xml ├── build_native.sh ├── gen │ └── edu │ │ └── nju │ │ └── four │ │ ├── BuildConfig.java │ │ └── R.java ├── ic_launcher-web.png ├── jni │ ├── Android.mk │ ├── Application.mk │ └── hellocpp │ │ └── main.cpp ├── libs │ ├── ShareSDK-Core-2.3.7.jar │ ├── ShareSDK-Email-2.3.7.jar │ ├── ShareSDK-QQ-2.3.7.jar │ ├── ShareSDK-QZone-2.3.7.jar │ ├── ShareSDK-Renren-2.3.7.jar │ ├── ShareSDK-ShortMessage-2.3.7.jar │ ├── ShareSDK-SinaWeibo-2.3.7.jar │ ├── armeabi │ │ └── libcocos2dcpp.so │ ├── libPluginProtocol.jar │ ├── mframework.jar │ └── x86 │ │ └── libcocos2dcpp.so ├── lint.xml ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ ├── auth_follow_cb_chd.png │ │ ├── auth_follow_cb_unc.png │ │ ├── auth_title_back.png │ │ ├── btn_back_nor.9.png │ │ ├── btn_cancel_back.9.png │ │ ├── edittext_back.9.png │ │ ├── gray_point.png │ │ ├── ic_launcher.png │ │ ├── icon.png │ │ ├── img_cancel.png │ │ ├── logo_email.png │ │ ├── logo_evernote.png │ │ ├── logo_qq.png │ │ ├── logo_qzone.png │ │ ├── logo_renren.png │ │ ├── logo_shortmessage.png │ │ ├── logo_sinaweibo.png │ │ ├── logo_wechatfavorite.png │ │ ├── pin.png │ │ ├── share_tb_back.9.png │ │ ├── share_vp_back.9.png │ │ ├── ssdk_auth_title_back.png │ │ ├── ssdk_back_arr.png │ │ ├── ssdk_logo.png │ │ ├── ssdk_title_div.png │ │ ├── title_back.png │ │ ├── title_shadow.png │ │ └── white_point.png │ ├── drawable-xxhdpi │ │ └── logo.png │ └── values │ │ ├── colors.xml │ │ ├── oks_strings.xml │ │ ├── ssdk_strings.xml │ │ ├── strings.xml │ │ └── styles.xml └── src │ ├── cn │ └── sharesdk │ │ ├── ShareSDKUtils.java │ │ └── onekeyshare │ │ ├── CustomerLogo.java │ │ ├── EditPage.java │ │ ├── FollowList.java │ │ ├── OnekeyShare.java │ │ ├── PicViewer.java │ │ ├── PlatformGridView.java │ │ ├── ShareContentCustomizeCallback.java │ │ └── ShareCore.java │ └── edu │ └── nju │ └── four │ └── Four.java └── proj.ios ├── AppController.h ├── AppController.mm ├── Default-568h@2x.png ├── Default.png ├── Default@2x.png ├── Four.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── wangxuanyi.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── wangxuanyi.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── Four.xcscheme │ ├── LocationTest.xcscheme │ └── xcschememanagement.plist ├── Icon-114.png ├── Icon-120.png ├── Icon-144.png ├── Icon-152.png ├── Icon-57.png ├── Icon-72.png ├── Icon-76.png ├── Info.plist ├── LocationTest ├── LocationTest.1 └── main.cpp ├── Prefix.pch ├── RootViewController.h ├── RootViewController.mm └── main.m /.gitignore: -------------------------------------------------------------------------------- 1 | proj.win32 2 | proj.android/obj 3 | *.class 4 | proj.android/bin -------------------------------------------------------------------------------- /Classes/AIChessboardController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AIChessboardController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #include "AIChessboardController.h" 10 | #include "AIController.h" 11 | #include "Message.h" 12 | #include "Chessboard.h" 13 | #include "PieceView.h" 14 | #include "LogoView.h" 15 | #include "Tag.h" 16 | #include "ResultView.h" 17 | #include "RotFlowerParticle.h" 18 | 19 | AIChessboardController::~AIChessboardController(){ 20 | CC_SAFE_RELEASE(actor); 21 | } 22 | 23 | bool AIChessboardController::init(){ 24 | ChessboardController::init(); 25 | 26 | actor = AIController::create(); 27 | actor->retain(); 28 | 29 | LogoView* black = dynamic_cast(this->getChildByTag(ROUND_BLACK)); 30 | LogoView* white = dynamic_cast(this->getChildByTag(ROUND_WHITE)); 31 | 32 | black->activateStop(); 33 | white->activateStop(); 34 | 35 | CCLabelTTF* label = ResultView::create(); 36 | this->addChild(label); 37 | 38 | modeLabel->setString("人机对战"); 39 | 40 | return true; 41 | } 42 | 43 | void AIChessboardController::onEnter(){ 44 | ChessboardController::onEnter(); 45 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(AIChessboardController::onNextRound), NEXT_ROUND_MSG, nullptr); 46 | CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, CLICK_REGRET_MSG); 47 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(AIChessboardController::tryRegret), AI_END_MOVE_MSG, nullptr); 48 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(AIChessboardController::tryAIRegret), CLICK_REGRET_MSG, nullptr); 49 | } 50 | 51 | void AIChessboardController::onExit(){ 52 | ChessboardController::onExit(); 53 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 54 | } 55 | 56 | void AIChessboardController::onNextRound(CCObject* o){ 57 | if (chessboard->getCurrentMove().currentRound == AI ) { 58 | CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this); 59 | Move move(AI); 60 | actor->getNextMove(chessboard->getPieces(), move); 61 | this->tryMove(move.src, move.dest); 62 | }else { 63 | CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, true); 64 | } 65 | } 66 | 67 | void AIChessboardController::tryAIRegret(cocos2d::CCObject *o){ 68 | if (chessboard->checkMessage(REGRET_MSG)){ 69 | chessboard->alterAIRegret(); 70 | 71 | CCString* frame_name = ( chessboard->getCurrentMove().currentRound == WHITE ) ? CCString::create("black.png") : CCString::create("white.png"); 72 | 73 | for (CCPoint p : chessboard->getCurrentMove().eatenPoints) { 74 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 75 | CCSprite* piece = PieceView::create(&(this->chessboard->getCurrentMove()), this->chessboard, cache->spriteFrameByName(frame_name->getCString()), p); 76 | this->addChild(piece); 77 | } 78 | } 79 | } 80 | 81 | void AIChessboardController::tryWin(cocos2d::CCObject* o){ 82 | if (chessboard->checkMessage(WIN_MSG)) { 83 | if (chessboard->checkWin(chessboard->getCurrentMove()) && chessboard->getCurrentMove().currentRound == PLAYER){ 84 | chessboard->alterWin(); 85 | this->addChild(RotFlowerParticle::create()); 86 | }else if (chessboard->checkWin(chessboard->getCurrentMove()) && chessboard->getCurrentMove().currentRound == AI) { 87 | chessboard->alterLose(); 88 | }else{ 89 | chessboard->alterNextRound(); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /Classes/AIChessboardController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AIChessboardController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #ifndef __Four__AIChessboardController__ 10 | #define __Four__AIChessboardController__ 11 | 12 | #include "ChessboardController.h" 13 | #include "ChessboardProtocol.h" 14 | 15 | #include "cocos2d.h" 16 | 17 | using cocos2d::CCNotificationCenter; 18 | 19 | class AIController; 20 | 21 | class AIChessboardController : public ChessboardController{ 22 | PIECE PLAYER; 23 | PIECE AI; 24 | 25 | AIController* actor; 26 | public: 27 | bool init(); 28 | AIChessboardController():PLAYER(BLACK), AI(WHITE){} 29 | virtual ~AIChessboardController(); 30 | 31 | CREATE_FUNC(AIChessboardController); 32 | 33 | virtual void onEnter(); 34 | virtual void onExit(); 35 | 36 | virtual void onNextRound(CCObject* o); 37 | virtual void tryAIRegret(CCObject* o); 38 | virtual void tryWin(CCObject* o); 39 | }; 40 | 41 | #endif /* defined(__Four__AIChessboardController__) */ 42 | -------------------------------------------------------------------------------- /Classes/AIController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AIController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #include "AIController.h" 10 | #include "ChessboardChecker.h" 11 | #include 12 | #include 13 | 14 | typedef std::vector SolutionList; 15 | 16 | bool AIController::init(){ 17 | return true; 18 | } 19 | 20 | void AIController::getNextMove(const ChessboardData &pieces, Move &nextMove){ 21 | // nextMove.src = ccp(0, 3); 22 | // nextMove.dest = ccp(0, 2); 23 | 24 | SolutionList solutionList; 25 | createSolutions(pieces, nextMove, solutionList); 26 | for (auto itr = solutionList.begin(); itr != solutionList.end(); ++itr) 27 | reduceBeKilledScore(*itr); 28 | 29 | int largest = solutionList[0].score; 30 | // Solution *resultSolution; 31 | Move resultMove = solutionList[0].move; 32 | for (auto s : solutionList){ 33 | std::srand(std::time(0)); 34 | if (s.score > largest) { 35 | largest = s.score; 36 | // resultSolution = &s; 37 | resultMove = s.move; 38 | } 39 | else if (s.score == largest && std::rand() > (RAND_MAX / 2)) { 40 | resultMove = s.move; 41 | } 42 | } 43 | nextMove = resultMove; 44 | solutionList.clear(); 45 | } 46 | 47 | //生成解决方案呢 48 | void AIController::createSolutions(const ChessboardData& pieces, Move& nextMove, SolutionList& solutionList) { 49 | PIECE p; 50 | 51 | for (int i = 0; i < WIDTH; i++) { // 获取所有棋子 52 | for (int j = 0; j < HEIGHT; j++) { 53 | p = getPiece(pieces, ccp(i, j)); 54 | if (p == nextMove.currentRound) { // 所属同一阵营 55 | CCPoint pointDevision[] = { ccp(0, 1), ccp(0, -1), ccp(-1, 0), ccp(1, 0) }; 56 | 57 | for (auto devision : pointDevision) { 58 | // 往四个方向 59 | Move move = Move(nextMove.currentRound, ccp(i, j), ccp(i, j) + devision); 60 | if (checkMove(pieces, move)) { 61 | CCLOG("from %d %d to %f %f", i, j, devision.x, devision.y); 62 | Solution solution = Solution(); 63 | solution.move = move; 64 | createChessboardMoveOver(pieces, move, solution.pieces); 65 | solution.score = getTotalScore(solution.pieces, move); 66 | solutionList.push_back(solution); 67 | } 68 | } 69 | } 70 | } 71 | } 72 | } 73 | 74 | //生成一个解决方案 75 | //Solution* AIController::createSolution(const ChessboardData& pieces, Move* move) { 76 | // Solution* solution = new Solution(); 77 | // solution->move = move; 78 | // solution->score = getTotalScore(pieces, *move); 79 | //} 80 | 81 | // 创建走完后的棋盘 82 | void AIController::createChessboardMoveOver(const ChessboardData& pieces1, Move& nextMove, ChessboardData& pieces2) { 83 | for (auto a : pieces1) 84 | pieces2.push_back(a); 85 | pieces2[nextMove.src.y][nextMove.src.x] = ZERO; 86 | pieces2[nextMove.dest.y][nextMove.dest.x] = nextMove.currentRound; 87 | } 88 | 89 | // 杀人评分 90 | int AIController::getKillScore(const ChessboardData& pieces, Move& nextMove) { 91 | // Move move(nextMove); 92 | 93 | // bool canEat = checkEat(pieces, move); 94 | 95 | if (!checkEat(pieces, nextMove)) 96 | return 0; 97 | 98 | // return (nextMove.eatenPoints.size() - nextMove.eatenPoints.size()) * 3; 99 | return nextMove.eatenPoints.size() * 3; 100 | } 101 | // 走位评分 102 | int AIController::getGoalScore(const ChessboardData& pieces, Move& nextMove) { 103 | // 往中间走加1分 104 | return ((nextMove.src.x < 1 || nextMove.src.x > 2) && (nextMove.dest.x >= 1 && nextMove.dest.x <= 2) ? 1 : 0) 105 | + ((nextMove.src.y < 1 || nextMove.src.y > 2) && (nextMove.dest.y >= 1 && nextMove.dest.y <= 2) ? 1 : 0); 106 | } 107 | 108 | // 总评分 109 | int AIController::getTotalScore(const ChessboardData& pieces, Move& nextMove) { 110 | return getKillScore(pieces, nextMove) + getGoalScore(pieces, nextMove); 111 | } 112 | 113 | // 被杀扣分 114 | void AIController::reduceBeKilledScore(Solution& solution) { 115 | Move move2 = solution.move; 116 | move2.currentRound = oppositePiece(solution.move.currentRound); 117 | 118 | SolutionList solutionList2; 119 | createSolutions(solution.pieces, move2, solutionList2); 120 | 121 | int largestPoint = 0; 122 | for (auto obj : solutionList2) 123 | largestPoint = obj.score > largestPoint ? obj.score : largestPoint; 124 | 125 | solution.score -= largestPoint; 126 | 127 | // int killCount = 0; 128 | // for (auto obj : solutionList2) 129 | // killCount = (obj.move.eatenPoints.size() > killCount) ? obj.move.eatenPoints.size() : killCount; 130 | 131 | // solution.score -= killCount * 2; 132 | } -------------------------------------------------------------------------------- /Classes/AIController.h: -------------------------------------------------------------------------------- 1 | // 2 | // AIController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #ifndef __Four__AIController__ 10 | #define __Four__AIController__ 11 | 12 | #include "ChessboardProtocol.h" 13 | #include "cocos2d.h" 14 | 15 | #include 16 | 17 | struct Solution 18 | { 19 | public: 20 | Move move = Move(BLACK); 21 | int score; 22 | ChessboardData pieces; 23 | 24 | ~Solution(){ 25 | // delete move; 26 | } 27 | }; 28 | 29 | typedef std::vector SolutionList; 30 | using cocos2d::CCObject; 31 | 32 | 33 | class AIController : public CCObject { 34 | CC_SYNTHESIZE(PIECE, AIPiece, AIPiece); 35 | 36 | public: 37 | bool init(); 38 | CREATE_FUNC(AIController); 39 | 40 | void getNextMove(const ChessboardData& pieces, Move& nextMove); 41 | 42 | private: 43 | 44 | //生成解决方案呢 45 | void createSolutions(const ChessboardData& pieces, Move& nextMove, SolutionList& solutionList); 46 | //生成一个解决方案 47 | // Solution* createSolution(const ChessboardData& pieces, Move* move); 48 | // 创建走完后的棋盘 49 | void createChessboardMoveOver(const ChessboardData& pieces1, Move& nextMove, ChessboardData& pieces2); 50 | 51 | // 杀人评分 52 | int getKillScore(const ChessboardData& pieces, Move& nextMove); 53 | // 走位评分 54 | int getGoalScore(const ChessboardData& pieces, Move& nextMove); 55 | // 总评分 56 | int getTotalScore(const ChessboardData& pieces, Move& nextMove); 57 | // 被杀扣分 58 | void reduceBeKilledScore(Solution& solution); 59 | }; 60 | 61 | #endif /* defined(__Four__AIController__) */ 62 | -------------------------------------------------------------------------------- /Classes/AIGameScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AIGameScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #include "AIGameScene.h" 10 | #include "AIChessboardController.h" 11 | #include "MenuController.h" 12 | 13 | bool AIGameScene::init(){ 14 | CCScene::init(); 15 | 16 | CCLayer* cc = AIChessboardController::create(); 17 | this->addChild(cc); 18 | CCLayer* mc = MenuController::create(); 19 | this->addChild(mc); 20 | 21 | return true; 22 | } -------------------------------------------------------------------------------- /Classes/AIGameScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // AIGameScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-5. 6 | // 7 | // 8 | 9 | #ifndef __Four__AIGameScene__ 10 | #define __Four__AIGameScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using cocos2d::CCScene; 15 | 16 | class AIGameScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(AIGameScene); 21 | 22 | }; 23 | 24 | #endif /* defined(__Four__AIGameScene__) */ 25 | -------------------------------------------------------------------------------- /Classes/AppDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "HelpScene.h" 3 | #include "StartScene.h" 4 | #include "SimpleAudioEngine.h" 5 | #include "AudioManager.h" 6 | 7 | #include 8 | 9 | USING_NS_CC; 10 | 11 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 12 | 13 | #include "C2DXShareSDK.h" 14 | 15 | using namespace cn::sharesdk; 16 | 17 | #endif 18 | 19 | AppDelegate::AppDelegate() { 20 | audio = AudioManager::create(); 21 | CC_SAFE_RETAIN(audio); 22 | } 23 | 24 | AppDelegate::~AppDelegate() 25 | { 26 | CC_SAFE_RELEASE(audio); 27 | } 28 | 29 | bool AppDelegate::applicationDidFinishLaunching() { 30 | 31 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 32 | C2DXShareSDK::open(CCString::create("api20"), false); 33 | #endif 34 | 35 | // initialize director 36 | CCDirector* pDirector = CCDirector::sharedDirector(); 37 | CCEGLView* pEGLView = CCEGLView::sharedOpenGLView(); 38 | 39 | 40 | pDirector->setOpenGLView(pEGLView); 41 | 42 | pEGLView->setDesignResolutionSize(640, 1136, kResolutionShowAll); 43 | 44 | pDirector->setAnimationInterval(1.0 / 60); 45 | 46 | // create a scene. it's an autorelease object 47 | 48 | CCDictionary* config = CCDictionary::create(); 49 | 50 | CCScene* pScene = nullptr; 51 | 52 | std::string config_path = CCFileUtils::sharedFileUtils()->getWritablePath() + "Config.plist"; 53 | 54 | bool firstTime = !CCFileUtils::sharedFileUtils()->isFileExist(config_path); 55 | 56 | if (firstTime) { 57 | pScene = HelpScene::create(); 58 | config->setObject(CCString::create("0"), "FirstTime"); 59 | CCAssert(config->writeToFile(config_path.c_str()), "not passes"); 60 | }else{ 61 | pScene = StartScene::create(); 62 | } 63 | 64 | // run 65 | pDirector->runWithScene(pScene); 66 | 67 | return true; 68 | } 69 | 70 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too 71 | void AppDelegate::applicationDidEnterBackground() { 72 | CCDirector::sharedDirector()->stopAnimation(); 73 | 74 | // if you use SimpleAudioEngine, it must be pause 75 | audio->pause(); 76 | } 77 | 78 | // this function will be called when the app is active again 79 | void AppDelegate::applicationWillEnterForeground() { 80 | CCDirector::sharedDirector()->startAnimation(); 81 | 82 | // if you use SimpleAudioEngine, it must resume here 83 | audio->resume(); 84 | } -------------------------------------------------------------------------------- /Classes/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #ifndef _APP_DELEGATE_H_ 2 | #define _APP_DELEGATE_H_ 3 | 4 | #include "cocos2d.h" 5 | 6 | 7 | class AudioManager; 8 | 9 | /** 10 | @brief The cocos2d Application. 11 | 12 | The reason for implement as private inheritance is to hide some interface call by CCDirector. 13 | */ 14 | class AppDelegate : private cocos2d::CCApplication 15 | { 16 | private: 17 | AudioManager* audio; 18 | 19 | //初始化平台配置 20 | 21 | public: 22 | AppDelegate(); 23 | virtual ~AppDelegate(); 24 | 25 | /** 26 | @brief Implement CCDirector and CCScene init code here. 27 | @return true Initialize success, app continue. 28 | @return false Initialize failed, app terminate. 29 | */ 30 | virtual bool applicationDidFinishLaunching(); 31 | 32 | /** 33 | @brief The function be called when the application enter background 34 | @param the pointer of the application 35 | */ 36 | virtual void applicationDidEnterBackground(); 37 | 38 | /** 39 | @brief The function be called when the application enter foreground 40 | @param the pointer of the application 41 | */ 42 | virtual void applicationWillEnterForeground(); 43 | }; 44 | 45 | #endif // _APP_DELEGATE_H_ 46 | 47 | -------------------------------------------------------------------------------- /Classes/AppMacros.h: -------------------------------------------------------------------------------- 1 | #ifndef __APPMACROS_H__ 2 | #define __APPMACROS_H__ 3 | 4 | #include "cocos2d.h" 5 | 6 | /* For demonstrating using one design resolution to match different resources, 7 | or one resource to match different design resolutions. 8 | 9 | [Situation 1] Using one design resolution to match different resources. 10 | Please look into Appdelegate::applicationDidFinishLaunching. 11 | We check current device frame size to decide which resource need to be selected. 12 | So if you want to test this situation which said in title '[Situation 1]', 13 | you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina), 14 | or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform 15 | and modify "proj.mac/AppController.mm" by changing the window rectangle. 16 | 17 | [Situation 2] Using one resource to match different design resolutions. 18 | The coordinates in your codes is based on your current design resolution rather than resource size. 19 | Therefore, your design resolution could be very large and your resource size could be small. 20 | To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536' 21 | and open iphone simulator or create a window of 480x320 size. 22 | 23 | [Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources. 24 | */ 25 | 26 | #define DESIGN_RESOLUTION_480X320 0 27 | #define DESIGN_RESOLUTION_1024X768 1 28 | #define DESIGN_RESOLUTION_2048X1536 2 29 | 30 | /* If you want to switch design resolution, change next line */ 31 | #define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320 32 | 33 | typedef struct tagResource 34 | { 35 | cocos2d::CCSize size; 36 | char directory[100]; 37 | }Resource; 38 | 39 | static Resource smallResource = { cocos2d::CCSizeMake(480, 320), "iphone" }; 40 | static Resource mediumResource = { cocos2d::CCSizeMake(1024, 768), "ipad" }; 41 | static Resource largeResource = { cocos2d::CCSizeMake(2048, 1536), "ipadhd" }; 42 | 43 | #if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320) 44 | static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320); 45 | #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768) 46 | static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768); 47 | #elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536) 48 | static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536); 49 | #else 50 | #error unknown target design resolution! 51 | #endif 52 | 53 | // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution 54 | #define TITLE_FONT_SIZE (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24) 55 | 56 | #endif /* __APPMACROS_H__ */ 57 | -------------------------------------------------------------------------------- /Classes/AudioManager.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // AudioManager.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-6. 6 | // 7 | // 8 | 9 | #include "AudioManager.h" 10 | #include "Message.h" 11 | 12 | AudioManager::~AudioManager(){ 13 | CC_SAFE_RELEASE(msg2audio); 14 | } 15 | 16 | bool AudioManager::init(){ 17 | using namespace cocos2d; 18 | 19 | msg2audio = cocos2d::CCDictionary::create(); 20 | CC_SAFE_RETAIN(msg2audio); 21 | CCFileUtils::sharedFileUtils()->addSearchPath("audio/"); 22 | 23 | msg2audio->setObject(CCStringMake("move.WAV"), BEGIN_MOVE_MSG); 24 | msg2audio->setObject(CCStringMake("eat.WAV"), BEGIN_EAT_MSG); 25 | msg2audio->setObject(CCStringMake("next_round.WAV"), NEXT_ROUND_MSG); 26 | msg2audio->setObject(CCStringMake("click.WAV"), CLICK_MSG); 27 | // msg2audio->setObject(CCStringMake("create.WAV"), CREATE_MSG); 28 | 29 | CCDictElement* e = nullptr; 30 | CCDICT_FOREACH(msg2audio, e){ 31 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(AudioManager::play), e->getStrKey(), e->getObject()); 32 | // CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(((CCString *)e->getObject())->getCString()); 33 | } 34 | 35 | return true; 36 | } 37 | 38 | void AudioManager::play(cocos2d::CCString *str){ 39 | CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(str->getCString()); 40 | } 41 | 42 | void AudioManager::pause(){ 43 | CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseAllEffects(); 44 | } 45 | 46 | void AudioManager::resume(){ 47 | CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeAllEffects(); 48 | } -------------------------------------------------------------------------------- /Classes/AudioManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // AudioManager.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-6. 6 | // 7 | // 8 | 9 | #ifndef __Four__AudioManager__ 10 | #define __Four__AudioManager__ 11 | 12 | #include "cocos2d.h" 13 | 14 | #include "SimpleAudioEngine.h" 15 | 16 | using cocos2d::CCObject; 17 | using cocos2d::CCNotificationCenter; 18 | using CocosDenshion::SimpleAudioEngine; 19 | using cocos2d::CCString; 20 | using cocos2d::CCDictionary; 21 | using cocos2d::CCFileUtils; 22 | 23 | class AudioManager : public CCObject { 24 | private: 25 | CCDictionary* msg2audio; 26 | 27 | public: 28 | virtual ~AudioManager(); 29 | bool init(); 30 | CREATE_FUNC(AudioManager); 31 | 32 | void play(CCString* str); 33 | void pause(); 34 | void resume(); 35 | 36 | }; 37 | 38 | #endif /* defined(__Four__AudioManager__) */ 39 | -------------------------------------------------------------------------------- /Classes/BaseController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // BaseController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #include "BaseController.h" 10 | 11 | bool BaseController::init(){ 12 | if (! CCLayer::init()) { 13 | return false; 14 | } 15 | 16 | // load res 17 | CCSpriteBatchNode* batch = CCSpriteBatchNode::create("AllSprites.png"); 18 | this->addChild(batch); 19 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 20 | cache->addSpriteFramesWithFile("AllSprites.plist"); 21 | 22 | // add background 23 | CCSprite* background = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("background.png")); 24 | background->setAnchorPoint(ccp(0, 0)); 25 | background->setPosition(ccp(0, 0)); 26 | this->addChild(background); 27 | 28 | return true; 29 | } -------------------------------------------------------------------------------- /Classes/BaseController.h: -------------------------------------------------------------------------------- 1 | // 2 | // BaseController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #ifndef __Four__BaseController__ 10 | #define __Four__BaseController__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class BaseController : public CCLayer { 17 | 18 | public: 19 | bool init(); 20 | CREATE_FUNC(BaseController); 21 | 22 | }; 23 | 24 | #endif /* defined(__Four__BaseController__) */ 25 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/Android/JSON/CCJSONConverter.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // CCJSONConverter.cpp 3 | // cocos2d-x-jc 4 | // 5 | // Created by LIN BOYU on 11/14/12. 6 | // 7 | // 8 | 9 | #include "CCJSONConverter.h" 10 | 11 | static CCJSONConverter _sharedConverter; 12 | 13 | CCJSONConverter * CCJSONConverter::sharedConverter() 14 | { 15 | static bool firstUse = true; 16 | if (firstUse) 17 | { 18 | firstUse = false; 19 | } 20 | return &_sharedConverter; 21 | } 22 | 23 | char * CCJSONConverter::strFrom(CCDictionary *dictionary) 24 | { 25 | CCAssert(dictionary, "CCJSONConverter:can not convert a null pointer"); 26 | cJSON * json = cJSON_CreateObject(); 27 | convertDictionaryToJson(dictionary, json); 28 | char* returnStr = cJSON_Print(json); 29 | cJSON_Delete(json); 30 | return returnStr; 31 | } 32 | 33 | CCDictionary * CCJSONConverter::dictionaryFrom(const char *str) 34 | { 35 | cJSON * json = cJSON_Parse(str); 36 | if (!json || json->type!=cJSON_Object) { 37 | if (json) { 38 | cJSON_Delete(json); 39 | } 40 | return NULL; 41 | } 42 | CCAssert(json && json->type==cJSON_Object, "CCJSONConverter:wrong json format"); 43 | CCDictionary * dictionary = new CCDictionary(); 44 | convertJsonToDictionary(json, dictionary); 45 | cJSON_Delete(json); 46 | return dictionary; 47 | } 48 | 49 | void CCJSONConverter::convertJsonToDictionary(cJSON *json, CCDictionary *dictionary) 50 | { 51 | dictionary->removeAllObjects(); 52 | cJSON * j = json->child; 53 | while (j) { 54 | CCObject * obj = getJsonObj(j); 55 | dictionary->setObject(obj, j->string); 56 | j = j->next; 57 | } 58 | } 59 | 60 | void CCJSONConverter::convertDictionaryToJson(CCDictionary *dictionary, cJSON *json) 61 | { 62 | CCDictElement * pElement = NULL; 63 | CCDICT_FOREACH(dictionary, pElement){ 64 | CCObject * obj = pElement->getObject(); 65 | cJSON * jsonItem = getObjJson(obj); 66 | cJSON_AddItemToObject(json, pElement->getStrKey(), jsonItem); 67 | } 68 | } 69 | 70 | void CCJSONConverter::convertJsonToArray(cJSON * json, CCArray * array) 71 | { 72 | array->removeAllObjects(); 73 | int size = cJSON_GetArraySize(json); 74 | for (int i=0; iaddObject(objItem); 78 | } 79 | } 80 | 81 | void CCJSONConverter::convertArrayToJson(CCArray * array, cJSON * json) 82 | { 83 | CCObject * obj = NULL; 84 | CCARRAY_FOREACH(array, obj){ 85 | cJSON * jsonItem = getObjJson(obj); 86 | cJSON_AddItemToArray(json, jsonItem); 87 | } 88 | } 89 | 90 | cJSON * CCJSONConverter::getObjJson(CCObject * obj) 91 | { 92 | std::string s = typeid(*obj).name(); 93 | if(s.find("CCDictionary")!=std::string::npos){ 94 | cJSON * json = cJSON_CreateObject(); 95 | convertDictionaryToJson((CCDictionary *)obj, json); 96 | return json; 97 | }else if(s.find("CCArray")!=std::string::npos){ 98 | cJSON * json = cJSON_CreateArray(); 99 | convertArrayToJson((CCArray *)obj, json); 100 | return json; 101 | }else if(s.find("CCString")!=std::string::npos){ 102 | CCString * s = (CCString *)obj; 103 | cJSON * json = cJSON_CreateString(s->getCString()); 104 | return json; 105 | }else if(s.find("CCNumber")!=std::string::npos){ 106 | CCNumber * n = (CCNumber *)obj; 107 | cJSON * json = cJSON_CreateNumber(n->getDoubleValue()); 108 | return json; 109 | }else if(s.find("CCNull")!=std::string::npos){ 110 | cJSON * json = cJSON_CreateNull(); 111 | return json; 112 | } 113 | CCLog("CCJSONConverter encountered an unrecognized type"); 114 | return NULL; 115 | } 116 | 117 | CCObject * CCJSONConverter::getJsonObj(cJSON * json) 118 | { 119 | switch (json->type) { 120 | case cJSON_Object: 121 | { 122 | CCDictionary * dictionary = new CCDictionary(); 123 | convertJsonToDictionary(json, dictionary); 124 | return dictionary; 125 | } 126 | case cJSON_Array: 127 | { 128 | CCArray * array = new CCArray(); 129 | convertJsonToArray(json, array); 130 | return array; 131 | } 132 | case cJSON_String: 133 | { 134 | CCString * string = new CCString(json->valuestring); 135 | return string; 136 | } 137 | case cJSON_Number: 138 | { 139 | CCNumber * number = new CCNumber(json->valuedouble); 140 | return number; 141 | } 142 | case cJSON_True: 143 | { 144 | CCNumber * boolean = new CCNumber(1); 145 | return boolean; 146 | } 147 | case cJSON_False: 148 | { 149 | CCNumber * boolean = new CCNumber(0); 150 | return boolean; 151 | } 152 | case cJSON_NULL: 153 | { 154 | CCNull * null = new CCNull(); 155 | return null; 156 | } 157 | default: 158 | { 159 | CCLog("CCJSONConverter encountered an unrecognized type"); 160 | return NULL; 161 | } 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/Android/JSON/CCJSONConverter.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCJSONConverter.h 3 | // cocos2d-x-jc 4 | // 5 | // Created by LIN BOYU on 11/14/12. 6 | // 7 | // 8 | 9 | #ifndef __cocos2d_x_jc__CCJSONConverter__ 10 | #define __cocos2d_x_jc__CCJSONConverter__ 11 | 12 | #include "cocos2d.h" 13 | using namespace cocos2d; 14 | #include "CCJSONData.h" 15 | #include "cJSON.h" 16 | 17 | #define CCJC_CAST_CCNUMBER(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 18 | #define CCJC_CAST_CCSTRING(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 19 | #define CCJC_CAST_CCBOOL(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 20 | #define CCJC_CAST_CCARRAY(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 21 | #define CCJC_CAST_CCDICTIONARY(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 22 | #define CCJC_CAST_CCNULL(__pDict__,__sKey__) dynamic_cast(__pDict__->objectForKey(__sKey__)) 23 | 24 | class CCJSONConverter : public CCObject { 25 | 26 | public: 27 | static CCJSONConverter * sharedConverter(); 28 | 29 | char * strFrom(CCDictionary * dictionary); 30 | 31 | CCDictionary * dictionaryFrom(const char * str); 32 | 33 | private: 34 | void convertJsonToDictionary(cJSON *json, CCDictionary *dictionary); 35 | 36 | void convertDictionaryToJson(CCDictionary *dictionary, cJSON *json); 37 | 38 | void convertJsonToArray(cJSON * json, CCArray * array); 39 | 40 | void convertArrayToJson(CCArray * array, cJSON * json); 41 | 42 | cJSON * getObjJson(CCObject * obj); 43 | 44 | CCObject * getJsonObj(cJSON * json); 45 | }; 46 | 47 | #endif /* defined(__cocos2d_x_jc__CCJSONConverter__) */ -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/Android/JSON/CCJSONData.h: -------------------------------------------------------------------------------- 1 | // 2 | // CCJSONData.h 3 | // cocos2d-x-jc 4 | // 5 | // Created by LIN BOYU on 11/14/12. 6 | // 7 | // 8 | 9 | #ifndef __cocos2d_x_jc__CCJSONData__ 10 | #define __cocos2d_x_jc__CCJSONData__ 11 | 12 | #include "cocos2d.h" 13 | using namespace cocos2d; 14 | 15 | class CCNumber : public CCObject { 16 | private: 17 | int m_nValue; 18 | double m_dValue; 19 | public: 20 | CCNumber(int v) 21 | : m_nValue(v),m_dValue(v) {} 22 | 23 | CCNumber(double v) 24 | : m_nValue(v),m_dValue(v) {} 25 | 26 | static CCNumber * create(int v) 27 | { 28 | CCNumber* pRet = new CCNumber(v); 29 | pRet->autorelease(); 30 | return pRet; 31 | } 32 | static CCNumber* create(double v) 33 | { 34 | CCNumber* pRet = new CCNumber(v); 35 | pRet->autorelease(); 36 | return pRet; 37 | } 38 | int getIntValue() const {return m_nValue;} 39 | double getDoubleValue() const {return m_dValue;} 40 | void setValue(int v) { m_nValue=v; m_dValue=v;} 41 | void setValue(double v) { m_nValue=v; m_dValue=v;} 42 | }; 43 | 44 | //class CCBool : public CCObject { 45 | //private: 46 | // bool m_bValue; 47 | //public: 48 | // CCBool(bool v) 49 | // :m_bValue(v){} 50 | // 51 | // static CCBool * create(bool v) 52 | // { 53 | // CCBool * pRet = new CCBool(v); 54 | // pRet->autorelease(); 55 | // return pRet; 56 | // } 57 | // 58 | // bool getValue() const { return m_bValue; } 59 | // void setValue(bool v) { m_bValue = v; } 60 | //}; 61 | 62 | class CCNull : public CCObject { 63 | public: 64 | static CCNull * create() 65 | { 66 | CCNull * pRet = new CCNull(); 67 | pRet->autorelease(); 68 | return pRet; 69 | } 70 | }; 71 | 72 | #endif /* defined(__cocos2d_x_jc__CCJSONData__) */ 73 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/Android/JSON/cJSON/cJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2009 Dave Gamble 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | */ 22 | 23 | #ifndef cJSON__h 24 | #define cJSON__h 25 | 26 | #ifdef __cplusplus 27 | extern "C" 28 | { 29 | #endif 30 | 31 | /* cJSON Types: */ 32 | #define cJSON_False 0 33 | #define cJSON_True 1 34 | #define cJSON_NULL 2 35 | #define cJSON_Number 3 36 | #define cJSON_String 4 37 | #define cJSON_Array 5 38 | #define cJSON_Object 6 39 | 40 | #define cJSON_IsReference 256 41 | 42 | /* The cJSON structure: */ 43 | typedef struct cJSON { 44 | struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ 45 | struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ 46 | 47 | int type; /* The type of the item, as above. */ 48 | 49 | char *valuestring; /* The item's string, if type==cJSON_String */ 50 | int valueint; /* The item's number, if type==cJSON_Number */ 51 | double valuedouble; /* The item's number, if type==cJSON_Number */ 52 | 53 | char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ 54 | } cJSON; 55 | 56 | typedef struct cJSON_Hooks { 57 | void *(*malloc_fn)(size_t sz); 58 | void (*free_fn)(void *ptr); 59 | } cJSON_Hooks; 60 | 61 | /* Supply malloc, realloc and free functions to cJSON */ 62 | extern void cJSON_InitHooks(cJSON_Hooks* hooks); 63 | 64 | 65 | /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ 66 | extern cJSON *cJSON_Parse(const char *value); 67 | /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ 68 | extern char *cJSON_Print(cJSON *item); 69 | /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ 70 | extern char *cJSON_PrintUnformatted(cJSON *item); 71 | /* Delete a cJSON entity and all subentities. */ 72 | extern void cJSON_Delete(cJSON *c); 73 | 74 | /* Returns the number of items in an array (or object). */ 75 | extern int cJSON_GetArraySize(cJSON *array); 76 | /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ 77 | extern cJSON *cJSON_GetArrayItem(cJSON *array,int item); 78 | /* Get item "string" from object. Case insensitive. */ 79 | extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); 80 | 81 | /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ 82 | extern const char *cJSON_GetErrorPtr(); 83 | 84 | /* These calls create a cJSON item of the appropriate type. */ 85 | extern cJSON *cJSON_CreateNull(); 86 | extern cJSON *cJSON_CreateTrue(); 87 | extern cJSON *cJSON_CreateFalse(); 88 | extern cJSON *cJSON_CreateBool(int b); 89 | extern cJSON *cJSON_CreateNumber(double num); 90 | extern cJSON *cJSON_CreateString(const char *string); 91 | extern cJSON *cJSON_CreateArray(); 92 | extern cJSON *cJSON_CreateObject(); 93 | 94 | /* These utilities create an Array of count items. */ 95 | extern cJSON *cJSON_CreateIntArray(int *numbers,int count); 96 | extern cJSON *cJSON_CreateFloatArray(float *numbers,int count); 97 | extern cJSON *cJSON_CreateDoubleArray(double *numbers,int count); 98 | extern cJSON *cJSON_CreateStringArray(const char **strings,int count); 99 | 100 | /* Append item to the specified array/object. */ 101 | extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); 102 | extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); 103 | /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ 104 | extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); 105 | extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); 106 | 107 | /* Remove/Detatch items from Arrays/Objects. */ 108 | extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which); 109 | extern void cJSON_DeleteItemFromArray(cJSON *array,int which); 110 | extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); 111 | extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); 112 | 113 | /* Update array items. */ 114 | extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem); 115 | extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); 116 | 117 | #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) 118 | #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) 119 | #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) 120 | #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) 121 | #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) 122 | 123 | #ifdef __cplusplus 124 | } 125 | #endif 126 | 127 | #endif 128 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/Android/ShareSDKUtils.h: -------------------------------------------------------------------------------- 1 | /* DO NOT EDIT THIS FILE - it is machine generated */ 2 | #include "AppDelegate.h" 3 | #include "cocos2d.h" 4 | #include "CCEventType.h" 5 | #include "platform/android/jni/JniHelper.h" 6 | #include 7 | #include 8 | #include "C2DXShareSDKTypeDef.h" 9 | #include "CCJSONConverter.h" 10 | 11 | USING_NS_CC; 12 | using namespace cn::sharesdk; 13 | 14 | /* Header for class ShareSDKUtils */ 15 | #ifndef _Included_ShareSDKUtils 16 | #define _Included_ShareSDKUtils 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | /* 22 | * Class: aaa_bbb_Main 23 | * Method: onJavaCallback 24 | * Signature: (Ljava/lang/String;)V 25 | */ 26 | JNIEXPORT void JNICALL Java_cn_sharesdk_ShareSDKUtils_onJavaCallback 27 | (JNIEnv * env, jclass thiz, jstring resp); 28 | 29 | void callBackComplete(int action, int platformId, CCDictionary* res); 30 | 31 | void callBackError(int action, int platformId, CCDictionary* res); 32 | 33 | void callBackCancel(int action, int platformId, CCDictionary* res); 34 | 35 | bool initShareSDK(const char* appKey, bool useAppTrusteeship); 36 | 37 | bool getMethod(JniMethodInfo &mi, const char *methodName, const char *paramCode); 38 | 39 | void releaseMethod(JniMethodInfo &mi); 40 | 41 | bool stopSDK(); 42 | 43 | bool setPlatformDevInfo(int platformId, CCDictionary *info); 44 | 45 | bool doAuthorize(int platformId, C2DXAuthResultEvent callback); 46 | 47 | bool removeAccount(int platformId); 48 | 49 | bool isValid(int platformId); 50 | 51 | bool showUser(int platformId, C2DXGetUserInfoResultEvent callback); 52 | 53 | bool doShare(int platformId, CCDictionary *content, C2DXShareResultEvent callback); 54 | 55 | bool multiShare(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback); 56 | 57 | bool onekeyShare(int platformId, CCDictionary *content, C2DXShareResultEvent callback); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | #endif 63 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/C2DXShareSDK.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // C2DXShareSDK.cpp 3 | // C2DXShareSDKSample 4 | // 5 | // Created by 冯 鸿杰 on 13-12-17. 6 | // 7 | // 8 | 9 | #include "C2DXShareSDK.h" 10 | 11 | #if CC_TARGET_PLATFORM == CC_PLATFORM_IOS 12 | 13 | #include "C2DXiOSShareSDK.h" 14 | 15 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 16 | 17 | #include "ShareSDKUtils.h" 18 | 19 | #endif 20 | 21 | using namespace cn::sharesdk; 22 | 23 | void C2DXShareSDK::open(CCString *appKey, bool useAppTrusteeship) 24 | { 25 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 26 | 27 | //TODO: Andorid 28 | initShareSDK(appKey->getCString(), useAppTrusteeship); 29 | 30 | 31 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 32 | 33 | //TODO: iOS 34 | C2DXiOSShareSDK::open(appKey, useAppTrusteeship); 35 | 36 | #endif 37 | } 38 | 39 | void C2DXShareSDK::close() 40 | { 41 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 42 | 43 | //TODO: Andorid 44 | stopSDK(); 45 | 46 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 47 | 48 | //TODO: iOS 49 | C2DXiOSShareSDK::close(); 50 | 51 | #endif 52 | } 53 | 54 | void C2DXShareSDK::setPlatformConfig(C2DXPlatType platType, CCDictionary *configInfo) 55 | { 56 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 57 | 58 | //TODO: Andorid 59 | // This is not a necessary method for Android, you can setup your platform configs more efficiently in "assets/ShareSDK.xml" 60 | // setPlatformDevInfo((int)platType, configInfo); 61 | 62 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 63 | 64 | //TODO: iOS 65 | C2DXiOSShareSDK::setPlatformConfig(platType, configInfo); 66 | 67 | #endif 68 | } 69 | 70 | void C2DXShareSDK::authorize(C2DXPlatType platType, C2DXAuthResultEvent callback) 71 | { 72 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 73 | 74 | //TODO: Andorid 75 | doAuthorize((int)platType, callback); 76 | 77 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 78 | 79 | //TODO: iOS 80 | C2DXiOSShareSDK::authorize(platType, callback); 81 | 82 | #endif 83 | } 84 | 85 | void C2DXShareSDK::cancelAuthorize(C2DXPlatType platType) 86 | { 87 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 88 | 89 | //TODO: Andorid 90 | removeAccount((int)platType); 91 | 92 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 93 | 94 | //TODO: iOS 95 | C2DXiOSShareSDK::cancelAuthorize(platType); 96 | 97 | #endif 98 | } 99 | 100 | bool C2DXShareSDK::hasAutorized(C2DXPlatType platType) 101 | { 102 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 103 | 104 | //TODO: Andorid 105 | return isValid((int)platType); 106 | 107 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 108 | 109 | //TODO: iOS 110 | return C2DXiOSShareSDK::hasAutorized(platType); 111 | 112 | #endif 113 | 114 | return false; 115 | } 116 | 117 | void C2DXShareSDK::getUserInfo(C2DXPlatType platType, C2DXGetUserInfoResultEvent callback) 118 | { 119 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 120 | 121 | //TODO: Andorid 122 | showUser((int)platType, callback); 123 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 124 | 125 | //TODO: iOS 126 | C2DXiOSShareSDK::getUserInfo(platType, callback); 127 | 128 | #endif 129 | } 130 | 131 | void C2DXShareSDK::shareContent(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback) 132 | { 133 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 134 | 135 | //TODO: Andorid 136 | doShare((int)platType, content, callback); 137 | 138 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 139 | 140 | //TODO: iOS 141 | C2DXiOSShareSDK::shareContent(platType, content, callback); 142 | 143 | #endif 144 | } 145 | 146 | void C2DXShareSDK::oneKeyShareContent(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback) 147 | { 148 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 149 | 150 | //TODO: Andorid 151 | multiShare(platTypes, content, callback); 152 | 153 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 154 | 155 | //TODO: iOS 156 | C2DXiOSShareSDK::oneKeyShareContent(platTypes, content, callback); 157 | 158 | #endif 159 | } 160 | 161 | void C2DXShareSDK::showShareMenu(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback) 162 | { 163 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 164 | 165 | //TODO: Andorid 166 | onekeyShare(0, content, callback); 167 | 168 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 169 | 170 | //TODO: iOS 171 | C2DXiOSShareSDK::showShareMenu(platTypes, content, callback); 172 | 173 | #endif 174 | } 175 | 176 | void C2DXShareSDK::showShareMenu(CCArray *platTypes, CCDictionary *content, CCPoint pt, C2DXMenuArrowDirection direction, C2DXShareResultEvent callback) 177 | { 178 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 179 | 180 | //TODO: Android 181 | showShareMenu(0, content, callback); 182 | 183 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 184 | 185 | //TODO: iOS 186 | C2DXiOSShareSDK::showShareMenu(platTypes, content, pt, direction, callback); 187 | 188 | #endif 189 | } 190 | 191 | void C2DXShareSDK::showShareView(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback) 192 | { 193 | #if CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID 194 | 195 | //TODO: Android 196 | onekeyShare((int) platType, content, callback); 197 | 198 | #elif CC_TARGET_PLATFORM == CC_PLATFORM_IOS 199 | 200 | //TODO: iOS 201 | C2DXiOSShareSDK::showShareView(platType, content, callback); 202 | 203 | #endif 204 | } 205 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/C2DXShareSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // C2DXShareSDK.h 3 | // C2DXShareSDKSample 4 | // 5 | // Created by 冯 鸿杰 on 13-12-17. 6 | // 7 | // 8 | 9 | #ifndef __C2DXShareSDKSample__C2DXShareSDK__ 10 | #define __C2DXShareSDKSample__C2DXShareSDK__ 11 | 12 | #include 13 | #include "cocos2d.h" 14 | #include "C2DXShareSDKTypeDef.h" 15 | 16 | USING_NS_CC; 17 | 18 | namespace cn 19 | { 20 | namespace sharesdk 21 | { 22 | /** 23 | * @brief ShareSDK 24 | */ 25 | class C2DXShareSDK 26 | { 27 | public: 28 | 29 | /** 30 | * @brief 初始化ShareSDK 31 | * 32 | * @param appKey 应用Key 33 | * @param useAppTrusteeship 是否使用应用信息托管 34 | */ 35 | static void open(CCString *appKey, bool useAppTrusteeship); 36 | 37 | /** 38 | * @brief 关闭ShareSDK 39 | */ 40 | static void close(); 41 | 42 | /** 43 | * @brief 设置平台配置信息 44 | * 45 | * @param platType 平台类型 46 | * @param configInfo 配置信息 47 | */ 48 | static void setPlatformConfig(C2DXPlatType platType, CCDictionary *configInfo); 49 | 50 | /** 51 | * @brief 用户授权 52 | * 53 | * @param platType 平台类型 54 | * @param callback 回调方法 55 | */ 56 | static void authorize(C2DXPlatType platType, C2DXAuthResultEvent callback); 57 | 58 | /** 59 | * @brief 取消用户授权 60 | * 61 | * @param platType 平台类型 62 | */ 63 | static void cancelAuthorize(C2DXPlatType platType); 64 | 65 | /** 66 | * @brief 用户是否授权 67 | * 68 | * @param platType 平台类型 69 | * 70 | * @return true 已授权, false 尚未授权 71 | */ 72 | static bool hasAutorized(C2DXPlatType platType); 73 | 74 | /** 75 | * @brief 获取用户信息 76 | * 77 | * @param platType 平台类型 78 | * @param callback 回调方法 79 | */ 80 | static void getUserInfo(C2DXPlatType platType, C2DXGetUserInfoResultEvent callback); 81 | 82 | /** 83 | * @brief 分享内容 84 | * 85 | * @param platType 平台类型 86 | * @param content 分享内容 87 | * @param callback 回调方法 88 | */ 89 | static void shareContent(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback); 90 | 91 | /** 92 | * @brief 一键分享内容 93 | * 94 | * @param platTypes 平台类型列表 95 | * @param content 分享内容 96 | * @param callback 回调方法 97 | */ 98 | static void oneKeyShareContent(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback); 99 | 100 | /** 101 | * @brief 显示分享菜单 102 | * 103 | * @param platTypes 平台类型列表 104 | * @param content 分享内容 105 | * @param callback 回调方法 106 | */ 107 | static void showShareMenu(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback); 108 | 109 | /** 110 | * @brief 显示分享菜单 111 | * 112 | * @param platTypes 平台类型列表 113 | * @param content 分享内容 114 | * @param pt 弹出分享菜单的位置,仅用于设置iPad分享菜单弹出 115 | * @param direction 弹出分享菜单指向,仅用于设置iPad分享菜单弹出 116 | * @param callback 回调方法 117 | */ 118 | static void showShareMenu(CCArray *platTypes, CCDictionary *content, CCPoint pt, C2DXMenuArrowDirection direction, C2DXShareResultEvent callback); 119 | 120 | /** 121 | * @brief 显示分享视图 122 | * 123 | * @param platType 平台类型 124 | * @param content 分享内容 125 | * @param callback 回调方法 126 | */ 127 | static void showShareView(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback); 128 | 129 | 130 | }; 131 | } 132 | } 133 | 134 | 135 | 136 | #endif /* defined(__C2DXShareSDKSample__C2DXShareSDK__) */ 137 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/C2DXShareSDKTypeDef.h: -------------------------------------------------------------------------------- 1 | // 2 | // C2DXShareSDKTypeDef.h 3 | // C2DXShareSDKSample 4 | // 5 | // Created by 冯 鸿杰 on 13-12-17. 6 | // 7 | // 8 | 9 | #ifndef C2DXShareSDKSample_C2DXShareSDKTypeDef_h 10 | #define C2DXShareSDKSample_C2DXShareSDKTypeDef_h 11 | 12 | #include "cocos2d.h" 13 | #include 14 | 15 | USING_NS_CC; 16 | 17 | namespace cn 18 | { 19 | namespace sharesdk 20 | { 21 | /** 22 | * @brief 平台类型 23 | */ 24 | enum C2DXPlatType 25 | { 26 | C2DXPlatTypeSinaWeibo = 1, /**< 新浪微博 */ 27 | C2DXPlatTypeTencentWeibo = 2, /**< 腾讯微博 */ 28 | C2DXPlatTypeSohuWeibo = 3, /**< 搜狐微博 */ 29 | C2DXPlatType163Weibo = 4, /**< 网易微博 */ 30 | C2DXPlatTypeDouBan = 5, /**< 豆瓣社区 */ 31 | C2DXPlatTypeQZone = 6, /**< QQ空间 */ 32 | C2DXPlatTypeRenren = 7, /**< 人人网 */ 33 | C2DXPlatTypeKaixin = 8, /**< 开心网 */ 34 | C2DXPlatTypePengyou = 9, /**< 朋友网 */ 35 | C2DXPlatTypeFacebook = 10, /**< Facebook */ 36 | C2DXPlatTypeTwitter = 11, /**< Twitter */ 37 | C2DXPlatTypeEvernote = 12, /**< 印象笔记 */ 38 | C2DXPlatTypeFoursquare = 13, /**< Foursquare */ 39 | C2DXPlatTypeGooglePlus = 14, /**< Google+ */ 40 | C2DXPlatTypeInstagram = 15, /**< Instagram */ 41 | C2DXPlatTypeLinkedIn = 16, /**< LinkedIn */ 42 | C2DXPlatTypeTumblr = 17, /**< Tumbir */ 43 | C2DXPlatTypeMail = 18, /**< 邮件分享 */ 44 | C2DXPlatTypeSMS = 19, /**< 短信分享 */ 45 | C2DXPlatTypeAirPrint = 20, /**< 打印 */ 46 | C2DXPlatTypeCopy = 21, /**< 拷贝 */ 47 | C2DXPlatTypeWeixiSession = 22, /**< 微信好友 */ 48 | C2DXPlatTypeWeixiTimeline = 23, /**< 微信朋友圈 */ 49 | C2DXPlatTypeQQ = 24, /**< QQ */ 50 | C2DXPlatTypeInstapaper = 25, /**< Instapaper */ 51 | C2DXPlatTypePocket = 26, /**< Pocket */ 52 | C2DXPlatTypeYouDaoNote = 27, /**< 有道云笔记 */ 53 | C2DXPlatTypeSohuKan = 28, /**< 搜狐随身看 */ 54 | C2DXPlatTypePinterest = 30, /**< Pinterest */ 55 | C2DXPlatTypeFlickr = 34, /**< Flickr */ 56 | C2DXPlatTypeDropbox = 35, /**< Dropbox */ 57 | C2DXPlatTypeVKontakte = 36, /**< VKontakte */ 58 | C2DXPlatTypeWeixiFav = 37, /**< 微信收藏 */ 59 | C2DXPlatTypeYiXinSession = 38, /**< 易信好友 */ 60 | C2DXPlatTypeYiXinTimeline = 39, /**< 易信朋友圈 */ 61 | C2DXPlatTypeYiXinFav = 40, /**< 易信收藏 */ 62 | C2DXPlatTypeAny = 99 /**< 任意平台 */ 63 | }; 64 | 65 | /** 66 | * @brief 内容类型 67 | */ 68 | enum C2DXContentType 69 | { 70 | C2DXContentTypeText = 0, /**< 文本 */ 71 | C2DXContentTypeImage = 1, /**< 图片 */ 72 | C2DXContentTypeNews = 2, /**< 新闻 */ 73 | C2DXContentTypeMusic = 3, /**< 音乐 */ 74 | C2DXContentTypeVideo = 4, /**< 视频 */ 75 | C2DXContentTypeApp = 5, /**< 应用,仅供微信使用 */ 76 | C2DXContentTypeNonGif = 6, /**< 非Gif消息,仅供微信使用 */ 77 | C2DXContentTypeGif = 7, /**< Gif消息,仅供微信使用 */ 78 | C2DXContentTypeFile = 8 /**< 文件消息,仅供微信使用 */ 79 | }; 80 | 81 | /** 82 | * @brief 返回状态 83 | */ 84 | enum C2DXResponseState 85 | { 86 | C2DXResponseStateBegin = 0, /**< 开始 */ 87 | C2DXResponseStateSuccess = 1, /**< 成功 */ 88 | C2DXResponseStateFail = 2, /**< 失败 */ 89 | C2DXResponseStateCancel = 3 /**< 取消 */ 90 | }; 91 | 92 | /** 93 | * @brief 分享菜单指向 94 | */ 95 | enum C2DXMenuArrowDirection 96 | { 97 | C2DXMenuArrowDirectionUp = 1UL << 0, /**< 向上 */ 98 | C2DXMenuArrowDirectionDown = 1UL << 1, /**< 向下 */ 99 | C2DXMenuArrowDirectionLeft = 1UL << 2, /**< 向左 */ 100 | C2DXMenuArrowDirectionRight = 1UL << 3, /**< 向右 */ 101 | C2DXMenuArrowDirectionAny = C2DXMenuArrowDirectionUp | C2DXMenuArrowDirectionDown | C2DXMenuArrowDirectionLeft | C2DXMenuArrowDirectionRight, /**< 任意 */ 102 | C2DXMenuArrowDirectionUnknown = UINT32_MAX /**< 未知 */ 103 | }; 104 | 105 | /** 106 | * @brief 授权返回回调事件 107 | */ 108 | typedef void(*C2DXAuthResultEvent) (C2DXResponseState state, C2DXPlatType platType, CCDictionary *error); 109 | 110 | /** 111 | * @brief 获取用户信息返回回调事件 112 | */ 113 | typedef void(*C2DXGetUserInfoResultEvent) (C2DXResponseState state, C2DXPlatType platType, CCDictionary *userInfo, CCDictionary *error); 114 | 115 | /** 116 | * @brief 分享返回回调事件 117 | */ 118 | typedef void(*C2DXShareResultEvent) (C2DXResponseState state, C2DXPlatType platType, CCDictionary *shareInfo, CCDictionary *error); 119 | } 120 | } 121 | 122 | #endif 123 | -------------------------------------------------------------------------------- /Classes/C2DXShareSDK/ios/C2DXiOSShareSDK.h: -------------------------------------------------------------------------------- 1 | // 2 | // C2DXiOSShareSDK.h 3 | // C2DXShareSDKSample 4 | // 5 | // Created by 冯 鸿杰 on 13-12-17. 6 | // 7 | // 8 | 9 | #ifndef __C2DXShareSDKSample__C2DXiOSShareSDK__ 10 | #define __C2DXShareSDKSample__C2DXiOSShareSDK__ 11 | 12 | #include 13 | #include "cocos2d.h" 14 | #include "C2DXShareSDKTypeDef.h" 15 | 16 | USING_NS_CC; 17 | 18 | namespace cn 19 | { 20 | namespace sharesdk 21 | { 22 | /** 23 | * @brief ShareSDK (iOS) 24 | */ 25 | class C2DXiOSShareSDK 26 | { 27 | public: 28 | 29 | /** 30 | * @brief 初始化ShareSDK 31 | * 32 | * @param appKey 应用Key 33 | * @param useAppTrusteeship 是否使用应用信息托管 34 | */ 35 | static void open(CCString *appKey, bool useAppTrusteeship); 36 | 37 | /** 38 | * @brief 关闭ShareSDK 39 | */ 40 | static void close(); 41 | 42 | /** 43 | * @brief 设置平台配置信息 44 | * 45 | * @param platType 平台类型 46 | * @param configInfo 配置信息 47 | */ 48 | static void setPlatformConfig(C2DXPlatType platType, CCDictionary *configInfo); 49 | 50 | /** 51 | * @brief 用户授权 52 | * 53 | * @param platType 平台类型 54 | * @param callback 回调方法 55 | */ 56 | static void authorize(C2DXPlatType platType, C2DXAuthResultEvent callback); 57 | 58 | /** 59 | * @brief 取消用户授权 60 | * 61 | * @param platType 平台类型 62 | */ 63 | static void cancelAuthorize(C2DXPlatType platType); 64 | 65 | /** 66 | * @brief 用户是否授权 67 | * 68 | * @param platType 平台类型 69 | * 70 | * @return true 已授权, false 尚未授权 71 | */ 72 | static bool hasAutorized(C2DXPlatType platType); 73 | 74 | /** 75 | * @brief 获取用户信息 76 | * 77 | * @param platType 平台类型 78 | * @param callback 回调方法 79 | */ 80 | static void getUserInfo(C2DXPlatType platType, C2DXGetUserInfoResultEvent callback); 81 | 82 | /** 83 | * @brief 分享内容 84 | * 85 | * @param platType 平台类型 86 | * @param content 分享内容 87 | * @param callback 回调方法 88 | */ 89 | static void shareContent(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback); 90 | 91 | /** 92 | * @brief 一键分享内容 93 | * 94 | * @param platTypes 平台类型列表 95 | * @param content 分享内容 96 | * @param callback 回调方法 97 | */ 98 | static void oneKeyShareContent(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback); 99 | 100 | /** 101 | * @brief 显示分享菜单 102 | * 103 | * @param platTypes 平台类型列表 104 | * @param content 分享内容 105 | * @param callback 回调方法 106 | */ 107 | static void showShareMenu(CCArray *platTypes, CCDictionary *content, C2DXShareResultEvent callback); 108 | 109 | /** 110 | * @brief 显示分享菜单 111 | * 112 | * @param platTypes 平台类型列表 113 | * @param content 分享内容 114 | * @param pt 弹出分享菜单参位置,仅用于设置iPad分享菜单弹出 115 | * @param direction 弹出分享菜单指向,仅用于设置iPad分享菜单弹出 116 | * @param callback 回调方法 117 | */ 118 | static void showShareMenu(CCArray *platTypes, CCDictionary *content, CCPoint pt, C2DXMenuArrowDirection direction, C2DXShareResultEvent callback); 119 | 120 | 121 | /** 122 | * @brief 显示分享视图 123 | * 124 | * @param platType 平台类型 125 | * @param content 分享内容 126 | * @param callback 回调方法 127 | */ 128 | static void showShareView(C2DXPlatType platType, CCDictionary *content, C2DXShareResultEvent callback); 129 | }; 130 | } 131 | } 132 | 133 | #endif /* defined(__C2DXShareSDKSample__C2DXiOSShareSDK__) */ 134 | -------------------------------------------------------------------------------- /Classes/Chessboard.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Chessboard.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-20. 6 | // 7 | // 8 | 9 | #include "Chessboard.h" 10 | #include "Message.h" 11 | #include "ChessboardChecker.h" 12 | 13 | #include 14 | 15 | Chessboard::~Chessboard(){ 16 | // cocos2d::CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 17 | } 18 | 19 | bool Chessboard::init(){ 20 | 21 | // 状态机实现 22 | Model::addTransition("start", BEGIN_MOVE_MSG, "moving") 23 | ->addTransition("start", REGRET_MSG, "back_moving") 24 | 25 | ->addTransition("start", AI_REGRET_MSG, "ai_back_moving") 26 | ->addTransition("ai_back_moving", AI_END_MOVE_MSG, "start") 27 | 28 | ->addTransition("back_moving", END_MOVE_MSG, "start") 29 | ->addTransition("moving", END_MOVE_MSG, "judge_eat") 30 | ->addTransition("judge_eat", NEXT_ROUND_MSG, "start") 31 | ->addTransition("judge_eat", BEGIN_EAT_MSG, "eating") 32 | ->addTransition("eating", END_EAT_MSG, "judge_win") 33 | ->addTransition("judge_win", NEXT_ROUND_MSG, "start") 34 | ->addTransition("judge_win", WIN_MSG, "win"); 35 | 36 | PIECE _pieces[][WIDTH] = { 37 | { BLACK, BLACK, BLACK, BLACK }, 38 | { ZERO, ZERO, ZERO, ZERO }, 39 | { ZERO, ZERO, ZERO, ZERO }, 40 | { WHITE, WHITE, WHITE, WHITE } 41 | }; 42 | 43 | Pieces2Data(_pieces, pieces); 44 | 45 | using namespace cocos2d; 46 | 47 | // Add Listeners 48 | 49 | return true; 50 | } 51 | 52 | bool Chessboard::checkWin(const Move &move){ 53 | return ::checkWin(pieces, move); 54 | } 55 | 56 | // 检查能否让某一方获胜,并且分发获胜事件 57 | void Chessboard::alterWin(){ 58 | this->onMessage(WIN_MSG); 59 | } 60 | 61 | bool Chessboard::checkEat(Move& move){ 62 | return ::checkEat(pieces, move); 63 | } 64 | 65 | // 检测能否吃掉一个棋子 66 | void Chessboard::alterEat(const Move& move){ 67 | currentMove.eatenPoints = move.eatenPoints; 68 | std::vector& eatenPoints = currentMove.eatenPoints; 69 | 70 | 71 | for (auto point : eatenPoints) { 72 | this->setPiece(point, ZERO); 73 | } 74 | 75 | 76 | this->onMessage(BEGIN_EAT_MSG); 77 | 78 | } 79 | 80 | 81 | bool Chessboard::checkMove(const Move &move){ 82 | return ::checkMove(this->pieces, move); 83 | } 84 | 85 | // 检测这一步是否能走,并且修改当前Point的值 86 | void Chessboard::alterMove(const Move& move){ 87 | 88 | currentMove.src = move.src; 89 | currentMove.dest = move.dest; 90 | currentMove.eatenPoints.clear(); 91 | 92 | // 将currentPoint的值改为目标位置的值 93 | this->setPiece(currentMove.src, ZERO); 94 | this->setPiece(currentMove.dest, currentMove.currentRound); 95 | 96 | this->onMessage(BEGIN_MOVE_MSG); 97 | } 98 | 99 | void Chessboard::setPiece(const cocos2d::CCPoint& p, PIECE type){ 100 | pieces[p.y][p.x] = type; 101 | } 102 | 103 | PIECE Chessboard::getPiece(const cocos2d::CCPoint& p){ 104 | return pieces[p.y][p.x]; 105 | } 106 | 107 | void Chessboard::setPieces(PIECE _pieces[][WIDTH]){ 108 | for (int i = 0; i < HEIGHT; ++i) { 109 | for (int j = 0; j < WIDTH; ++j) { 110 | if (getPiece(ccp(j, i)) != ZERO ) 111 | currentMove.eatenPoints.push_back(ccp(j, i)); 112 | } 113 | } 114 | cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(BEGIN_EAT_MSG); 115 | pieces.clear(); 116 | Pieces2Data(_pieces, pieces); 117 | return ; 118 | } 119 | 120 | void Chessboard::setPieces(const ChessboardData& data ){ 121 | currentMove.eatenPoints.clear(); 122 | for (int i = 0; i < HEIGHT; ++i) { 123 | for (int j = 0; j < WIDTH; ++j) { 124 | if (getPiece(ccp(j, i)) != ZERO ) 125 | currentMove.eatenPoints.push_back(ccp(j, i)); 126 | } 127 | } 128 | cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(BEGIN_EAT_MSG); 129 | pieces.clear(); 130 | pieces = data; 131 | return; 132 | } 133 | 134 | void Chessboard::alterNextRound(){ 135 | Move move(currentMove); 136 | moves.push(move); 137 | currentMove.currentRound = oppositePiece(currentMove.currentRound); 138 | currentMove.src = ccp(-1, -1); 139 | currentMove.dest = ccp(-1, -1); 140 | currentMove.eatenPoints.clear(); 141 | 142 | this->onMessage(NEXT_ROUND_MSG, this); 143 | } 144 | 145 | 146 | void Chessboard::alterRegret(){ 147 | if (moves.empty()) 148 | return; 149 | currentMove = moves.top(); 150 | moves.pop(); 151 | for (CCPoint p : currentMove.eatenPoints) { 152 | setPiece(p, oppositePiece(currentMove.currentRound)); 153 | } 154 | setPiece(currentMove.dest, ZERO); 155 | setPiece(currentMove.src, currentMove.currentRound); 156 | this->onMessage(REGRET_MSG); 157 | } 158 | 159 | void Chessboard::alterAIRegret(){ 160 | if (moves.empty()) 161 | return; 162 | currentMove = moves.top(); 163 | moves.pop(); 164 | for (CCPoint p : currentMove.eatenPoints) { 165 | setPiece(p, oppositePiece(currentMove.currentRound)); 166 | } 167 | setPiece(currentMove.dest, ZERO); 168 | setPiece(currentMove.src, currentMove.currentRound); 169 | this->onMessage(AI_REGRET_MSG); 170 | } 171 | 172 | void Chessboard::alterLose(){ 173 | this->onMessage(LOSE_MSG); 174 | } 175 | 176 | 177 | -------------------------------------------------------------------------------- /Classes/Chessboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // Chessboard.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-20. 6 | // 7 | // 8 | 9 | #ifndef __Four__Chessboard__ 10 | #define __Four__Chessboard__ 11 | 12 | #include "Model.h" 13 | #include "ChessboardProtocol.h" 14 | #include "Message.h" 15 | 16 | #include 17 | #include 18 | using std::vector; 19 | using std::stack; 20 | 21 | #include "cocos2d.h" 22 | using cocos2d::CCArray; 23 | using cocos2d::CCPoint; 24 | 25 | class Chessboard : public Model { 26 | CC_SYNTHESIZE_PASS_BY_REF(Move, currentMove, CurrentMove); 27 | CC_SYNTHESIZE_READONLY_PASS_BY_REF(ChessboardData, pieces, Pieces) 28 | 29 | private: 30 | // 棋盘代表了存储棋子类型的二维数组 31 | stack< Move > moves; 32 | 33 | void setPiece(const cocos2d::CCPoint& p, PIECE type); 34 | 35 | public: 36 | explicit Chessboard():Model("start"),currentMove(BLACK, ccp(-1, -1), ccp(-1, -1)){} 37 | 38 | virtual ~Chessboard(); 39 | bool init(); 40 | 41 | CREATE_FUNC(Chessboard); 42 | 43 | // 检查能否让某一方获胜,并且分发获胜事件 44 | bool checkWin(const Move& move); 45 | void alterWin(); 46 | void alterLose(); 47 | 48 | // 检测能否吃掉一个棋子,并且将棋盘模型进行改变 49 | bool checkEat(Move& move); 50 | void alterEat(const Move& move); 51 | 52 | // 检测这一步是否能走,并且将棋盘模型进行改变 53 | bool checkMove(const Move& move); 54 | void alterMove(const Move& move); 55 | 56 | void alterNextRound(); 57 | void alterRegret(); 58 | void alterAIRegret(); 59 | 60 | // for test, not recommend to use 61 | void setPieces(PIECE _pieces[][WIDTH]); 62 | void setPieces(const ChessboardData& data ); 63 | PIECE getPiece(const cocos2d::CCPoint& p); 64 | 65 | }; 66 | 67 | #endif /* defined(__Four__Chessboard__) */ 68 | -------------------------------------------------------------------------------- /Classes/ChessboardChecker.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardChecker.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-26. 6 | // 7 | // 8 | 9 | #include "ChessboardChecker.h" 10 | 11 | #include 12 | #include 13 | 14 | using std::vector; 15 | 16 | bool inbound(const CCPoint& p, int width, int height){ 17 | return p.x >= 0 && p.y >= 0 && p.x < width && p.y < height; 18 | } 19 | 20 | bool inbound(const CCPoint& p){ 21 | return inbound(p, WIDTH, HEIGHT); 22 | } 23 | 24 | PIECE oppositePiece(PIECE p){ 25 | return (p == BLACK ? WHITE : BLACK); 26 | } 27 | 28 | PIECE getPiece(const ChessboardData& pieces, const cocos2d::CCPoint& p){ 29 | return pieces[p.y][p.x]; 30 | } 31 | 32 | bool checkWin( const ChessboardData& pieces, const Move& move ){ 33 | PIECE enemyRound = oppositePiece(move.currentRound); 34 | int cnt = 0; 35 | for (int i = 0; i < HEIGHT; ++i) { 36 | for (int j = 0; j < WIDTH; ++j) { 37 | if (pieces[i][j] == enemyRound) 38 | cnt++; 39 | } 40 | } 41 | if (cnt < 2) 42 | return true; 43 | return false; 44 | } 45 | 46 | bool checkMove( const ChessboardData& pieces, const Move& move ){ 47 | 48 | if ( inbound(move.src) && inbound(move.dest) && getPiece(pieces, move.src) == move.currentRound && getPiece(pieces, move.dest) == ZERO && (move.dest.x - (floor)(move.dest.x)) == 0) 49 | return true; 50 | return false; 51 | } 52 | 53 | bool checkEat( const ChessboardData& pieces, Move& move ){ 54 | cocos2d::CCPoint currentPoint = move.dest; 55 | PIECE currentRound = move.currentRound; 56 | std::vector& eatenPoints = move.eatenPoints; 57 | 58 | cocos2d::CCPoint directions[4] = {ccp(1, 0), ccp(-1, 0), ccp(0, 1), ccp(0, -1)}; 59 | for(auto direction : directions){ 60 | CCPoint first = currentPoint + direction; 61 | if (inbound(first) && getPiece(pieces, first) == currentRound){ 62 | CCPoint second = currentPoint + direction * 2; 63 | if (inbound(second)){ 64 | CCPoint third = currentPoint + direction * 3; 65 | if (inbound(third)) { 66 | if (getPiece(pieces, second) == oppositePiece(currentRound) && getPiece(pieces, third) == ZERO){ 67 | eatenPoints.push_back(second); 68 | } 69 | }else{ 70 | third = currentPoint - direction; 71 | if ((getPiece(pieces, second) == oppositePiece(currentRound) && getPiece(pieces, third) == ZERO)){ 72 | eatenPoints.push_back(second); 73 | }else if (getPiece(pieces, third) == oppositePiece(currentRound) && getPiece(pieces, second) == ZERO){ 74 | eatenPoints.push_back(third); 75 | } 76 | } 77 | }else{ 78 | second = currentPoint - direction; 79 | CCPoint third = currentPoint - direction * 2; 80 | if (getPiece(pieces, second) == oppositePiece(currentRound) && getPiece(pieces, third) == ZERO){ 81 | eatenPoints.push_back(second); 82 | } 83 | } 84 | } 85 | } 86 | CCLOG("size : %lu", eatenPoints.size()); 87 | 88 | 89 | if (eatenPoints.size() == 0) 90 | return false; 91 | logPoint(eatenPoints[0]); 92 | return true; 93 | } 94 | -------------------------------------------------------------------------------- /Classes/ChessboardChecker.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardChecker.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-26. 6 | // 7 | // 8 | 9 | #ifndef __Four__ChessboardChecker__ 10 | #define __Four__ChessboardChecker__ 11 | 12 | #include "ChessboardProtocol.h" 13 | 14 | bool inbound(const CCPoint& p); 15 | 16 | PIECE getPiece(const ChessboardData& pieces, const cocos2d::CCPoint& p); 17 | 18 | PIECE oppositePiece(PIECE p); 19 | 20 | bool checkMove( const ChessboardData& pieces, const Move& move ); 21 | 22 | bool checkEat( const ChessboardData& pieces, Move& move ); 23 | 24 | bool checkWin( const ChessboardData& pieces, const Move& move ); 25 | 26 | #endif /* defined(__Four__ChessboardChecker__) */ 27 | -------------------------------------------------------------------------------- /Classes/ChessboardController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-24. 6 | // 7 | // 8 | 9 | #include "ChessboardController.h" 10 | #include "PieceView.h" 11 | #include "LogoView.h" 12 | #include "Chessboard.h" 13 | #include "RotFlowerParticle.h" 14 | #include "ChessboardProtocol.h" 15 | #include "Tag.h" 16 | 17 | 18 | 19 | ChessboardController::~ChessboardController(){ 20 | CC_SAFE_RELEASE(chessboard); 21 | CC_SAFE_RELEASE(modeLabel); 22 | } 23 | 24 | void ChessboardController::initPieceViews(){ 25 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 26 | 27 | for (int i = 0; i < HEIGHT; ++i) { 28 | for (int j = 0; j < WIDTH; ++j) { 29 | CCString* frame_name; 30 | if (chessboard->getPiece(ccp(j, i)) == BLACK ) 31 | frame_name = new CCString("black.png"); 32 | else if (chessboard->getPiece(ccp(j, i)) == WHITE) 33 | frame_name = new CCString("white.png"); 34 | else 35 | continue; 36 | CCSprite* black = PieceView::create(&(this->chessboard->getCurrentMove()), this->chessboard, cache->spriteFrameByName(frame_name->getCString()), ccp(j, i)); 37 | this->addChild(black); 38 | } 39 | } 40 | } 41 | 42 | bool ChessboardController::init(){ 43 | using namespace cocos2d; 44 | 45 | if (! BaseController::init()) { 46 | return false; 47 | } 48 | 49 | // 初始化Model 50 | this->chessboard = Chessboard::create(); 51 | this->chessboard->retain(); 52 | 53 | // PIECE _pieces[4][4] = { 54 | // {ZERO, WHITE, ZERO, BLACK}, 55 | // {ZERO, ZERO, WHITE, BLACK}, 56 | // {ZERO, ZERO, ZERO, ZERO}, 57 | // {ZERO, ZERO, ZERO, ZERO} 58 | // }; 59 | 60 | // chessboard->setPieces(_pieces); 61 | 62 | //初始化View 63 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 64 | 65 | initPieceViews(); 66 | 67 | CCSprite* black_logo = LogoView::create(&(this->chessboard->getCurrentMove()), cache->spriteFrameByName("black_logo.png"), BLACK); 68 | black_logo->setTag(ROUND_BLACK); 69 | CCSprite* white_logo = LogoView::create(&(this->chessboard->getCurrentMove()), cache->spriteFrameByName("white_logo.png"), WHITE); 70 | white_logo->setTag(ROUND_WHITE); 71 | this->addChild(black_logo); 72 | this->addChild(white_logo); 73 | 74 | modeLabel = CCLabelTTF::create("人人对战", "Helvetica-Bold", 32.0f); 75 | modeLabel->setColor(ccBLACK); 76 | modeLabel->setPosition(ccp(320, 1050)); 77 | CC_SAFE_RETAIN(modeLabel); 78 | this->addChild(modeLabel); 79 | 80 | return true; 81 | } 82 | 83 | 84 | void ChessboardController::onEnter() 85 | { 86 | using cocos2d::CCDirector; 87 | 88 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ChessboardController::tryEat), END_MOVE_MSG, NULL); 89 | 90 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ChessboardController::tryWin), END_EAT_MSG, NULL); 91 | 92 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ChessboardController::tryRegret), CLICK_REGRET_MSG, nullptr); 93 | 94 | // this->setTouchEnabled(true); 95 | CCDirector* pDirector = CCDirector::sharedDirector(); 96 | pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); 97 | CCLayer::onEnter(); 98 | } 99 | 100 | void ChessboardController::onExit() 101 | { 102 | using cocos2d::CCDirector; 103 | 104 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 105 | 106 | CCDirector* pDirector = CCDirector::sharedDirector(); 107 | pDirector->getTouchDispatcher()->removeDelegate(this); 108 | CCLayer::onExit(); 109 | } 110 | 111 | bool ChessboardController::ccTouchBegan(CCTouch* touch, CCEvent* event) 112 | { 113 | return true; 114 | } 115 | 116 | void ChessboardController::ccTouchMoved(CCTouch* touch, CCEvent* event) 117 | { 118 | // CCTouchDelegate 119 | } 120 | 121 | void ChessboardController::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){ 122 | logPoint(pTouch->getStartLocation()); 123 | tryMove(RealToLogic(pTouch->getStartLocation()), RealToLogic(pTouch->getLocation())); 124 | } 125 | 126 | void ChessboardController::tryMove(const CCPoint& src, const CCPoint& dest){ 127 | if (dest.equals(src)) 128 | return; 129 | CCPoint newDest = (dest - src) / (dest - src).getLength() + src; 130 | Move move(chessboard->getCurrentMove().currentRound,src, newDest); 131 | if(chessboard->checkMessage(BEGIN_MOVE_MSG) && chessboard->checkMove(move)){ 132 | chessboard->alterMove(move); 133 | } 134 | 135 | } 136 | 137 | void ChessboardController::tryEat(CCObject* o){ 138 | 139 | Move move(chessboard->getCurrentMove()); 140 | if(chessboard->checkMessage(BEGIN_EAT_MSG)){ 141 | if (chessboard->checkEat(move)){ 142 | chessboard->alterEat(move); 143 | }else{ 144 | chessboard->alterNextRound(); 145 | } 146 | } 147 | } 148 | 149 | void ChessboardController::tryWin(CCObject* o){ 150 | if (chessboard->checkMessage(WIN_MSG)) { 151 | if (chessboard->checkWin(chessboard->getCurrentMove())){ 152 | chessboard->alterWin(); 153 | this->addChild(RotFlowerParticle::create()); 154 | }else{ 155 | chessboard->alterNextRound(); 156 | } 157 | } 158 | } 159 | 160 | void ChessboardController::tryRegret(cocos2d::CCObject *o){ 161 | if (chessboard->checkMessage(REGRET_MSG)){ 162 | chessboard->alterRegret(); 163 | 164 | CCString* frame_name = ( chessboard->getCurrentMove().currentRound == WHITE ) ? CCString::create("black.png") : CCString::create("white.png"); 165 | 166 | for (CCPoint p : chessboard->getCurrentMove().eatenPoints) { 167 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 168 | CCSprite* piece = PieceView::create(&(this->chessboard->getCurrentMove()), this->chessboard, cache->spriteFrameByName(frame_name->getCString()), p); 169 | this->addChild(piece); 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /Classes/ChessboardController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-24. 6 | // 7 | // 8 | 9 | #ifndef __Four__ChessboardController__ 10 | #define __Four__ChessboardController__ 11 | 12 | #include "ChessboardProtocol.h" 13 | #include "BaseController.h" 14 | 15 | #include "cocos2d.h" 16 | 17 | using cocos2d::CCTouch; 18 | using cocos2d::CCEvent; 19 | 20 | class Chessboard; 21 | 22 | using cocos2d::CCLayer; 23 | 24 | class ChessboardController : public BaseController { 25 | protected: 26 | Chessboard* chessboard; 27 | CCLabelTTF* modeLabel; 28 | 29 | void initPieceViews(); 30 | 31 | public: 32 | virtual bool init(); 33 | virtual ~ChessboardController(); 34 | 35 | CREATE_FUNC(ChessboardController); 36 | 37 | virtual void onEnter(); 38 | virtual void onExit(); 39 | 40 | virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event); 41 | virtual void ccTouchMoved(CCTouch* touch, CCEvent* event); 42 | virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); 43 | 44 | // try方法, 向Model请求进行操作 45 | virtual void tryMove(const CCPoint& src, const CCPoint& dest); 46 | virtual void tryEat(CCObject* o); 47 | virtual void tryWin(CCObject* o); 48 | virtual void tryRegret(CCObject* o); 49 | }; 50 | 51 | 52 | 53 | #endif /* defined(__Four__ChessboardController__) */ 54 | -------------------------------------------------------------------------------- /Classes/ChessboardProtocol.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardProtocol.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-26. 6 | // 7 | // 8 | 9 | #include "ChessboardProtocol.h" 10 | 11 | void Pieces2Data(PIECE _pieces[][WIDTH], ChessboardData& data){ 12 | for (int i = 0; i < HEIGHT; ++i) { 13 | data.push_back(std::vector(_pieces[i], _pieces[i] + WIDTH)); 14 | } 15 | } 16 | 17 | CCPoint LogicToReal(const cocos2d::CCPoint& p){ 18 | return ccp(X_OFFSET + p.x * PIECE_WIDTH, Y_OFFSET + p.y * PIECE_HEIGHT); 19 | } 20 | 21 | CCPoint RealToLogic(const cocos2d::CCPoint& p){ 22 | return ccp(round((p.x - X_OFFSET) / PIECE_WIDTH ), round((p.y - Y_OFFSET) / PIECE_HEIGHT)); 23 | } 24 | 25 | void Move::operator=(const Move &_move){ 26 | this->currentRound = _move.currentRound; 27 | this->src = _move.src; 28 | this->dest = _move.dest; 29 | this->eatenPoints = _move.eatenPoints; 30 | } 31 | 32 | void logPoint(const cocos2d::CCPoint& p){ 33 | CCLOG("x:%f y:%f", p.x, p.y); 34 | } -------------------------------------------------------------------------------- /Classes/ChessboardProtocol.h: -------------------------------------------------------------------------------- 1 | // 2 | // ChessboardProtocol.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-20. 6 | // 7 | // 8 | 9 | #ifndef Four_ChessboardProtocol_h 10 | #define Four_ChessboardProtocol_h 11 | 12 | #include "cocos2d.h" 13 | using cocos2d::CCPoint; 14 | 15 | typedef enum { 16 | ZERO, 17 | BLACK, 18 | WHITE, 19 | } PIECE; 20 | 21 | const int WIDTH = 4; 22 | const int HEIGHT = 4; 23 | const int PIECE_NUM = 4; 24 | 25 | const int PIECE_WIDTH = 128; 26 | const int PIECE_HEIGHT = 128; 27 | 28 | const int X_OFFSET = 128; 29 | const int Y_OFFSET = 288; 30 | 31 | struct Move { 32 | PIECE currentRound; 33 | CCPoint src; 34 | CCPoint dest; 35 | std::vector eatenPoints; 36 | Move(PIECE _p):currentRound(_p){} 37 | Move(PIECE _p,const cocos2d::CCPoint& _src, const cocos2d::CCPoint& _dest):currentRound(_p),src(_src),dest(_dest){} 38 | Move(const cocos2d::CCPoint& _src, const cocos2d::CCPoint& _dest):src(_src),dest(_dest){} 39 | Move(const Move& _move):currentRound(_move.currentRound),src(_move.src),dest(_move.dest),eatenPoints(_move.eatenPoints){} 40 | void operator=(const Move& _move); 41 | }; 42 | 43 | typedef std::vector< std::vector > ChessboardData; 44 | 45 | void Pieces2Data(PIECE _pieces[][WIDTH], ChessboardData& data); 46 | 47 | CCPoint LogicToReal(const cocos2d::CCPoint& p); 48 | 49 | CCPoint RealToLogic(const cocos2d::CCPoint& p); 50 | 51 | void logPoint(const cocos2d::CCPoint& p); 52 | 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /Classes/FixMoveAIChessboardController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FixMoveAIChessboardController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #include "FixMoveAIChessboardController.h" 10 | #include "MoveBoard.h" 11 | 12 | bool FixMoveAIChessboardController::init(){ 13 | AIChessboardController::init(); 14 | 15 | CCLabelTTF* label = MoveBoard::create(); 16 | this->addChild(label); 17 | 18 | modeLabel->setString("固定步数"); 19 | 20 | return true; 21 | } -------------------------------------------------------------------------------- /Classes/FixMoveAIChessboardController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FixMoveAIChessboardController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #ifndef __Four__FixMoveAIChessboardController__ 10 | #define __Four__FixMoveAIChessboardController__ 11 | 12 | #include "AIChessboardController.h" 13 | 14 | #include "cocos2d.h" 15 | 16 | using namespace std; 17 | 18 | class FixMoveAIChessboardController : public AIChessboardController { 19 | 20 | public: 21 | bool init(); 22 | CREATE_FUNC(FixMoveAIChessboardController); 23 | }; 24 | 25 | #endif /* defined(__Four__FixMoveAIChessboardController__) */ 26 | -------------------------------------------------------------------------------- /Classes/FixMoveAIGameScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FixMoveAIGameScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #include "FixMoveAIGameScene.h" 10 | #include "FixMoveAIChessboardController.h" 11 | #include "MenuController.h" 12 | 13 | bool FixMoveAIGameScene::init(){ 14 | 15 | CCLayer* l1 = FixMoveAIChessboardController::create(); 16 | this->addChild(l1); 17 | CCLayer* l2 = MenuController::create(); 18 | this->addChild(l2); 19 | 20 | return true; 21 | } -------------------------------------------------------------------------------- /Classes/FixMoveAIGameScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // FixMoveAIGameScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #ifndef __Four__FixMoveAIGameScene__ 10 | #define __Four__FixMoveAIGameScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using cocos2d::CCScene; 15 | 16 | class FixMoveAIGameScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(FixMoveAIGameScene); 21 | 22 | }; 23 | 24 | #endif /* defined(__Four__FixMoveAIGameScene__) */ 25 | -------------------------------------------------------------------------------- /Classes/FixTimeAIChessboardController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FixTimeAIChessboardController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #include "FixTimeAIChessboardController.h" 10 | #include "TimeBoard.h" 11 | 12 | bool FixTimeAIChessboardController::init(){ 13 | AIChessboardController::init(); 14 | 15 | CCLabelTTF* label = TimeBoard::create(); 16 | this->addChild(label); 17 | 18 | modeLabel->setString("固定时间"); 19 | 20 | return true; 21 | } -------------------------------------------------------------------------------- /Classes/FixTimeAIChessboardController.h: -------------------------------------------------------------------------------- 1 | // 2 | // FixTimeAIChessboardController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #ifndef __Four__FixTimeAIChessboardController__ 10 | #define __Four__FixTimeAIChessboardController__ 11 | 12 | #include "AIChessboardController.h" 13 | 14 | #include "cocos2d.h" 15 | 16 | using namespace cocos2d; 17 | 18 | class FixTimeAIChessboardController : public AIChessboardController { 19 | 20 | public: 21 | bool init(); 22 | CREATE_FUNC(FixTimeAIChessboardController); 23 | }; 24 | 25 | #endif /* defined(__Four__FixTimeAIChessboardController__) */ 26 | -------------------------------------------------------------------------------- /Classes/FixTimeAIGameScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // FixTimeAIGameScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #include "FixTimeAIGameScene.h" 10 | #include "FixTimeAIChessboardController.h" 11 | #include "MenuController.h" 12 | 13 | bool FixTimeAIGameScene::init(){ 14 | 15 | CCLayer* l1 = FixTimeAIChessboardController::create(); 16 | this->addChild(l1); 17 | CCLayer* l2 = MenuController::create(); 18 | this->addChild(l2); 19 | 20 | return true; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Classes/FixTimeAIGameScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // FixTimeAIGameScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #ifndef __Four__FixTimeAIGameScene__ 10 | #define __Four__FixTimeAIGameScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using cocos2d::CCScene; 15 | 16 | class FixTimeAIGameScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(FixTimeAIGameScene); 21 | 22 | }; 23 | 24 | #endif /* defined(__Four__FixTimeAIGameScene__) */ 25 | -------------------------------------------------------------------------------- /Classes/GameScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // GameScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-25. 6 | // 7 | // 8 | 9 | #include "GameScene.h" 10 | #include "ChessboardController.h" 11 | #include "MenuController.h" 12 | 13 | bool GameScene::init(){ 14 | CCScene::init(); 15 | 16 | CCLayer* cc = ChessboardController::create(); 17 | this->addChild(cc); 18 | CCLayer* mc = MenuController::create(); 19 | this->addChild(mc); 20 | 21 | return true; 22 | } -------------------------------------------------------------------------------- /Classes/GameScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // GameScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-25. 6 | // 7 | // 8 | 9 | #ifndef __Four__GameScene__ 10 | #define __Four__GameScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class GameScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(GameScene); 21 | }; 22 | 23 | #endif /* defined(__Four__GameScene__) */ 24 | -------------------------------------------------------------------------------- /Classes/HelpController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // HelpController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #include "HelpController.h" 10 | #include "Tag.h" 11 | #include "Chessboard.h" 12 | #include "StartScene.h" 13 | #include "PieceView.h" 14 | 15 | HelpController::~HelpController(){ 16 | CC_SAFE_RETAIN(intros); 17 | CC_SAFE_RELEASE(label); 18 | } 19 | 20 | bool HelpController::init(){ 21 | BaseController::init(); 22 | 23 | intros = CCArray::create(); 24 | CC_SAFE_RETAIN(intros); 25 | 26 | 27 | intros->addObject(CCString::create("黑子轻轻下滑,两黑一白,即可吃子")); 28 | intros->addObject(CCString::create("当白子被吃到仅剩一个时,即可胜利")); 29 | PIECE pieces1[HEIGHT][WIDTH] = { 30 | {ZERO, BLACK, ZERO, WHITE}, 31 | {ZERO, ZERO, BLACK, ZERO}, 32 | {ZERO, ZERO, ZERO, ZERO}, 33 | {ZERO, ZERO, ZERO, ZERO} 34 | }; 35 | ChessboardData data1; 36 | Pieces2Data(pieces1, data1); 37 | datas.push_back(data1); 38 | moves.push_back(Move(BLACK, ccp(2, 1), ccp(2, 0))); 39 | 40 | intros->addObject(CCString::create("白子轻轻下滑,白子先动,不可吃子")); 41 | intros->addObject(CCString::create("教程结束,开始游戏吧")); 42 | PIECE pieces2[HEIGHT][WIDTH] = { 43 | {ZERO, BLACK, BLACK, ZERO}, 44 | {ZERO, ZERO, ZERO, WHITE}, 45 | {ZERO, ZERO, ZERO, ZERO}, 46 | {ZERO, ZERO, ZERO, ZERO} 47 | }; 48 | ChessboardData data2; 49 | Pieces2Data(pieces2, data2); 50 | datas.push_back(data2); 51 | moves.push_back(Move(WHITE, ccp(3, 1), ccp(3, 0))); 52 | 53 | this->chessboard = Chessboard::create(); 54 | CC_SAFE_RETAIN(this->chessboard); 55 | chessboard->setPieces(datas[0]); 56 | ChessboardController::initPieceViews(); 57 | 58 | label = CCLabelTTF::create(dynamic_cast(intros->objectAtIndex(0))->getCString(), "Helvetica-Bold", 32.0f); 59 | label->setPosition(ccp(320, 960)); 60 | label->setColor(ccBLACK); 61 | this->addChild(label); 62 | CC_SAFE_RETAIN(label); 63 | 64 | progress = 0; 65 | 66 | return true; 67 | } 68 | 69 | void HelpController::onEnter(){ 70 | ChessboardController::onEnter(); 71 | CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, END_EAT_MSG); 72 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(HelpController::tryWin), END_EAT_MSG, nullptr); 73 | } 74 | 75 | void HelpController::ccTouchEnded(cocos2d::CCTouch *touch, cocos2d::CCEvent *event){ 76 | progress++; 77 | if (progress < (moves.size() * 2) ) { 78 | int index = progress / 2; 79 | if (progress % 2 != 0) { 80 | chessboard->setCurrentMove(moves[index]); 81 | tryMove(moves[index].src, moves[index].dest); 82 | }else{ 83 | chessboard->setPieces(datas[index]); 84 | this->initPieceViews(); 85 | } 86 | label->setString(dynamic_cast(intros->objectAtIndex(progress))->getCString()); 87 | }else{ 88 | StartScene* scene = StartScene::create(); 89 | CCTransitionSlideInR* slide = CCTransitionSlideInR::create(0.3, scene); 90 | CCDirector::sharedDirector()->replaceScene(slide); 91 | } 92 | 93 | } 94 | 95 | void HelpController::tryWin(){ 96 | if (chessboard->checkMessage(WIN_MSG)) { 97 | chessboard->alterNextRound(); 98 | } 99 | } -------------------------------------------------------------------------------- /Classes/HelpController.h: -------------------------------------------------------------------------------- 1 | // 2 | // HelpController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #ifndef __Four__HelpController__ 10 | #define __Four__HelpController__ 11 | 12 | #include "ChessboardController.h" 13 | #include "ChessboardProtocol.h" 14 | 15 | #include "cocos2d.h" 16 | 17 | #include 18 | 19 | using namespace cocos2d; 20 | 21 | class HelpController : public ChessboardController { 22 | private: 23 | CCArray* intros; 24 | std::vector datas; 25 | std::vector moves; 26 | int progress; 27 | CCLabelTTF* label; 28 | 29 | public: 30 | ~HelpController(); 31 | bool init(); 32 | CREATE_FUNC(HelpController); 33 | 34 | void onEnter(); 35 | 36 | virtual void ccTouchEnded(CCTouch* touch, CCEvent* event); 37 | 38 | void tryWin(); 39 | }; 40 | 41 | #endif /* defined(__Four__HelpController__) */ 42 | -------------------------------------------------------------------------------- /Classes/HelpScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // HelpScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #include "HelpScene.h" 10 | #include "HelpController.h" 11 | 12 | 13 | bool HelpScene::init(){ 14 | cocos2d::CCScene::create(); 15 | 16 | CCLayer* layer = HelpController::create(); 17 | this->addChild(layer); 18 | 19 | return true; 20 | } -------------------------------------------------------------------------------- /Classes/HelpScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // HelpScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #ifndef __Four__HelpScene__ 10 | #define __Four__HelpScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using cocos2d::CCScene; 15 | 16 | class HelpScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(HelpScene); 21 | }; 22 | 23 | 24 | #endif /* defined(__Four__HelpScene__) */ 25 | -------------------------------------------------------------------------------- /Classes/ImageButton.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ImageButton.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #include "ImageButton.h" 10 | 11 | void ImageButton::onEnter(){ 12 | CCMenuItemSprite::onEnter(); 13 | this->setScale(0.05); 14 | CCActionInterval* s = CCScaleTo::create(0.3f, 1.0f); 15 | this->runAction(s); 16 | } 17 | 18 | void ImageButton::onExit(){ 19 | CCMenuItemSprite::onExit(); 20 | CCActionInterval* s = CCScaleTo::create(0.3f, 0.05f); 21 | this->runAction(s); 22 | } 23 | 24 | ImageButton* ImageButton::create(CCNode *sprite, cocos2d::CCObject *target, SEL_MenuHandler selector){ 25 | ImageButton* pRet = new ImageButton(); 26 | 27 | if (pRet && pRet->initWithNormalSprite(sprite, sprite, sprite, target, selector)) 28 | { 29 | pRet->autorelease(); 30 | return pRet; 31 | } 32 | CC_SAFE_DELETE(pRet); 33 | return NULL; 34 | } -------------------------------------------------------------------------------- /Classes/ImageButton.h: -------------------------------------------------------------------------------- 1 | // 2 | // ImageButton.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #ifndef __Four__ImageButton__ 10 | #define __Four__ImageButton__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class ImageButton : public CCMenuItemSprite { 17 | 18 | public: 19 | void onEnter(); 20 | void onExit(); 21 | 22 | static ImageButton* create(CCNode* sprite, CCObject* target, SEL_MenuHandler selector); 23 | 24 | }; 25 | 26 | #endif /* defined(__Four__ImageButton__) */ 27 | -------------------------------------------------------------------------------- /Classes/LogoView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // LogoView.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-3. 6 | // 7 | // 8 | 9 | #include "LogoView.h" 10 | #include "Message.h" 11 | 12 | LogoView::~LogoView(){ 13 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 14 | } 15 | 16 | bool LogoView::init(){ 17 | CCSprite::init(); 18 | 19 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(LogoView::onNextRound), NEXT_ROUND_MSG, nullptr); 20 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(LogoView::onNextRound), REGRET_MSG, nullptr); 21 | 22 | return true; 23 | } 24 | 25 | LogoView* LogoView::create(const Move *_currentMove, cocos2d::CCSpriteFrame *frame, PIECE _presentRound){ 26 | LogoView* view = LogoView::create(); 27 | view->setDisplayFrame(frame); 28 | view->setCurrentMove(_currentMove); 29 | view->setPresentRound(_presentRound); 30 | return view; 31 | } 32 | 33 | void LogoView::onEnter(){ 34 | CCSprite::onEnter(); 35 | this->setPosition(ccp(832, 960)); 36 | if (this->presentRound == this->currentMove->currentRound ){ 37 | this->onNextRound(nullptr); 38 | } 39 | } 40 | 41 | void LogoView::onNextRound(CCObject* o){ 42 | if (this->presentRound == this->currentMove->currentRound ) { 43 | this->runAction(CCEaseElasticOut::create(CCMoveTo::create(1.0f, ccp(320, 960)))); 44 | }else{ 45 | this->runAction(CCSequence::createWithTwoActions(CCMoveTo::create(0.4f, ccp(-192, 960)), CCPlace::create(ccp(832, 960)) ) ); 46 | } 47 | } 48 | 49 | void LogoView::activateStop(){ 50 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(LogoView::onStop), WIN_MSG, nullptr); 51 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(LogoView::onStop), LOSE_MSG, nullptr); 52 | } 53 | 54 | void LogoView::onStop(){ 55 | this->runAction(CCSequence::createWithTwoActions(CCScaleTo::create(0.05f, 0.5f), CCRemoveSelf::create())); 56 | } 57 | -------------------------------------------------------------------------------- /Classes/LogoView.h: -------------------------------------------------------------------------------- 1 | // 2 | // LogoView.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-3. 6 | // 7 | // 8 | 9 | #ifndef __Four__LogoView__ 10 | #define __Four__LogoView__ 11 | 12 | #include "ChessboardProtocol.h" 13 | 14 | #include "cocos2d.h" 15 | 16 | using namespace cocos2d; 17 | 18 | class LogoView : public CCSprite { 19 | CC_SYNTHESIZE(const Move*, currentMove, CurrentMove); 20 | CC_SYNTHESIZE(PIECE, presentRound, PresentRound); 21 | 22 | public: 23 | bool init(); 24 | CREATE_FUNC(LogoView); 25 | static LogoView* create(const Move* _currentMove, CCSpriteFrame* frame, PIECE _presentRound); 26 | virtual ~LogoView(); 27 | 28 | void onEnter(); 29 | 30 | // listener 31 | void onNextRound(CCObject* o); 32 | 33 | // 在有AI的情况下LogoView需要对胜利或者失败的场景做出反应 34 | void activateStop(); 35 | void onStop(); 36 | }; 37 | 38 | #endif /* defined(__Four__LogoView__) */ 39 | -------------------------------------------------------------------------------- /Classes/MenuController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // MenuController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #include "MenuController.h" 10 | #include "ImageButton.h" 11 | #include "StartScene.h" 12 | #include "Message.h" 13 | 14 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 15 | 16 | #include "C2DXShareSDK.h" 17 | 18 | using namespace cn::sharesdk; 19 | 20 | void shareResultHandler(C2DXResponseState state, C2DXPlatType platType, CCDictionary *shareInfo, CCDictionary *error) 21 | { 22 | switch (state) { 23 | case C2DXResponseStateSuccess: 24 | CCLog("分享成功"); 25 | break; 26 | case C2DXResponseStateFail: 27 | CCLog("分享失败"); 28 | break; 29 | default: 30 | break; 31 | } 32 | } 33 | 34 | #endif 35 | 36 | bool MenuController::init(){ 37 | 38 | if (! CCLayer::init()) { 39 | return false; 40 | } 41 | 42 | CCSpriteBatchNode* batch = CCSpriteBatchNode::create("AllSprites.png"); 43 | this->addChild(batch); 44 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 45 | cache->addSpriteFramesWithFile("AllSprites.plist"); 46 | 47 | CCSprite* background = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("menubar.png")); 48 | background->setAnchorPoint(ccp(0, 0)); 49 | background->setPosition(ccp(0, 0)); 50 | this->addChild(background); 51 | 52 | CCSprite* back = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("back.png")); 53 | ImageButton* backButton = ImageButton::create(back, this, menu_selector(MenuController::onBack)); 54 | backButton->setPosition(ccp(128, 48)); 55 | 56 | CCSprite* regret = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("regret.png")); 57 | ImageButton* regretButton = ImageButton::create(regret, this, menu_selector(MenuController::onRegret)); 58 | regretButton->setPosition(ccp(320, 48)); 59 | 60 | CCSprite* plus = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("plus.png")); 61 | ImageButton* plusButton = ImageButton::create(plus, this, menu_selector(MenuController::onShare)); 62 | plusButton->setPosition(ccp(512, 48)); 63 | 64 | CCMenu* menu = CCMenu::create(backButton, regretButton, plusButton, NULL); 65 | menu->setPosition(ccp(0, 0)); 66 | this->addChild(menu); 67 | 68 | return true; 69 | } 70 | 71 | void MenuController::onBack(CCObject* o){ 72 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CLICK_MSG); 73 | StartScene* ss = StartScene::create(); 74 | CCTransitionSlideInL* slide = CCTransitionSlideInL::create(0.3f, ss); 75 | CCDirector::sharedDirector()->replaceScene(slide); 76 | } 77 | 78 | void MenuController::onRegret(cocos2d::CCObject *o){ 79 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CLICK_MSG); 80 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CLICK_REGRET_MSG); 81 | } 82 | 83 | void MenuController::onShare(cocos2d::CCObject *o){ 84 | 85 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) 86 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CLICK_MSG); 87 | CCDictionary *content = CCDictionary::create(); 88 | content -> setObject(CCString::create("这是一条测试内容"), "content"); 89 | content -> setObject(CCString::create("http://img0.bdstatic.com/img/image/308342ac65c10385343da168d569113b07ecb8088ef.jpg"), "image"); 90 | content -> setObject(CCString::create("测试标题"), "title"); 91 | content -> setObject(CCString::create("测试描述"), "description"); 92 | content -> setObject(CCString::create("http://sharesdk.cn"), "url"); 93 | content -> setObject(CCString::createWithFormat("%d", C2DXContentTypeNews), "type"); 94 | content -> setObject(CCString::create("http://sharesdk.cn"), "siteUrl"); 95 | content -> setObject(CCString::create("ShareSDK"), "site"); 96 | content -> setObject(CCString::create("http://mp3.mwap8.com/destdir/Music/2009/20090601/ZuiXuanMinZuFeng20090601119.mp3"), "musicUrl"); 97 | content -> setObject(CCString::create("extInfo"), "extInfo"); 98 | 99 | C2DXShareSDK::showShareMenu(NULL, content, CCPointMake(100, 100), C2DXMenuArrowDirectionLeft, shareResultHandler); 100 | #endif 101 | } 102 | 103 | -------------------------------------------------------------------------------- /Classes/MenuController.h: -------------------------------------------------------------------------------- 1 | // 2 | // MenuController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #ifndef __Four__MenuController__ 10 | #define __Four__MenuController__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class MenuController : public CCLayer{ 17 | 18 | public: 19 | bool init(); 20 | CREATE_FUNC(MenuController); 21 | 22 | void onBack(CCObject* o); 23 | void onRegret(CCObject* o); 24 | void onShare(CCObject* o); 25 | }; 26 | 27 | 28 | #endif /* defined(__Four__MenuController__) */ 29 | 30 | -------------------------------------------------------------------------------- /Classes/Message.h: -------------------------------------------------------------------------------- 1 | // 2 | // Event.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-20. 6 | // 7 | // 8 | 9 | #ifndef Four_Message_h 10 | #define Four_Message_h 11 | 12 | static const char* TEST_MSG = "test"; 13 | static const char* CREATE_MSG = "create"; 14 | 15 | static const char* BEGIN_MOVE_MSG = "begin_move"; 16 | static const char* END_MOVE_MSG = "end_move"; 17 | static const char* AI_END_MOVE_MSG = "ai_end_move"; 18 | static const char* BEGIN_EAT_MSG = "begin_eat"; 19 | static const char* END_EAT_MSG = "end_eat"; 20 | static const char* FAIL_MSG= "fail"; 21 | static const char* WIN_MSG= "win"; 22 | static const char* NEXT_ROUND_MSG= "next_round"; 23 | 24 | static const char* CLICK_REGRET_MSG = "click_regret"; 25 | static const char* REGRET_MSG = "regret"; 26 | static const char* AI_REGRET_MSG = "ai_regret"; 27 | 28 | static const char* CLICK_MSG = "click"; 29 | static const char* LOSE_MSG = "lose"; 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /Classes/Model.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // Model.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-21. 6 | // 7 | // 8 | 9 | #include "Model.h" 10 | 11 | #include 12 | 13 | Model* Model::addTransition(const string& from, const string& event, const string& to){ 14 | map& form_transitions = transitions[from]; 15 | form_transitions[event] = to; 16 | return this; 17 | } 18 | 19 | void Model::onAsyncMessage(CCNode* node, CCString* msg){ 20 | async = false; 21 | this->onMessage(msg->getCString()); 22 | msg->release(); 23 | } 24 | 25 | bool Model::checkMessage(const string &msg){ 26 | return transitions[currentState].find(msg) != transitions[currentState].end(); 27 | } 28 | 29 | void Model::onMessage(const string& msg){ 30 | CCLOG("%s", msg.c_str()); 31 | if (checkMessage(msg) && !async) { 32 | this->currentState = this->transitions[this->currentState][msg]; 33 | CCLOG("transfer to State : %s", this->currentState.c_str()); 34 | cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(msg.c_str()); 35 | } 36 | } 37 | 38 | void Model::onMessage(const string &msg, CCObject* o){ 39 | CCLOG("%s", msg.c_str()); 40 | if (checkMessage(msg) && !async) { 41 | this->currentState = this->transitions[this->currentState][msg]; 42 | CCLOG("transfer to State : %s", this->currentState.c_str()); 43 | cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(msg.c_str(), o); 44 | } 45 | } 46 | 47 | void Model::waitAction(cocos2d::CCNode* node, cocos2d::CCFiniteTimeAction* action, const string& msg){ 48 | using namespace cocos2d; 49 | async = true; 50 | CCString* cc_msg = CCString::create(msg); 51 | cc_msg->retain(); 52 | CCFiniteTimeAction* action2 = CCCallFuncND::create(this, callfuncND_selector(Model::onAsyncMessage), (void *) cc_msg); 53 | CCSequence* sequence = CCSequence::createWithTwoActions(action, action2); 54 | node->runAction(sequence); 55 | } 56 | 57 | const char* Model::getState(){ 58 | return this->currentState.c_str(); 59 | } 60 | -------------------------------------------------------------------------------- /Classes/Model.h: -------------------------------------------------------------------------------- 1 | // 2 | // Model.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-21. 6 | // 7 | // 8 | 9 | #ifndef __Four__Model__ 10 | #define __Four__Model__ 11 | 12 | #include 13 | #include 14 | 15 | using std::map; 16 | using std::string; 17 | 18 | #include "cocos2d.h" 19 | 20 | using cocos2d::CCAction; 21 | using cocos2d::CCNode; 22 | using cocos2d::CCObject; 23 | using cocos2d::CCString; 24 | 25 | class Model : public CCObject { 26 | 27 | private: 28 | map > transitions; 29 | string currentState; 30 | bool async; 31 | 32 | public: 33 | explicit Model(const string& _initial):currentState(_initial), async(false){} 34 | 35 | explicit Model(const string& _initial ,const map >& _transitions): 36 | currentState(_initial),transitions(_transitions), async(false){} 37 | 38 | virtual ~Model(){} 39 | 40 | // 添加一条状态转换,from-起始状态,msg-接收的消息,to-终结状态,在msg发生时会发生状态转换 41 | Model* addTransition(const string& from, const string& msg, const string& to); 42 | 43 | // 检查当前状态机能否发生msg对应的状态转换 44 | bool checkMessage(const string& msg); 45 | 46 | // 触发msg对应的状态转换 47 | void onMessage(const string& msg); 48 | void onMessage(const string& msg, CCObject* o); 49 | 50 | // 等待某个CCAction结束后发送一条消息。 51 | void waitAction(cocos2d::CCNode* node, cocos2d::CCFiniteTimeAction* action, const string& msg); 52 | 53 | // 得到当前状态名称 54 | const char* getState(); 55 | 56 | // callback 57 | void onAsyncMessage(CCNode* node , CCString* msg); 58 | }; 59 | 60 | #endif /* defined(__Four__Model__) */ 61 | -------------------------------------------------------------------------------- /Classes/MoveBoard.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // MoveBoard.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-10. 6 | // 7 | // 8 | 9 | #include "MoveBoard.h" 10 | #include "Message.h" 11 | #include "Chessboard.h" 12 | 13 | bool MoveBoard::init(){ 14 | 15 | leftMoves = 30; 16 | CCLabelTTF::initWithString("Move : 30", "Helvetica-Bold", 32.0f); 17 | this->setColor(ccBLACK); 18 | this->setPosition(ccp(320, 860)); 19 | 20 | return true; 21 | } 22 | 23 | void MoveBoard::onEnter(){ 24 | CCLabelTTF::onEnter(); 25 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(MoveBoard::onNextRound), NEXT_ROUND_MSG, NULL); 26 | } 27 | 28 | void MoveBoard::onExit(){ 29 | CCLabelTTF::onExit(); 30 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 31 | } 32 | 33 | void MoveBoard::onNextRound(cocos2d::CCObject *o){ 34 | Chessboard* chessboard = dynamic_cast(o); 35 | if (chessboard->getCurrentMove().currentRound == BLACK){ 36 | leftMoves--; 37 | CCString* str = CCString::createWithFormat("Move : %d", leftMoves); 38 | this->setString(str->getCString()); 39 | if (leftMoves == 0) { 40 | CCNotificationCenter::sharedNotificationCenter()->postNotification(LOSE_MSG); 41 | } 42 | } 43 | } 44 | 45 | 46 | -------------------------------------------------------------------------------- /Classes/MoveBoard.h: -------------------------------------------------------------------------------- 1 | // 2 | // MoveBoard.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-10. 6 | // 7 | // 8 | 9 | #ifndef __Four__MoveBoard__ 10 | #define __Four__MoveBoard__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class MoveBoard : public CCLabelTTF { 17 | private: 18 | int leftMoves; 19 | 20 | public: 21 | bool init(); 22 | CREATE_FUNC(MoveBoard); 23 | 24 | void onEnter(); 25 | void onExit(); 26 | 27 | void onNextRound(CCObject* o); 28 | }; 29 | 30 | #endif /* defined(__Four__MoveBoard__) */ 31 | -------------------------------------------------------------------------------- /Classes/PieceView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // PieceView.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-24. 6 | // 7 | // 8 | 9 | #include "PieceView.h" 10 | #include "ChessboardProtocol.h" 11 | #include "Chessboard.h" 12 | 13 | #include 14 | #include 15 | 16 | PieceView::~PieceView(){ 17 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 18 | CC_SAFE_DELETE(this->dropAction); 19 | CC_SAFE_RELEASE(this->model); 20 | } 21 | 22 | bool PieceView::init(){ 23 | CCSprite::init(); 24 | this->setAnchorPoint(ccp(0.5, 0.5)); 25 | 26 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PieceView::onBeginMove), BEGIN_MOVE_MSG, nullptr); 27 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PieceView::onBeginEat), BEGIN_EAT_MSG, nullptr); 28 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PieceView::onRegret), REGRET_MSG, nullptr); 29 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(PieceView::onAIRegret), AI_REGRET_MSG, nullptr); 30 | 31 | return true; 32 | } 33 | 34 | PieceView* PieceView::create(const Move* _currentMove, Model* _model, cocos2d::CCSpriteFrame *frame, const CCPoint& _logic_position){ 35 | PieceView* view = PieceView::create(); 36 | view->setCurrentMove(_currentMove); 37 | view->setModel(_model); 38 | _model->retain(); 39 | view->setDisplayFrame(frame); 40 | CCPoint dest = LogicToReal(_logic_position); 41 | view->setPosition(ccp(dest.x, CCDirector::sharedDirector()->getVisibleSize().height)); 42 | CCActionInterval* drop = CCMoveTo::create(0.6f, dest); 43 | 44 | drop->retain(); 45 | view->setDropAction(drop); 46 | 47 | return view; 48 | } 49 | 50 | void PieceView::onEnter(){ 51 | CCSprite::onEnter(); 52 | CCActionInterval* bounce = CCEaseBounceOut::create(this->dropAction); 53 | this->runAction(bounce); 54 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CREATE_MSG); 55 | } 56 | 57 | void PieceView::onExit(){ 58 | CCSprite::onExit(); 59 | this->runAction(dropAction->reverse()); 60 | } 61 | 62 | 63 | void PieceView::onBeginMove(CCObject* o){ 64 | if (!(currentMove->src).equals(RealToLogic(this->getPosition()))) 65 | return; 66 | CCPoint dest = LogicToReal(currentMove->dest); 67 | model->waitAction(this, CCEaseExponentialOut::create(CCMoveTo::create(0.5f, dest)), END_MOVE_MSG); 68 | } 69 | 70 | void PieceView::onBeginEat(CCObject* o){ 71 | const std::vector eatenPoints = currentMove->eatenPoints; 72 | CCPoint logic_position = RealToLogic(this->getPosition()); 73 | 74 | 75 | if (std::find_if(eatenPoints.begin(), eatenPoints.end(), 76 | [logic_position](const CCPoint& p)->bool{return p.equals(logic_position) ;} ) == eatenPoints.end()) 77 | // if (!eatenPoints[0].equals(logic_position)) 78 | return; 79 | CCScaleTo* st = CCScaleTo::create(0.2f, 0.05); 80 | CCRemoveSelf* rs = CCRemoveSelf::create(); 81 | model->waitAction(this, CCSequence::createWithTwoActions(st, rs), END_EAT_MSG); 82 | } 83 | 84 | void PieceView::onRegret(CCObject* o){ 85 | if (!(currentMove->dest).equals(RealToLogic(this->getPosition()))) 86 | return; 87 | CCPoint src = LogicToReal(currentMove->src); 88 | model->waitAction(this, CCEaseExponentialOut::create(CCMoveTo::create(0.6f, src)), END_MOVE_MSG); 89 | } 90 | 91 | void PieceView::onAIRegret(CCObject* o){ 92 | if (!(currentMove->dest).equals(RealToLogic(this->getPosition()))) 93 | return; 94 | CCPoint src = LogicToReal(currentMove->src); 95 | model->waitAction(this, CCEaseExponentialOut::create(CCMoveTo::create(0.65f, src)), AI_END_MOVE_MSG); 96 | } 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Classes/PieceView.h: -------------------------------------------------------------------------------- 1 | // 2 | // PieceView.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-4-24. 6 | // 7 | // 8 | 9 | #ifndef __Four__PieceView__ 10 | #define __Four__PieceView__ 11 | 12 | #include "cocos2d.h" 13 | #include "Model.h" 14 | #include "ChessboardProtocol.h" 15 | 16 | using namespace cocos2d; 17 | 18 | class PieceView : public CCSprite{ 19 | CC_SYNTHESIZE(const Move*, currentMove, CurrentMove); 20 | CC_SYNTHESIZE(Model*, model, Model); 21 | CC_SYNTHESIZE(CCActionInterval*, dropAction, DropAction); 22 | 23 | private: 24 | bool containsTouchLocation(CCTouch* touch); 25 | 26 | public: 27 | PieceView(){} 28 | virtual ~PieceView(); 29 | virtual bool init(); 30 | CREATE_FUNC(PieceView); 31 | static PieceView* create(const Move* _currentMove, Model* _model, CCSpriteFrame* frame, const CCPoint& _logic_position); 32 | 33 | void onEnter(); 34 | void onExit(); 35 | 36 | // listener 37 | void onBeginMove(CCObject* o); 38 | void onBeginEat(CCObject* o); 39 | void onRegret(CCObject* o); 40 | void onAIRegret(CCObject* o); 41 | }; 42 | 43 | #endif /* defined(__Four__PieceView__) */ 44 | -------------------------------------------------------------------------------- /Classes/ResultView.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // ResultView.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #include "ResultView.h" 10 | #include "Message.h" 11 | 12 | ResultView::~ResultView(){ 13 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 14 | } 15 | 16 | bool ResultView::init(){ 17 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ResultView::onWin), WIN_MSG, nullptr); 18 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(ResultView::onLose), LOSE_MSG, nullptr); 19 | 20 | CCLabelTTF::initWithString("", "Helvetica-Bold", 96.0f); 21 | this->setColor(ccBLACK); 22 | this->setPosition(ccp(320, 1200)); 23 | 24 | return true; 25 | } 26 | 27 | void ResultView::onWin(CCObject* o){ 28 | this->setString("WIN"); 29 | this->runAction(CCEaseElasticOut::create(CCMoveTo::create(0.5f, ccp(320, 960)))); 30 | } 31 | 32 | void ResultView::onLose(CCObject* o){ 33 | this->setString("LOSE"); 34 | this->runAction(CCEaseElasticOut::create(CCMoveTo::create(0.5f, ccp(320, 960)))); 35 | } -------------------------------------------------------------------------------- /Classes/ResultView.h: -------------------------------------------------------------------------------- 1 | // 2 | // ResultView.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-11. 6 | // 7 | // 8 | 9 | #ifndef __Four__ResultView__ 10 | #define __Four__ResultView__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class ResultView : public CCLabelTTF { 17 | 18 | public: 19 | ~ResultView(); 20 | bool init(); 21 | CREATE_FUNC(ResultView); 22 | 23 | void onWin(CCObject* o); 24 | void onLose(CCObject* o); 25 | }; 26 | 27 | #endif /* defined(__Four__ResultView__) */ 28 | -------------------------------------------------------------------------------- /Classes/RotFlowerParticle.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RotFlowerParticle.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-7. 6 | // 7 | // 8 | 9 | #include "RotFlowerParticle.h" 10 | 11 | bool RotFlowerParticle::init(){ 12 | 13 | CCParticleSnow::init(); 14 | 15 | this->setTexture(CCTextureCache::sharedTextureCache()->addImage("star.png")); 16 | this->setEmissionRate(this->getTotalParticles() / this->getLife()); 17 | this->setPosition(ccp(320, 1100)); 18 | this->setLife(3); 19 | this->setLifeVar(1); 20 | this->setGravity(CCPointZero); 21 | this->setSpeed(130); 22 | this->setSpeedVar(30); 23 | 24 | // color of particles 25 | ccColor4F startColor = {0.5f, 0.5f, 0.5f, 1.0f}; 26 | this->setStartColor(startColor); 27 | 28 | ccColor4F startColorVar = {0.5f, 0.5f, 0.5f, 1.0f}; 29 | this->setStartColorVar(startColorVar); 30 | 31 | ccColor4F endColor = {0.1f, 0.1f, 0.1f, 0.2f}; 32 | this->setEndColor(endColor); 33 | 34 | ccColor4F endColorVar = {0.1f, 0.1f, 0.1f, 0.2f}; 35 | this->setEndColorVar(endColorVar); 36 | 37 | this->setScale(2.0); 38 | 39 | return true; 40 | } -------------------------------------------------------------------------------- /Classes/RotFlowerParticle.h: -------------------------------------------------------------------------------- 1 | // 2 | // RotFlowerParticle.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-7. 6 | // 7 | // 8 | 9 | #ifndef __Four__RotFlowerParticle__ 10 | #define __Four__RotFlowerParticle__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class RotFlowerParticle : public CCParticleSnow { 17 | 18 | 19 | public: 20 | bool init(); 21 | CREATE_FUNC(RotFlowerParticle); 22 | }; 23 | 24 | #endif /* defined(__Four__RotFlowerParticle__) */ 25 | -------------------------------------------------------------------------------- /Classes/StartController.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // StartController.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #include "StartController.h" 10 | #include "ImageButton.h" 11 | #include "ChessboardProtocol.h" 12 | #include "GameScene.h" 13 | #include "AIGameScene.h" 14 | #include "FixTimeAIGameScene.h" 15 | #include "FixMoveAIGameScene.h" 16 | #include "Message.h" 17 | 18 | bool StartController::init(){ 19 | if (! BaseController::init()) { 20 | return false; 21 | } 22 | 23 | 24 | // load res 25 | 26 | CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); 27 | 28 | CCSprite* four_logo = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("four_logo.png")); 29 | four_logo->setPosition(ccp(320, 960)); 30 | this->addChild(four_logo); 31 | 32 | CCSprite* h2h = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("h2h.png")); 33 | ImageButton* h2hButton = ImageButton::create(h2h, this, menu_selector(StartController::onH2H)); 34 | h2hButton->setPosition(LogicToReal(ccp(1, 2))); 35 | 36 | 37 | 38 | CCSprite* h2c = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("h2c.png")); 39 | ImageButton* h2cButton = ImageButton::create(h2c, this, menu_selector(StartController::onH2C)); 40 | h2cButton->setPosition(LogicToReal(ccp(2, 2))); 41 | 42 | CCSprite* fixTime = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("help.png")); 43 | ImageButton* fixTimeButton = ImageButton::create(fixTime, this, menu_selector(StartController::onFixTime)); 44 | fixTimeButton->setPosition(LogicToReal(ccp(1, 1))); 45 | 46 | CCSprite* fixMove = CCSprite::createWithSpriteFrame(cache->spriteFrameByName("exit.png")); 47 | ImageButton* fixMoveButton = ImageButton::create(fixMove, this, menu_selector(StartController::onFixMove)); 48 | fixMoveButton->setPosition(LogicToReal(ccp(2, 1))); 49 | 50 | CCMenu* menu = CCMenu::create(h2hButton, h2cButton, fixTimeButton, fixMoveButton, NULL); 51 | menu->setPosition(ccp(0, 0)); 52 | this->addChild(menu); 53 | 54 | return true; 55 | } 56 | 57 | void transfer2NextScene(CCScene* scene){ 58 | CCNotificationCenter::sharedNotificationCenter()->postNotification(CLICK_MSG); 59 | CCTransitionSlideInR* slide = CCTransitionSlideInR::create(0.3, scene); 60 | CCDirector::sharedDirector()->replaceScene(slide); 61 | } 62 | 63 | void StartController::onH2H(CCObject* o){ 64 | CCScene* gs = GameScene::create(); 65 | transfer2NextScene(gs); 66 | } 67 | 68 | void StartController::onH2C(CCObject* o){ 69 | CCScene* gs = AIGameScene::create(); 70 | transfer2NextScene(gs); 71 | } 72 | 73 | void StartController::onFixTime(CCObject* o){ 74 | CCScene* gs = FixTimeAIGameScene::create(); 75 | transfer2NextScene(gs); 76 | } 77 | 78 | void StartController::onFixMove(CCObject* o){ 79 | CCScene* gs = FixMoveAIGameScene::create(); 80 | transfer2NextScene(gs); 81 | } 82 | 83 | -------------------------------------------------------------------------------- /Classes/StartController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StartController.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #ifndef __Four__StartController__ 10 | #define __Four__StartController__ 11 | 12 | #include "BaseController.h" 13 | 14 | #include "cocos2d.h" 15 | 16 | using namespace cocos2d; 17 | 18 | class StartController : public BaseController { 19 | 20 | public: 21 | bool init(); 22 | CREATE_FUNC(StartController); 23 | 24 | // 进行人人对战 25 | void onH2H(CCObject* o); 26 | // 进行人机对战 27 | void onH2C(CCObject* o); 28 | // 当固定时间进行人机对战时 29 | void onFixTime(CCObject* o); 30 | // 当固定步数进行人机对战时 31 | void onFixMove(CCObject* o); 32 | }; 33 | 34 | 35 | 36 | #endif /* defined(__Four__StartController__) */ 37 | -------------------------------------------------------------------------------- /Classes/StartScene.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // StartScene.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #include "StartScene.h" 10 | #include "StartController.h" 11 | 12 | bool StartScene::init(){ 13 | CCScene::init(); 14 | 15 | StartController* sc = StartController::create(); 16 | this->addChild(sc); 17 | 18 | return true; 19 | } -------------------------------------------------------------------------------- /Classes/StartScene.h: -------------------------------------------------------------------------------- 1 | // 2 | // StartScene.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-2. 6 | // 7 | // 8 | 9 | #ifndef __Four__StartScene__ 10 | #define __Four__StartScene__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using cocos2d::CCScene; 15 | 16 | class StartScene : public CCScene { 17 | 18 | public: 19 | virtual bool init(); 20 | CREATE_FUNC(StartScene); 21 | }; 22 | 23 | #endif /* defined(__Four__StartScene__) */ 24 | -------------------------------------------------------------------------------- /Classes/Tag.h: -------------------------------------------------------------------------------- 1 | // 2 | // Tag.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-9. 6 | // 7 | // 8 | 9 | #ifndef Four_Tag_h 10 | #define Four_Tag_h 11 | 12 | typedef enum { 13 | ROUND_WHITE, 14 | ROUND_BLACK 15 | } TAG; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Classes/TimeBoard.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // TimeBoard.cpp 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-10. 6 | // 7 | // 8 | 9 | #include "TimeBoard.h" 10 | #include "Message.h" 11 | 12 | bool TimeBoard::init(){ 13 | 14 | leftSeconds = 60; 15 | CCLabelTTF::initWithString("Time : 60", "Helvetica-Bold", 32.0f); 16 | this->setColor(ccBLACK); 17 | this->setPosition(ccp(320, 860)); 18 | 19 | return true; 20 | } 21 | 22 | void TimeBoard::onEnter(){ 23 | CCLabelTTF::onEnter(); 24 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(TimeBoard::onStop), WIN_MSG, nullptr); 25 | CCNotificationCenter::sharedNotificationCenter()->addObserver(this, callfuncO_selector(TimeBoard::onStop), LOSE_MSG, nullptr); 26 | this->schedule(schedule_selector(TimeBoard::onTimeChanged), 1.0f); 27 | } 28 | 29 | void TimeBoard::onExit(){ 30 | CCLabelTTF::onExit(); 31 | CCNotificationCenter::sharedNotificationCenter()->removeAllObservers(this); 32 | this->unscheduleAllSelectors(); 33 | } 34 | 35 | void TimeBoard::onTimeChanged(float dt){ 36 | leftSeconds--; 37 | CCString* str = CCString::createWithFormat("Time : %d", leftSeconds); 38 | this->setString(str->getCString()); 39 | if (leftSeconds == 0) { 40 | CCNotificationCenter::sharedNotificationCenter()->postNotification(LOSE_MSG); 41 | } 42 | } 43 | 44 | void TimeBoard::onStop(){ 45 | this->unscheduleAllSelectors(); 46 | } 47 | 48 | -------------------------------------------------------------------------------- /Classes/TimeBoard.h: -------------------------------------------------------------------------------- 1 | // 2 | // TimeBoard.h 3 | // Four 4 | // 5 | // Created by 王选易 on 14-5-10. 6 | // 7 | // 8 | 9 | #ifndef __Four__TimeBoard__ 10 | #define __Four__TimeBoard__ 11 | 12 | #include "cocos2d.h" 13 | 14 | using namespace cocos2d; 15 | 16 | class TimeBoard : public CCLabelTTF { 17 | private: 18 | int leftSeconds; 19 | 20 | public: 21 | bool init(); 22 | CREATE_FUNC(TimeBoard); 23 | 24 | void onEnter(); 25 | void onExit(); 26 | 27 | void onTimeChanged(float dt); 28 | void onStop(); 29 | }; 30 | 31 | #endif /* defined(__Four__TimeBoard__) */ 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Four 2 | ==== 3 | 4 | ![](http://wangxuanyihaha.qiniudn.com/four/four_logo.png) 5 | 6 | 基于Cocos2d-x框架,并使用MVC架构的一个棋类游戏。 7 | 8 | Pure MVC架构,构建可维护的Cocos2d-x游戏。 9 | 10 | ###使用的框架 11 | 12 | Cocos2d-x2.2.3 13 | 14 | ###apk下载地址 15 | 16 | [应用宝](http://a.myapp.com/o/simple.jsp?pkgname=edu.nju.four) 17 | 18 | [360手机助手](http://zhushou.360.cn/detail/index/soft_id/1757556?recrefer=SE_D_four#btn-install-now-log) 19 | 20 | ###相关博客 21 | 22 | - 架构篇:[http://my.oschina.net/wangxuanyihaha/blog/265649](http://my.oschina.net/wangxuanyihaha/blog/265649) 23 | 24 | ###项目导入 25 | 26 | 将该项目放在Cocos2d-x根目录下的projects文件夹下。 27 | 28 | ####Xcode 29 | 30 | 直接点击Four.xcodeproj,即可通过Xcode打开该项目。 31 | 32 | ####Eclipse 33 | 34 | 使用Eclipse的Import功能,将已有的安卓代码导入到Eclipse中,并运行proj.android中的build_native.sh。再在Eclipse中运行即可。 35 | 36 | ###游戏截图 37 | 38 | ![1](http://wangxuanyihaha.qiniudn.com/four/four_large_1.png) 39 | 40 | ![2](http://wangxuanyihaha.qiniudn.com/four/four_large_2.png) 41 | -------------------------------------------------------------------------------- /Resources/AllSprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/AllSprites.png -------------------------------------------------------------------------------- /Resources/audio/click.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/audio/click.WAV -------------------------------------------------------------------------------- /Resources/audio/create.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/audio/create.WAV -------------------------------------------------------------------------------- /Resources/audio/eat.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/audio/eat.WAV -------------------------------------------------------------------------------- /Resources/audio/move.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/audio/move.WAV -------------------------------------------------------------------------------- /Resources/audio/next_round.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/audio/next_round.WAV -------------------------------------------------------------------------------- /Resources/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /Resources/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/Resources/star.png -------------------------------------------------------------------------------- /proj.android/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /proj.android/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Four 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.cdt.managedbuilder.core.genmakebuilder 25 | clean,full,incremental, 26 | 27 | 28 | ?name? 29 | 30 | 31 | 32 | org.eclipse.cdt.make.core.append_environment 33 | true 34 | 35 | 36 | org.eclipse.cdt.make.core.autoBuildTarget 37 | all 38 | 39 | 40 | org.eclipse.cdt.make.core.buildArguments 41 | -C ${ProjDirPath} NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt -j2 42 | 43 | 44 | org.eclipse.cdt.make.core.buildCommand 45 | ${ProjDirPath}/ANDROID_NDK/ndk-build 46 | 47 | 48 | org.eclipse.cdt.make.core.cleanBuildTarget 49 | clean 50 | 51 | 52 | org.eclipse.cdt.make.core.contents 53 | org.eclipse.cdt.make.core.activeConfigSettings 54 | 55 | 56 | org.eclipse.cdt.make.core.enableAutoBuild 57 | false 58 | 59 | 60 | org.eclipse.cdt.make.core.enableCleanBuild 61 | true 62 | 63 | 64 | org.eclipse.cdt.make.core.enableFullBuild 65 | true 66 | 67 | 68 | org.eclipse.cdt.make.core.fullBuildTarget 69 | all 70 | 71 | 72 | org.eclipse.cdt.make.core.stopOnError 73 | true 74 | 75 | 76 | org.eclipse.cdt.make.core.useDefaultBuildCmd 77 | false 78 | 79 | 80 | 81 | 82 | com.android.ide.eclipse.adt.ApkBuilder 83 | 84 | 85 | 86 | 87 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder 88 | full,incremental, 89 | 90 | 91 | 92 | 93 | 94 | com.android.ide.eclipse.adt.AndroidNature 95 | org.eclipse.jdt.core.javanature 96 | org.eclipse.cdt.core.cnature 97 | org.eclipse.cdt.core.ccnature 98 | org.eclipse.cdt.managedbuilder.core.managedBuildNature 99 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature 100 | 101 | 102 | 103 | Classes 104 | 2 105 | COCOS2DX/projects/Four/Classes 106 | 107 | 108 | cocos2dx 109 | 2 110 | COCOS2DX/cocos2dx 111 | 112 | 113 | extensions 114 | 2 115 | COCOS2DX/extensions 116 | 117 | 118 | scripting 119 | 2 120 | COCOS2DX/scripting 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /proj.android/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /proj.android/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 3 | org.eclipse.jdt.core.compiler.compliance=1.6 4 | org.eclipse.jdt.core.compiler.source=1.6 5 | -------------------------------------------------------------------------------- /proj.android/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /proj.android/README.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites: 2 | 3 | * Android NDK 4 | * Android SDK **OR** Eclipse ADT Bundle 5 | * Android AVD target installed 6 | 7 | ## Building project 8 | 9 | There are two ways of building Android projects. 10 | 11 | 1. Eclipse 12 | 2. Command Line 13 | 14 | ### Import Project in Eclipse 15 | 16 | #### Features: 17 | 18 | 1. Complete workflow from Eclipse, including: 19 | * Build C++. 20 | * Clean C++. 21 | * Build and Run whole project. 22 | * Logcat view. 23 | * Debug Java code. 24 | * Javascript editor. 25 | * Project management. 26 | 2. True C++ editing, including: 27 | * Code completion. 28 | * Jump to definition. 29 | * Refactoring tools etc. 30 | * Quick open C++ files. 31 | 32 | 33 | #### Setup Eclipse Environment (only once) 34 | 35 | 36 | **NOTE:** This step needs to be done only once to setup the Eclipse environment for cocos2d-x projects. Skip this section if you've done this before. 37 | 38 | 1. Download Eclipse ADT bundle from [Google ADT homepage](http://developer.android.com/sdk/index.html) 39 | 40 | **OR** 41 | 42 | Install Eclipse with Java. Add ADT and CDT plugins. 43 | 44 | 2. Only for Windows 45 | 1. Install [Cygwin](http://www.cygwin.com/) with make (select make package from the list during the install). 46 | 2. Add `Cygwin\bin` directory to system PATH variable. 47 | 3. Add this line `none /cygdrive cygdrive binary,noacl,posix=0,user 0 0` to `Cygwin\etc\fstab` file. 48 | 49 | 3. Set up Variables: 50 | 1. Path Variable `COCOS2DX`: 51 | * Eclipse->Preferences->General->Workspace->**Linked Resources** 52 | * Click **New** button to add a Path Variable `COCOS2DX` pointing to the root cocos2d-x directory. 53 | ![Example](https://lh5.googleusercontent.com/-oPpk9kg3e5w/UUOYlq8n7aI/AAAAAAAAsdQ/zLA4eghBH9U/s400/cocos2d-x-eclipse-vars.png) 54 | 55 | 2. C/C++ Environment Variable `NDK_ROOT`: 56 | * Eclipse->Preferences->C/C++->Build->**Environment**. 57 | * Click **Add** button and add a new variable `NDK_ROOT` pointing to the root NDK directory. 58 | ![Example](https://lh3.googleusercontent.com/-AVcY8IAT0_g/UUOYltoRobI/AAAAAAAAsdM/22D2J9u3sig/s400/cocos2d-x-eclipse-ndk.png) 59 | * Only for Windows: Add new variables **CYGWIN** with value `nodosfilewarning` and **SHELLOPTS** with value `igncr` 60 | 61 | 4. Import libcocos2dx library project: 62 | 1. File->New->Project->Android Project From Existing Code. 63 | 2. Click **Browse** button and open `cocos2d-x/cocos2dx/platform/android/java` directory. 64 | 3. Click **Finish** to add project. 65 | 66 | #### Adding and running from Eclipse 67 | 68 | ![Example](https://lh3.googleusercontent.com/-SLBOu6e3QbE/UUOcOXYaGqI/AAAAAAAAsdo/tYBY2SylOSM/s288/cocos2d-x-eclipse-project-from-code.png) ![Import](https://lh5.googleusercontent.com/-XzC9Pn65USc/UUOcOTAwizI/AAAAAAAAsdk/4b6YM-oim9Y/s400/cocos2d-x-eclipse-import-project.png) 69 | 70 | 1. File->New->Project->Android Project From Existing Code 71 | 2. **Browse** to your project directory. eg: `cocos2d-x/cocos2dx/samples/Cpp/TestCpp/proj.android/` 72 | 3. Add the project 73 | 4. Click **Run** or **Debug** to compile C++ followed by Java and to run on connected device or emulator. 74 | 75 | 76 | ### Running project from Command Line 77 | 78 | $ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/ 79 | $ export NDK_ROOT=/path/to/ndk 80 | $ ./build_native.sh 81 | $ ant debug install 82 | 83 | If the last command results in sdk.dir missing error then do: 84 | 85 | $ android list target 86 | $ android update project -p . -t (id from step 6) 87 | $ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6) 88 | -------------------------------------------------------------------------------- /proj.android/ant.properties: -------------------------------------------------------------------------------- 1 | # This file is used to override default values used by the Ant build system. 2 | # 3 | # This file must be checked into Version Control Systems, as it is 4 | # integral to the build system of your project. 5 | 6 | # This file is only used by the Ant script. 7 | 8 | # You can use this to override default values such as 9 | # 'source.dir' for the location of your java source folder and 10 | # 'out.dir' for the location of your output folder. 11 | 12 | # You can also use it define how the release builds are signed by declaring 13 | # the following properties: 14 | # 'key.store' for the location of your keystore and 15 | # 'key.alias' for the name of the key to use. 16 | # The password will be asked during the build when you use the 'release' target. 17 | 18 | -------------------------------------------------------------------------------- /proj.android/assets/AllSprites.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/AllSprites.png -------------------------------------------------------------------------------- /proj.android/assets/audio/click.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/audio/click.WAV -------------------------------------------------------------------------------- /proj.android/assets/audio/create.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/audio/create.WAV -------------------------------------------------------------------------------- /proj.android/assets/audio/eat.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/audio/eat.WAV -------------------------------------------------------------------------------- /proj.android/assets/audio/move.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/audio/move.WAV -------------------------------------------------------------------------------- /proj.android/assets/audio/next_round.WAV: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/audio/next_round.WAV -------------------------------------------------------------------------------- /proj.android/assets/fonts/Marker Felt.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/fonts/Marker Felt.ttf -------------------------------------------------------------------------------- /proj.android/assets/star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/assets/star.png -------------------------------------------------------------------------------- /proj.android/bin/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | 10 | 12 | 13 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /proj.android/bin/R.txt: -------------------------------------------------------------------------------- 1 | int color sliding_menu_background 0x7f030002 2 | int color sliding_menu_body_background 0x7f030003 3 | int color sliding_menu_item_down 0x7f030000 4 | int color sliding_menu_item_release 0x7f030001 5 | int drawable auth_follow_cb_chd 0x7f020000 6 | int drawable auth_follow_cb_unc 0x7f020001 7 | int drawable auth_title_back 0x7f020002 8 | int drawable btn_back_nor 0x7f020003 9 | int drawable btn_cancel_back 0x7f020004 10 | int drawable edittext_back 0x7f020005 11 | int drawable gray_point 0x7f020006 12 | int drawable ic_launcher 0x7f020007 13 | int drawable icon 0x7f020008 14 | int drawable img_cancel 0x7f020009 15 | int drawable logo 0x7f02000a 16 | int drawable logo_email 0x7f02000b 17 | int drawable logo_evernote 0x7f02000c 18 | int drawable logo_qq 0x7f02000d 19 | int drawable logo_qzone 0x7f02000e 20 | int drawable logo_renren 0x7f02000f 21 | int drawable logo_shortmessage 0x7f020010 22 | int drawable logo_sinaweibo 0x7f020011 23 | int drawable logo_wechatfavorite 0x7f020012 24 | int drawable pin 0x7f020013 25 | int drawable share_tb_back 0x7f020014 26 | int drawable share_vp_back 0x7f020015 27 | int drawable ssdk_auth_title_back 0x7f020016 28 | int drawable ssdk_back_arr 0x7f020017 29 | int drawable ssdk_logo 0x7f020018 30 | int drawable ssdk_title_div 0x7f020019 31 | int drawable title_back 0x7f02001a 32 | int drawable title_shadow 0x7f02001b 33 | int drawable white_point 0x7f02001c 34 | int string app_downloading 0x7f04003a 35 | int string app_name 0x7f04003d 36 | int string app_upload 0x7f040072 37 | int string app_upload_extinfo 0x7f040073 38 | int string buy_failed 0x7f040082 39 | int string buy_success 0x7f040081 40 | int string cancel 0x7f040000 41 | int string customer_douban 0x7f040055 42 | int string customer_facebook 0x7f040056 43 | int string customer_kaixin 0x7f04005d 44 | int string customer_nemb 0x7f040057 45 | int string customer_qzone 0x7f04005a 46 | int string customer_renren 0x7f040058 47 | int string customer_sina 0x7f040059 48 | int string customer_sohu 0x7f04005e 49 | int string customer_suishenkan 0x7f040060 50 | int string customer_tencent 0x7f04005b 51 | int string customer_tumblr 0x7f040061 52 | int string customer_twitter 0x7f04005c 53 | int string customer_youdao 0x7f04005f 54 | int string demo_get_access_token 0x7f040050 55 | int string demo_get_my_info 0x7f040051 56 | int string demo_get_other_info 0x7f040052 57 | int string demo_share_all 0x7f04004f 58 | int string demo_share_all_gui 0x7f04004e 59 | int string douban 0x7f040026 60 | int string download_faield 0x7f040039 61 | int string dropbox 0x7f040030 62 | int string email 0x7f040021 63 | int string emoji_upload 0x7f04006a 64 | int string emoji_upload_bm 0x7f04006c 65 | int string emoji_upload_url 0x7f04006b 66 | int string evenote_title 0x7f040065 67 | int string evernote 0x7f040028 68 | int string facebook 0x7f04001d 69 | int string failed_to_start_incentive_page 0x7f040038 70 | int string file_upload 0x7f040074 71 | int string finish 0x7f040001 72 | int string flickr 0x7f04002e 73 | int string foursquare 0x7f04002b 74 | int string get_other_info_format 0x7f04004c 75 | int string get_sina_friends_list 0x7f040053 76 | int string get_tencent_friends_list 0x7f040054 77 | int string get_token_format 0x7f04004a 78 | int string get_user_info_format 0x7f04004b 79 | int string google_plus_client_inavailable 0x7f040012 80 | int string googleplus 0x7f04002a 81 | int string image_upload 0x7f040067 82 | int string image_upload_bitmap 0x7f040068 83 | int string image_upload_url 0x7f040069 84 | int string incentive_title 0x7f040037 85 | int string instagram 0x7f040032 86 | int string instagram_client_inavailable 0x7f040015 87 | int string kaixin 0x7f040020 88 | int string laiwang 0x7f040083 89 | int string linkedin 0x7f040029 90 | int string list_friends 0x7f040009 91 | int string mingdao 0x7f040035 92 | int string mingdao_share_content 0x7f04003b 93 | int string more 0x7f04003e 94 | int string multi_share 0x7f040005 95 | int string music_upload 0x7f04006d 96 | int string neteasemicroblog 0x7f040025 97 | int string not_yet_authorized 0x7f040062 98 | int string pinterest 0x7f04002d 99 | int string pinterest_client_inavailable 0x7f040014 100 | int string plz_choose_wechat 0x7f040049 101 | int string pull_to_refresh 0x7f04000b 102 | int string qq 0x7f04002c 103 | int string qq_client_inavailable 0x7f040013 104 | int string qzone 0x7f040019 105 | int string qzone_add_blog_sample 0x7f040079 106 | int string qzone_customer_share_style 0x7f040084 107 | int string receive_rewards 0x7f040080 108 | int string refreshing 0x7f04000d 109 | int string release_to_refresh 0x7f04000c 110 | int string renren 0x7f04001f 111 | int string select_one_plat_at_least 0x7f040008 112 | int string share 0x7f040004 113 | int string share_canceled 0x7f040007 114 | int string share_completed 0x7f040006 115 | int string share_content 0x7f040063 116 | int string share_content_short 0x7f040064 117 | int string share_failed 0x7f04000a 118 | int string share_to 0x7f040003 119 | int string share_to_favorite 0x7f040077 120 | int string share_to_format 0x7f04004d 121 | int string share_to_mingdao 0x7f04003c 122 | int string share_to_moment 0x7f040076 123 | int string share_to_qzone 0x7f040036 124 | int string share_to_wechat 0x7f040075 125 | int string share_to_yixin 0x7f04007c 126 | int string share_to_yixin_favorite 0x7f04007e 127 | int string share_to_yixin_moment 0x7f04007d 128 | int string sharing 0x7f040002 129 | int string shortmessage 0x7f040022 130 | int string sinaweibo 0x7f040017 131 | int string sm_item_about 0x7f040048 132 | int string sm_item_auth 0x7f040040 133 | int string sm_item_customer 0x7f040043 134 | int string sm_item_demo 0x7f04003f 135 | int string sm_item_fl_tc 0x7f040045 136 | int string sm_item_fl_weibo 0x7f040044 137 | int string sm_item_visit_website 0x7f040047 138 | int string sm_item_visit_wechat 0x7f040046 139 | int string sm_item_wechat 0x7f040041 140 | int string sm_item_yixin 0x7f040042 141 | int string sohumicroblog 0x7f040023 142 | int string sohusuishenkan 0x7f040024 143 | int string tencentweibo 0x7f040018 144 | int string tumblr 0x7f04002f 145 | int string twitter 0x7f04001e 146 | int string update 0x7f040066 147 | int string video_upload 0x7f04006e 148 | int string vkontakte 0x7f040031 149 | int string webpage_upload 0x7f04006f 150 | int string webpage_upload_bitmap 0x7f040070 151 | int string webpage_upload_url 0x7f040071 152 | int string website 0x7f04000f 153 | int string wechat 0x7f04001a 154 | int string wechat_client_inavailable 0x7f040011 155 | int string wechat_client_is_not_installed_correctly 0x7f04007a 156 | int string wechat_client_not_support_following_operation 0x7f04007b 157 | int string wechat_demo_title 0x7f040078 158 | int string wechatfavorite 0x7f04001c 159 | int string wechatmoments 0x7f04001b 160 | int string weibo_oauth_regiseter 0x7f04000e 161 | int string weibo_upload_content 0x7f040010 162 | int string yixin 0x7f040033 163 | int string yixin_client_inavailable 0x7f040016 164 | int string yixin_demo_title 0x7f04007f 165 | int string yixinmoments 0x7f040034 166 | int string youdao 0x7f040027 167 | int style AppTheme 0x7f050000 168 | -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/BuildConfig.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/BuildConfig.class -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/Four.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/Four.class -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/R$attr.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/R$attr.class -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/R$drawable.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/R$drawable.class -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/R$string.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/R$string.class -------------------------------------------------------------------------------- /proj.android/bin/classes/edu/nju/four/R.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/bin/classes/edu/nju/four/R.class -------------------------------------------------------------------------------- /proj.android/bin/jarlist.cache: -------------------------------------------------------------------------------- 1 | # cache for current jar dependency. DO NOT EDIT. 2 | # format is 3 | # Encoding is UTF-8 4 | -------------------------------------------------------------------------------- /proj.android/build.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 9 | 29 | 30 | 31 | 40 | 41 | 42 | 43 | 47 | 48 | 60 | 61 | 62 | 80 | 81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /proj.android/build_native.sh: -------------------------------------------------------------------------------- 1 | APPNAME="Four" 2 | 3 | # options 4 | 5 | buildexternalsfromsource= 6 | 7 | usage(){ 8 | cat << EOF 9 | usage: $0 [options] 10 | 11 | Build C/C++ code for $APPNAME using Android NDK 12 | 13 | OPTIONS: 14 | -s Build externals from source 15 | -h this help 16 | EOF 17 | } 18 | 19 | while getopts "sh" OPTION; do 20 | case "$OPTION" in 21 | s) 22 | buildexternalsfromsource=1 23 | ;; 24 | h) 25 | usage 26 | exit 0 27 | ;; 28 | esac 29 | done 30 | 31 | # paths 32 | 33 | if [ -z "${NDK_ROOT+aaa}" ];then 34 | echo "please define NDK_ROOT" 35 | exit 1 36 | fi 37 | 38 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 39 | # ... use paths relative to current directory 40 | COCOS2DX_ROOT="$DIR/../../.." 41 | APP_ROOT="$DIR/.." 42 | APP_ANDROID_ROOT="$DIR" 43 | 44 | echo "NDK_ROOT = $NDK_ROOT" 45 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT" 46 | echo "APP_ROOT = $APP_ROOT" 47 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT" 48 | 49 | # make sure assets is exist 50 | if [ -d "$APP_ANDROID_ROOT"/assets ]; then 51 | rm -rf "$APP_ANDROID_ROOT"/assets 52 | fi 53 | 54 | mkdir "$APP_ANDROID_ROOT"/assets 55 | 56 | # copy resources 57 | for file in "$APP_ROOT"/Resources/* 58 | do 59 | if [ -d "$file" ]; then 60 | cp -rf "$file" "$APP_ANDROID_ROOT"/assets 61 | fi 62 | 63 | if [ -f "$file" ]; then 64 | cp "$file" "$APP_ANDROID_ROOT"/assets 65 | fi 66 | done 67 | 68 | # run ndk-build 69 | if [[ "$buildexternalsfromsource" ]]; then 70 | echo "Building external dependencies from source" 71 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ 72 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source" 73 | else 74 | echo "Using prebuilt externals" 75 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \ 76 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt" 77 | fi 78 | -------------------------------------------------------------------------------- /proj.android/gen/edu/nju/four/BuildConfig.java: -------------------------------------------------------------------------------- 1 | /** Automatically generated file. DO NOT MODIFY */ 2 | package edu.nju.four; 3 | 4 | public final class BuildConfig { 5 | public final static boolean DEBUG = true; 6 | } -------------------------------------------------------------------------------- /proj.android/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/ic_launcher-web.png -------------------------------------------------------------------------------- /proj.android/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_MODULE := cocos2dcpp_shared 6 | 7 | LOCAL_MODULE_FILENAME := libcocos2dcpp 8 | 9 | #MY_CPP_LIST := $(wildcard $(LOCAL_PATH)/*.cpp) 10 | #MY_CPP_LIST += $(wildcard $(LOCAL_PATH)/hellocpp/*.cpp) 11 | #MY_CPP_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp) 12 | 13 | #LOCAL_SRC_FILES := $(MY_CPP_LIST:$(LOCAL_PATH)/%=%) 14 | 15 | #声明一个变量MY_CPP_PATH表示源码目录 16 | MY_CPP_PATH := $(LOCAL_PATH)/hellocpp/ 17 | MY_CPP_PATH += $(LOCAL_PATH)/../../Classes/ 18 | 19 | My_All_Files := $(shell find $(MY_CPP_PATH)/.) 20 | My_All_Files := $(My_All_Files:$(MY_CPP_PATH)/./%=$(MY_CPP_PATH)%) 21 | MY_CPP_LIST := $(filter %.cpp %.c,$(My_All_Files)) 22 | MY_CPP_LIST := $(MY_CPP_LIST:$(LOCAL_PATH)/%=%) 23 | 24 | 25 | #获取目录下的所有文件 26 | #My_All_Files := $(shell find $(MY_CPP_PATH)/.) 27 | #My_All_Files := $(My_All_Files:$(MY_CPP_PATH)/./%=$(MY_CPP_PATH)%) 28 | 29 | #从My_All_Files中再次提取所有的cpp文件,这里也可以使用filter函数 30 | #MY_CPP_LIST := $(foreach c_file,$(My_All_Files), $(wildcard $(c_file)/*.cpp) ) 31 | #MY_CPP_LIST := $(MY_CPP_LIST:$(LOCAL_PATH)/%=%) 32 | 33 | LOCAL_SRC_FILES := $(MY_CPP_LIST) 34 | 35 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ 36 | $(LOCAL_PATH)/../../Classes/C2DXShareSDK \ 37 | $(LOCAL_PATH)/../../Classes/C2DXShareSDK/Android \ 38 | $(LOCAL_PATH)/../../Classes/C2DXShareSDK/Android/JSON \ 39 | $(LOCAL_PATH)/../../Classes/C2DXShareSDK/Android/JSON/cJSON 40 | 41 | LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static 42 | LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static 43 | LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static 44 | LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static 45 | LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static 46 | 47 | include $(BUILD_SHARED_LIBRARY) 48 | 49 | $(call import-module,cocos2dx) 50 | $(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl) 51 | $(call import-module,CocosDenshion/android) 52 | $(call import-module,extensions) 53 | $(call import-module,external/Box2D) 54 | $(call import-module,external/chipmunk) 55 | -------------------------------------------------------------------------------- /proj.android/jni/Application.mk: -------------------------------------------------------------------------------- 1 | APP_STL := gnustl_static 2 | APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -DCOCOS2D_DEBUG=1 3 | APP_CPPFLAGS += -std=c++11 4 | NDK_TOOLCHAIN_VERSION=4.8 5 | APP_ABI := armeabi x86 -------------------------------------------------------------------------------- /proj.android/jni/hellocpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include "AppDelegate.h" 2 | #include "cocos2d.h" 3 | #include "CCEventType.h" 4 | #include "platform/android/jni/JniHelper.h" 5 | #include 6 | #include 7 | 8 | #define LOG_TAG "main" 9 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__) 10 | 11 | using namespace cocos2d; 12 | 13 | extern "C" 14 | { 15 | 16 | jint JNI_OnLoad(JavaVM *vm, void *reserved) 17 | { 18 | JniHelper::setJavaVM(vm); 19 | 20 | return JNI_VERSION_1_4; 21 | } 22 | 23 | void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h) 24 | { 25 | if (!CCDirector::sharedDirector()->getOpenGLView()) 26 | { 27 | CCEGLView *view = CCEGLView::sharedOpenGLView(); 28 | view->setFrameSize(w, h); 29 | 30 | AppDelegate *pAppDelegate = new AppDelegate(); 31 | CCApplication::sharedApplication()->run(); 32 | } 33 | else 34 | { 35 | ccGLInvalidateStateCache(); 36 | CCShaderCache::sharedShaderCache()->reloadDefaultShaders(); 37 | ccDrawInit(); 38 | CCTextureCache::reloadAllTextures(); 39 | CCNotificationCenter::sharedNotificationCenter()->postNotification(EVENT_COME_TO_FOREGROUND, NULL); 40 | CCDirector::sharedDirector()->setGLDefaultValues(); 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-Core-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-Core-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-Email-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-Email-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-QQ-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-QQ-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-QZone-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-QZone-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-Renren-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-Renren-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-ShortMessage-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-ShortMessage-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/ShareSDK-SinaWeibo-2.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/ShareSDK-SinaWeibo-2.3.7.jar -------------------------------------------------------------------------------- /proj.android/libs/armeabi/libcocos2dcpp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/armeabi/libcocos2dcpp.so -------------------------------------------------------------------------------- /proj.android/libs/libPluginProtocol.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/libPluginProtocol.jar -------------------------------------------------------------------------------- /proj.android/libs/mframework.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/mframework.jar -------------------------------------------------------------------------------- /proj.android/libs/x86/libcocos2dcpp.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/libs/x86/libcocos2dcpp.so -------------------------------------------------------------------------------- /proj.android/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /proj.android/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /proj.android/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-19 12 | 13 | android.library.reference.1=../../../cocos2dx/platform/android/java 14 | -------------------------------------------------------------------------------- /proj.android/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /proj.android/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/auth_follow_cb_chd.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/auth_follow_cb_chd.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/auth_follow_cb_unc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/auth_follow_cb_unc.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/auth_title_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/auth_title_back.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/btn_back_nor.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/btn_back_nor.9.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/btn_cancel_back.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/btn_cancel_back.9.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/edittext_back.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/edittext_back.9.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/gray_point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/gray_point.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/icon.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/img_cancel.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/img_cancel.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_email.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_email.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_evernote.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_evernote.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_qq.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_qq.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_qzone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_qzone.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_renren.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_renren.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_shortmessage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_shortmessage.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_sinaweibo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_sinaweibo.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/logo_wechatfavorite.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/logo_wechatfavorite.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/pin.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/share_tb_back.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/share_tb_back.9.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/share_vp_back.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/share_vp_back.9.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/ssdk_auth_title_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/ssdk_auth_title_back.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/ssdk_back_arr.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/ssdk_back_arr.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/ssdk_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/ssdk_logo.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/ssdk_title_div.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/ssdk_title_div.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/title_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/title_back.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/title_shadow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/title_shadow.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xhdpi/white_point.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xhdpi/white_point.png -------------------------------------------------------------------------------- /proj.android/res/drawable-xxhdpi/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.android/res/drawable-xxhdpi/logo.png -------------------------------------------------------------------------------- /proj.android/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ff39393b 4 | #00000000 5 | #ff2c2c2e 6 | #fff5f5f5 7 | 8 | -------------------------------------------------------------------------------- /proj.android/res/values/oks_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 取消 4 | 完成 5 | 分享操作正在后台进行… 6 | 分享到 7 | 分享 8 | 图文分享 9 | 分享成功 10 | 分享已取消 11 | 请选择一个目标平台 12 | %s的朋友 13 | 分享失败 14 | 下拉刷新 15 | 松开刷新 16 | 刷新中… 17 | -------------------------------------------------------------------------------- /proj.android/res/values/ssdk_strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 应用授权 4 | http://www.shareSDK.cn 5 | 分享图片 6 | 目前您的微信版本过低或未安装微信,需要安装微信才能使用 7 | Google+ 版本过低或者没有安装,需要升级或安装Google+才能使用! 8 | QQ 版本过低或者没有安装,需要升级或安装QQ才能使用! 9 | Pinterest版本过低或者没有安装,需要升级或安装Pinterest才能使用! 10 | Instagram版本过低或者没有安装,需要升级或安装Instagram才能使用! 11 | 目前您的易信版本过低或未安装易信,需要安装易信才能使用 12 | 13 | 新浪微博 14 | 腾讯微博 15 | QQ空间 16 | 微信好友 17 | 微信朋友圈 18 | 微信收藏 19 | Facebook 20 | Twitter 21 | 人人网 22 | 开心网 23 | 邮件 24 | 信息 25 | 搜狐微博 26 | 搜狐随身看 27 | 网易微博 28 | 豆瓣 29 | 有道云笔记 30 | 印象笔记 31 | Linked In 32 | Google+ 33 | FourSquare 34 | QQ 35 | Pinterest 36 | Flickr 37 | Tumblr 38 | Dropbox 39 | VK 40 | Instagram 41 | 易信 42 | 易信朋友圈 43 | 明道 44 | 45 | 分享到QQ空间 46 | 分享有奖 47 | 无法打开“分享有奖页面” 48 | 下载失败 49 | 应用正在后台下载 50 | 网页分享 51 | 分享到明道 52 | -------------------------------------------------------------------------------- /proj.android/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | Four 3 | 4 | 更多 5 | 接口 6 | 授权 7 | 微信 8 | 易信 9 | 自定义接口 10 | 关注新浪微博 11 | 关注腾讯微博 12 | 关注官方微信 13 | 关注官方网站 14 | Demo版本 Ver. %s 15 | 请选择微信客户端完成操作 16 | 获取%s的AccessToken 17 | 获取%s授权用户资料 18 | 获取%s其他用户资料 19 | 分享到%s 20 | 21 | 分享全部(有分享界面) 22 | 分享全部(无界面,直接分享) 23 | 获取AccessToken 24 | 获取授权用户资料 25 | 获取其他用户资料 26 | 27 | 获取新浪微博关注列表 28 | 获取腾讯微博关注列表 29 | 搜索用户 30 | 获取通知列表 31 | 获取推荐话题 32 | 上传照片到用户的相册 33 | 获取微博主页列表 34 | 发表日志到QQ空间 35 | 获取我的粉丝列表 36 | 获取主页列表 37 | 获取可能认识的人 38 | 获取好友列表 39 | 获取笔记本列表 40 | 获取搜狐随身看书签列表 41 | 获取Tumblr用户Post列表 42 | 43 | 尚未授权 44 | ShareSDK for Android不仅集成简单、支持如QQ好友、微信、新浪微博、腾讯微博等所有社交平台,而且还有强大的统计分析管理后台,实时了解用户、信息流、回流率、传播效应等数据,详情见官网http://sharesdk.cn @ShareSDK 45 | ShareSDK不仅集成简单、支持如微信、新浪微博、腾讯微博等社交平台,而且还有强大的统计分析管理后台,实时了解用户、信息流、回流率、传播效应等数据,详情见官网http://sharesdk.cn @ShareSDK 46 | ShareSDK是一个神奇的SDK 47 | 48 | 文字分享 49 | 图片分享(本地图片) 50 | 图片分享(Bitmap对象) 51 | 图片分享(网络图片) 52 | 表情分享(本地图片) 53 | 表情分享(网络图片) 54 | 表情分享(Bitmap对象) 55 | 音乐分享 56 | 视频分享 57 | 网页分享(本地图片) 58 | 网页分享(Bitmap对象) 59 | 网页分享(网络图片) 60 | 应用分享(携带文件) 61 | 应用分享(携带脚本) 62 | 文件分享 63 | 微信好友 64 | 微信朋友圈 65 | 微信收藏 66 | 微信分享Demo标题 67 |

QQ互联

轻松分享,快乐生活。详情请看。
68 | 微信客户端未安装或版本太旧 69 | 微信客户端不支持第三方应用执行关注功能 70 | 易信好友 71 | 易信朋友圈 72 | 易信收藏 73 | 易信分享Demo标题 74 | 恭喜你得到%s个金币! 75 | 购买成功 76 | 购买失败 77 | 来往 78 | 自定义QQ空间分享风格 79 |
80 | -------------------------------------------------------------------------------- /proj.android/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | -------------------------------------------------------------------------------- /proj.android/src/cn/sharesdk/onekeyshare/CustomerLogo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 官网地站:http://www.ShareSDK.cn 3 | * 技术支持QQ: 4006852216 4 | * 官方微信:ShareSDK (如果发布新版本的话,我们将会第一时间通过微信将版本更新内容推送给您。如果使用过程中有任何问题,也可以通过微信与我们取得联系,我们将会在24小时内给予回复) 5 | * 6 | * Copyright (c) 2013年 ShareSDK.cn. All rights reserved. 7 | */ 8 | 9 | package cn.sharesdk.onekeyshare; 10 | 11 | import android.graphics.Bitmap; 12 | import android.view.View.OnClickListener; 13 | 14 | /** 九宫格自定义的图标对象 */ 15 | public class CustomerLogo { 16 | public String label; 17 | public Bitmap logo; 18 | public OnClickListener listener; 19 | } 20 | -------------------------------------------------------------------------------- /proj.android/src/cn/sharesdk/onekeyshare/PicViewer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 官网地站:http://www.ShareSDK.cn 3 | * 技术支持QQ: 4006852216 4 | * 官方微信:ShareSDK (如果发布新版本的话,我们将会第一时间通过微信将版本更新内容推送给您。如果使用过程中有任何问题,也可以通过微信与我们取得联系,我们将会在24小时内给予回复) 5 | * 6 | * Copyright (c) 2013年 ShareSDK.cn. All rights reserved. 7 | */ 8 | 9 | 10 | package cn.sharesdk.onekeyshare; 11 | 12 | import android.graphics.Bitmap; 13 | import android.view.View; 14 | import android.view.View.OnClickListener; 15 | import android.widget.ImageView; 16 | import android.widget.ImageView.ScaleType; 17 | import cn.sharesdk.framework.FakeActivity; 18 | 19 | /** 查看编辑页面中图片的例子 */ 20 | public class PicViewer extends FakeActivity implements OnClickListener { 21 | private ImageView ivViewer; 22 | private Bitmap pic; 23 | 24 | /** 设置图片用于浏览 */ 25 | public void setImageBitmap(Bitmap pic) { 26 | this.pic = pic; 27 | if (ivViewer != null) { 28 | ivViewer.setImageBitmap(pic); 29 | } 30 | } 31 | 32 | public void onCreate() { 33 | ivViewer = new ImageView(activity); 34 | ivViewer.setScaleType(ScaleType.CENTER_INSIDE); 35 | ivViewer.setBackgroundColor(0xc0000000); 36 | ivViewer.setOnClickListener(this); 37 | activity.setContentView(ivViewer); 38 | if (pic != null && !pic.isRecycled()) { 39 | ivViewer.setImageBitmap(pic); 40 | } 41 | } 42 | 43 | public void onClick(View v) { 44 | finish(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /proj.android/src/cn/sharesdk/onekeyshare/ShareContentCustomizeCallback.java: -------------------------------------------------------------------------------- 1 | package cn.sharesdk.onekeyshare; 2 | 3 | import cn.sharesdk.framework.Platform; 4 | import cn.sharesdk.framework.Platform.ShareParams; 5 | 6 | public interface ShareContentCustomizeCallback { 7 | 8 | public void onShare(Platform platform, ShareParams paramsToShare); 9 | 10 | } 11 | -------------------------------------------------------------------------------- /proj.android/src/cn/sharesdk/onekeyshare/ShareCore.java: -------------------------------------------------------------------------------- 1 | /* 2 | * 官网地站:http://www.ShareSDK.cn 3 | * 技术支持QQ: 4006852216 4 | * 官方微信:ShareSDK (如果发布新版本的话,我们将会第一时间通过微信将版本更新内容推送给您。如果使用过程中有任何问题,也可以通过微信与我们取得联系,我们将会在24小时内给予回复) 5 | * 6 | * Copyright (c) 2013年 ShareSDK.cn. All rights reserved. 7 | */ 8 | 9 | package cn.sharesdk.onekeyshare; 10 | 11 | import java.util.HashMap; 12 | import android.content.Context; 13 | import android.content.Intent; 14 | import android.content.pm.ResolveInfo; 15 | import android.text.TextUtils; 16 | import cn.sharesdk.framework.Platform; 17 | import cn.sharesdk.framework.Platform.ShareParams; 18 | import cn.sharesdk.framework.ShareSDK; 19 | 20 | /** 21 | * ShareCore是快捷分享的实际出口,此类使用了反射的方式,配合传递进来的HashMap, 22 | *构造{@link ShareParams}对象,并执行分享,使快捷分享不再需要考虑目标平台 23 | */ 24 | public class ShareCore { 25 | private ShareContentCustomizeCallback customizeCallback; 26 | 27 | /** 设置用于分享过程中,根据不同平台自定义分享内容的回调 */ 28 | public void setShareContentCustomizeCallback(ShareContentCustomizeCallback callback) { 29 | customizeCallback = callback; 30 | } 31 | 32 | /** 33 | * 向指定平台分享内容 34 | *

35 | * 注意:
36 | * 参数data的键值需要严格按照{@link ShareParams}不同子类具体字段来命名, 37 | *否则无法反射此字段,也无法设置其值。 38 | */ 39 | public boolean share(Platform plat, HashMap data) { 40 | if (plat == null || data == null) { 41 | return false; 42 | } 43 | 44 | String imagePath = (String) data.get("imagePath"); 45 | String viewToShare = (String) data.get("viewToShare"); 46 | if (TextUtils.isEmpty(imagePath) && !TextUtils.isEmpty(viewToShare)) { 47 | data.put("imagePath", data.get("viewToShare")); 48 | } 49 | 50 | ShareParams sp = new ShareParams(data); 51 | if (customizeCallback != null) { 52 | customizeCallback.onShare(plat, sp); 53 | } 54 | plat.share(sp); 55 | return true; 56 | } 57 | 58 | /** 判断指定平台是否使用客户端分享 */ 59 | public static boolean isUseClientToShare(Context context, String platform) { 60 | if ("Wechat".equals(platform) || "WechatMoments".equals(platform) 61 | || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform) 62 | || "Email".equals(platform) || "GooglePlus".equals(platform) 63 | || "QQ".equals(platform) || "Pinterest".equals(platform) 64 | || "Instagram".equals(platform) || "Yixin".equals(platform) 65 | || "YixinMoments".equals(platform) || "QZone".equals(platform) 66 | || "Mingdao".equals(platform)) { 67 | return true; 68 | } else if ("Evernote".equals(platform)) { 69 | Platform plat = ShareSDK.getPlatform(context, platform); 70 | if ("true".equals(plat.getDevinfo("ShareByAppClient"))) { 71 | return true; 72 | } 73 | } else if ("SinaWeibo".equals(platform)) { 74 | Platform plat = ShareSDK.getPlatform(context, platform); 75 | if ("true".equals(plat.getDevinfo("ShareByAppClient"))) { 76 | Intent test = new Intent(Intent.ACTION_SEND); 77 | test.setPackage("com.sina.weibo"); 78 | test.setType("image/*"); 79 | ResolveInfo ri = plat.getContext().getPackageManager().resolveActivity(test, 0); 80 | return (ri != null); 81 | } 82 | } 83 | 84 | return false; 85 | } 86 | 87 | /** 判断指定平台是否可以用来授权 */ 88 | public static boolean canAuthorize(Context context, String platform) { 89 | if ("Wechat".equals(platform) || "WechatMoments".equals(platform) 90 | || "WechatFavorite".equals(platform) || "ShortMessage".equals(platform) 91 | || "Email".equals(platform) || "GooglePlus".equals(platform) 92 | || "QQ".equals(platform) || "Pinterest".equals(platform) 93 | || "Yixin".equals(platform) || "YixinMoments".equals(platform)) { 94 | return false; 95 | } 96 | return true; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /proj.android/src/edu/nju/four/Four.java: -------------------------------------------------------------------------------- 1 | /**************************************************************************** 2 | Copyright (c) 2010-2011 cocos2d-x.org 3 | 4 | http://www.cocos2d-x.org 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. 23 | ****************************************************************************/ 24 | package edu.nju.four; 25 | 26 | import org.cocos2dx.lib.Cocos2dxActivity; 27 | import org.cocos2dx.lib.Cocos2dxGLSurfaceView; 28 | 29 | import cn.sharesdk.ShareSDKUtils; 30 | import android.os.Bundle; 31 | 32 | public class Four extends Cocos2dxActivity{ 33 | 34 | protected void onCreate(Bundle savedInstanceState){ 35 | super.onCreate(savedInstanceState); 36 | ShareSDKUtils.prepare(); 37 | } 38 | 39 | public Cocos2dxGLSurfaceView onCreateView() { 40 | Cocos2dxGLSurfaceView glSurfaceView = new Cocos2dxGLSurfaceView(this); 41 | // Four should create stencil buffer 42 | glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0); 43 | 44 | return glSurfaceView; 45 | } 46 | 47 | static { 48 | System.loadLibrary("cocos2dcpp"); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /proj.ios/AppController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @class RootViewController; 4 | 5 | @interface AppController : NSObject { 6 | UIWindow *window; 7 | RootViewController *viewController; 8 | } 9 | 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /proj.ios/AppController.mm: -------------------------------------------------------------------------------- 1 | #import "AppController.h" 2 | #import "EAGLView.h" 3 | #import "cocos2d.h" 4 | #import "AppDelegate.h" 5 | #import "RootViewController.h" 6 | 7 | @implementation AppController 8 | 9 | #pragma mark - 10 | #pragma mark Application lifecycle 11 | 12 | // cocos2d application instance 13 | static AppDelegate s_sharedApplication; 14 | 15 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 16 | 17 | // Override point for customization after application launch. 18 | 19 | // Add the view controller's view to the window and display. 20 | window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; 21 | 22 | // Init the EAGLView 23 | EAGLView *__glView = [EAGLView viewWithFrame: [window bounds] 24 | pixelFormat: kEAGLColorFormatRGB565 25 | depthFormat: GL_DEPTH24_STENCIL8_OES 26 | preserveBackbuffer: NO 27 | sharegroup: nil 28 | multiSampling: NO 29 | numberOfSamples: 0]; 30 | 31 | // Use RootViewController manage EAGLView 32 | viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; 33 | viewController.wantsFullScreenLayout = YES; 34 | viewController.view = __glView; 35 | 36 | // Set RootViewController to window 37 | if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) 38 | { 39 | // warning: addSubView doesn't work on iOS6 40 | [window addSubview: viewController.view]; 41 | } 42 | else 43 | { 44 | // use this method on ios6 45 | [window setRootViewController:viewController]; 46 | } 47 | 48 | [window makeKeyAndVisible]; 49 | 50 | [[UIApplication sharedApplication] setStatusBarHidden:true]; 51 | 52 | cocos2d::CCApplication::sharedApplication()->run(); 53 | 54 | return YES; 55 | } 56 | 57 | 58 | - (void)applicationWillResignActive:(UIApplication *)application { 59 | /* 60 | Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 61 | Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 62 | */ 63 | cocos2d::CCDirector::sharedDirector()->pause(); 64 | } 65 | 66 | - (void)applicationDidBecomeActive:(UIApplication *)application { 67 | /* 68 | Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 69 | */ 70 | cocos2d::CCDirector::sharedDirector()->resume(); 71 | } 72 | 73 | - (void)applicationDidEnterBackground:(UIApplication *)application { 74 | /* 75 | Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 76 | If your application supports background execution, called instead of applicationWillTerminate: when the user quits. 77 | */ 78 | cocos2d::CCApplication::sharedApplication()->applicationDidEnterBackground(); 79 | } 80 | 81 | - (void)applicationWillEnterForeground:(UIApplication *)application { 82 | /* 83 | Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background. 84 | */ 85 | cocos2d::CCApplication::sharedApplication()->applicationWillEnterForeground(); 86 | } 87 | 88 | - (void)applicationWillTerminate:(UIApplication *)application { 89 | /* 90 | Called when the application is about to terminate. 91 | See also applicationDidEnterBackground:. 92 | */ 93 | } 94 | 95 | 96 | #pragma mark - 97 | #pragma mark Memory management 98 | 99 | - (void)applicationDidReceiveMemoryWarning:(UIApplication *)application { 100 | /* 101 | Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later. 102 | */ 103 | } 104 | 105 | 106 | - (void)dealloc { 107 | [window release]; 108 | [super dealloc]; 109 | } 110 | 111 | 112 | @end 113 | -------------------------------------------------------------------------------- /proj.ios/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Default-568h@2x.png -------------------------------------------------------------------------------- /proj.ios/Default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Default.png -------------------------------------------------------------------------------- /proj.ios/Default@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Default@2x.png -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/project.xcworkspace/xcuserdata/wangxuanyi.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Four.xcodeproj/project.xcworkspace/xcuserdata/wangxuanyi.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/xcuserdata/wangxuanyi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 8 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/xcuserdata/wangxuanyi.xcuserdatad/xcschemes/Four.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/xcuserdata/wangxuanyi.xcuserdatad/xcschemes/LocationTest.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 51 | 52 | 58 | 59 | 60 | 61 | 62 | 63 | 69 | 70 | 76 | 77 | 78 | 79 | 81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /proj.ios/Four.xcodeproj/xcuserdata/wangxuanyi.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Four.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | LocationTest.xcscheme 13 | 14 | orderHint 15 | 2 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | 09EE9ADB1903C01400482CE4 21 | 22 | primary 23 | 24 | 25 | 1D6058900D05DD3D006BFB54 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /proj.ios/Icon-114.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-114.png -------------------------------------------------------------------------------- /proj.ios/Icon-120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-120.png -------------------------------------------------------------------------------- /proj.ios/Icon-144.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-144.png -------------------------------------------------------------------------------- /proj.ios/Icon-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-152.png -------------------------------------------------------------------------------- /proj.ios/Icon-57.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-57.png -------------------------------------------------------------------------------- /proj.ios/Icon-72.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-72.png -------------------------------------------------------------------------------- /proj.ios/Icon-76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrNerverDie/Four/39c9acc41bd0a1ed68a325ae21d842eac6ab2dc6/proj.ios/Icon-76.png -------------------------------------------------------------------------------- /proj.ios/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | Icon-57.png 13 | CFBundleIconFiles 14 | 15 | Icon.png 16 | Icon@2x.png 17 | Icon-57.png 18 | Icon-114.png 19 | Icon-72.png 20 | Icon-144.png 21 | Icon-76.png 22 | Icon-120.png 23 | Icon-152.png 24 | 25 | CFBundleIdentifier 26 | edu.nju.four 27 | CFBundleInfoDictionaryVersion 28 | 6.0 29 | CFBundleName 30 | ${PRODUCT_NAME} 31 | CFBundlePackageType 32 | APPL 33 | CFBundleShortVersionString 34 | 35 | CFBundleSignature 36 | ???? 37 | CFBundleVersion 38 | 1.0 39 | LSRequiresIPhoneOS 40 | 41 | UIAppFonts 42 | 43 | UISupportedInterfaceOrientations 44 | 45 | UIInterfaceOrientationPortrait 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /proj.ios/LocationTest/LocationTest.1: -------------------------------------------------------------------------------- 1 | .\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples. 2 | .\"See Also: 3 | .\"man mdoc.samples for a complete listing of options 4 | .\"man mdoc for the short list of editing options 5 | .\"/usr/share/misc/mdoc.template 6 | .Dd 14-4-20 \" DATE 7 | .Dt LocationTest 1 \" Program name and manual section number 8 | .Os Darwin 9 | .Sh NAME \" Section Header - required - don't modify 10 | .Nm LocationTest, 11 | .\" The following lines are read in generating the apropos(man -k) database. Use only key 12 | .\" words here as the database is built based on the words here and in the .ND line. 13 | .Nm Other_name_for_same_program(), 14 | .Nm Yet another name for the same program. 15 | .\" Use .Nm macro to designate other names for the documented program. 16 | .Nd This line parsed for whatis database. 17 | .Sh SYNOPSIS \" Section Header - required - don't modify 18 | .Nm 19 | .Op Fl abcd \" [-abcd] 20 | .Op Fl a Ar path \" [-a path] 21 | .Op Ar file \" [file] 22 | .Op Ar \" [file ...] 23 | .Ar arg0 \" Underlined argument - use .Ar anywhere to underline 24 | arg2 ... \" Arguments 25 | .Sh DESCRIPTION \" Section Header - required - don't modify 26 | Use the .Nm macro to refer to your program throughout the man page like such: 27 | .Nm 28 | Underlining is accomplished with the .Ar macro like this: 29 | .Ar underlined text . 30 | .Pp \" Inserts a space 31 | A list of items with descriptions: 32 | .Bl -tag -width -indent \" Begins a tagged list 33 | .It item a \" Each item preceded by .It macro 34 | Description of item a 35 | .It item b 36 | Description of item b 37 | .El \" Ends the list 38 | .Pp 39 | A list of flags and their descriptions: 40 | .Bl -tag -width -indent \" Differs from above in tag removed 41 | .It Fl a \"-a flag as a list item 42 | Description of -a flag 43 | .It Fl b 44 | Description of -b flag 45 | .El \" Ends the list 46 | .Pp 47 | .\" .Sh ENVIRONMENT \" May not be needed 48 | .\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1 49 | .\" .It Ev ENV_VAR_1 50 | .\" Description of ENV_VAR_1 51 | .\" .It Ev ENV_VAR_2 52 | .\" Description of ENV_VAR_2 53 | .\" .El 54 | .Sh FILES \" File used or created by the topic of the man page 55 | .Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact 56 | .It Pa /usr/share/file_name 57 | FILE_1 description 58 | .It Pa /Users/joeuser/Library/really_long_file_name 59 | FILE_2 description 60 | .El \" Ends the list 61 | .\" .Sh DIAGNOSTICS \" May not be needed 62 | .\" .Bl -diag 63 | .\" .It Diagnostic Tag 64 | .\" Diagnostic informtion here. 65 | .\" .It Diagnostic Tag 66 | .\" Diagnostic informtion here. 67 | .\" .El 68 | .Sh SEE ALSO 69 | .\" List links in ascending order by section, alphabetically within a section. 70 | .\" Please do not reference files that do not exist without filing a bug report 71 | .Xr a 1 , 72 | .Xr b 1 , 73 | .Xr c 1 , 74 | .Xr a 2 , 75 | .Xr b 2 , 76 | .Xr a 3 , 77 | .Xr b 3 78 | .\" .Sh BUGS \" Document known, unremedied bugs 79 | .\" .Sh HISTORY \" Document history if command behaves in a unique manner -------------------------------------------------------------------------------- /proj.ios/LocationTest/main.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // main.cpp 3 | // LocationTest 4 | // 5 | // Created by 王选易 on 14-4-20. 6 | // 7 | // 8 | 9 | #include 10 | 11 | int main(int argc, const char * argv[]) 12 | { 13 | 14 | // insert code here... 15 | std::cout << "Hello, World!\n"; 16 | return 0; 17 | } 18 | 19 | -------------------------------------------------------------------------------- /proj.ios/Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'iphone' target in the 'iphone' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #endif 9 | -------------------------------------------------------------------------------- /proj.ios/RootViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | 4 | @interface RootViewController : UIViewController { 5 | 6 | } 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /proj.ios/RootViewController.mm: -------------------------------------------------------------------------------- 1 | #import "RootViewController.h" 2 | 3 | 4 | @implementation RootViewController 5 | 6 | /* 7 | // The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad. 8 | - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 9 | if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) { 10 | // Custom initialization 11 | } 12 | return self; 13 | } 14 | */ 15 | 16 | /* 17 | // Implement loadView to create a view hierarchy programmatically, without using a nib. 18 | - (void)loadView { 19 | } 20 | */ 21 | 22 | /* 23 | // Implement viewDidLoad to do additional setup after loading the view, typically from a nib. 24 | - (void)viewDidLoad { 25 | [super viewDidLoad]; 26 | } 27 | 28 | */ 29 | // Override to allow orientations other than the default portrait orientation. 30 | // This method is deprecated on ios6 31 | - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 32 | return UIInterfaceOrientationIsLandscape( interfaceOrientation ); 33 | } 34 | 35 | // For ios6, use supportedInterfaceOrientations & shouldAutorotate instead 36 | - (NSUInteger) supportedInterfaceOrientations{ 37 | #ifdef __IPHONE_6_0 38 | return UIInterfaceOrientationMaskAllButUpsideDown; 39 | #endif 40 | } 41 | 42 | - (BOOL) shouldAutorotate { 43 | return YES; 44 | } 45 | 46 | //fix not hide status on ios7 47 | - (BOOL)prefersStatusBarHidden 48 | { 49 | return YES; 50 | } 51 | 52 | - (void)didReceiveMemoryWarning { 53 | // Releases the view if it doesn't have a superview. 54 | [super didReceiveMemoryWarning]; 55 | 56 | // Release any cached data, images, etc that aren't in use. 57 | } 58 | 59 | - (void)viewDidUnload { 60 | [super viewDidUnload]; 61 | // Release any retained subviews of the main view. 62 | // e.g. self.myOutlet = nil; 63 | } 64 | 65 | 66 | - (void)dealloc { 67 | [super dealloc]; 68 | } 69 | 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /proj.ios/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | // Under iOS and the Simulator, we can use an alternate Accelerometer interface 4 | #import "AccelerometerSimulation.h" 5 | 6 | int main(int argc, char *argv[]) { 7 | 8 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 9 | int retVal = UIApplicationMain(argc, argv, nil, @"AppController"); 10 | [pool release]; 11 | return retVal; 12 | } 13 | --------------------------------------------------------------------------------