[cocos2d-iPhone] 游戏中简单加密,防止八门神器

常见情况下,定义玩家金钱

@property(nonatomic,assign)int userMoney;

这样貌似用八门神器是能修改的。

为防止直接搜索修改,通过设置 userMoney的setter和getter来存取具体数值

.h文件

@interface XXX : NSObject{
    int userCoin;//实际金钱值
}

@property(nonatomic,assign)int userMoney;

.m文件

-(int)userMoney{
    return userCoin+5678;//实际值加XXXX
}

-(void)setUserMoney:(int)userMoney{
    userCoin=userMoney-5678;//实际值减XXXX
}

 

 存档时,只需要保存userCoin值即可。

直接搜索userMoney数值是搜索不到的。

实际运行时通过xx.userMoney来使用

以上

 

posted @ 2013-07-01 14:39  allo_shuang  阅读(212)  评论(0编辑  收藏  举报