zoukankan      html  css  js  c++  java
  • Cocos2d 之FlyBird开发---GameData类

    |   版权声明:本文为博主原创文章,未经博主允许不得转载。

            现在是大数据的时代,绝大多数的游戏也都离不开游戏数据的控制,简单的就是一般记录游戏的得分情况,高端大气上档次一点的就是记录和保存各方面的游戏数据。在Cocos2d-x中保存游戏数据的方式有多种详见:Cocos2d-x之数据的处理。在FlyBird游戏的数据方面只是保存了游戏的分数,见下代码:

    GameData.h

    #ifndef _GAME_DATA_H_
    #define _GAME_DATA_H_
     
    #include "cocos2d.h"
    USING_NS_CC;
     
    class GameData
    {
    public:
         static void initGameData();
         static int getGameData();
         static void keepGameData(int);
    };
     
    #endif // _GAME_DATA_H_
    

     

    GameData.cpp

    #include "GameData.h"
     
    void GameData::initGameData()
    {
         UserDefault::getInstance()->setIntegerForKey("best", 0);
         //UserDefault::getInstance()->flush();
    }
     
    int GameData::getGameData()
    {
         return UserDefault::getInstance()->getIntegerForKey("best");
    }
     
    void GameData::keepGameData(int nowScore)
    {
         int bestScore = UserDefault::getInstance()->getIntegerForKey("best");
         if (nowScore > bestScore)
                  UserDefault::getInstance()->setIntegerForKey("best", nowScore);
         UserDefault::getInstance()->flush();
    }
    

      

    函数功能详见:http://lipei95.blog.163.com/blog/static/257578646201671924726318/

    Apk打包详见: 

  • 相关阅读:
    csp-2020-s游记
    线性DP
    tarjan无向图
    tarjan有向图
    树前置知识普及
    hash
    可持久化线段树&主席树
    [HAOI 2015] 树上染色
    [Contest on 2020.11.24] Beetle
    [Contest on 2020.11.24] Candy
  • 原文地址:https://www.cnblogs.com/geore/p/5800170.html
Copyright © 2011-2022 走看看