Map.m
资源名称:PushBox.rar [点击查看]
上传用户:qhdwjd2004
上传日期:2020-12-29
资源大小:362k
文件大小:3k
源码类别:
iPhone
开发平台:
Objective-C
- #import "Map.h"
- @implementation Map
- // 加载关卡地图
- +(void)LoadChapter:(byte)index Data:(byte[])mapdata
- {
- FILE *fp;
- const char *filepath = Sys_Map_Path;
- fp=fopen(filepath, "r");
- if(fp!=NULL){
- fseek(fp, Map_LEN * index, SEEK_SET);
- fread(mapdata, Map_LEN, 1, fp);
- fclose(fp);
- }
- else
- {
- NSLog(@"fopen err");
- }
- }
- +(int)ChapterCount
- {
- int len = 0;
- FILE *fp = fopen(Sys_Map_Path, "r");
- if(fp != NULL)
- {
- fseek(fp, 0, SEEK_END);
- len = ftell(fp);
- fclose(fp);
- }
- return len/Map_LEN;
- }
- // 检查是否存在残局
- +(bool)CheckMessExist
- {
- FILE *fp;
- fp = fopen(MESS_PATH,"r");
- if(fp!=NULL)
- {
- fclose(fp);
- return YES;
- }
- else
- {
- return NO;
- }
- }
- // 保存残局
- +(void)SaveMess:(Mess)messdata
- {
- FILE *fp;
- const char *filepath = MESS_PATH;
- fp=fopen(filepath, "w");
- if(fp!=NULL){
- fwrite(&messdata, sizeof(Mess), 1, fp);
- fclose(fp);
- }
- else
- {
- NSLog(@"fopen err");
- }
- }
- // 加载残局数据
- +(Mess)LoadMess
- {
- Mess messdata;
- FILE *fp;
- const char *filepath = MESS_PATH;
- fp=fopen(filepath, "r");
- if(fp!=NULL){
- fread(&messdata, sizeof(Mess), 1, fp);
- fclose(fp);
- }
- else
- {
- NSLog(@"fopen err");
- }
- return messdata;
- }
- +(Mess)MessCopy:(Mess)source
- {
- Mess messcopy;
- messcopy.isCustom = source.isCustom;
- messcopy.chapterIndex = source.chapterIndex;
- messcopy.enableChapterCount = source.enableChapterCount;
- int i=0;
- for(;i<Map_LEN;i++)
- {
- messcopy.mapdata[i] = source.mapdata[i];
- }
- return messcopy;
- }
- // 加载自定义地图
- +(void)LoadMap:(NSString*)path Data:(byte[])mapdata
- {
- FILE *fp;
- const char *filepath = [path UTF8String];
- fp=fopen(filepath, "r");
- if(fp!=NULL){
- fseek(fp, 0, SEEK_SET);
- fread(mapdata, Map_LEN, 1, fp);
- fclose(fp);
- }
- else
- {
- NSLog(@"fopen err");
- }
- }
- // 删除自定义地图
- +(void)DeleteMap:(NSString*)path
- {
- remove([path UTF8String]);
- }
- // 检查文件是否存在
- +(bool)FileExist:(NSString*)path
- {
- FILE *fp;
- fp = fopen([path UTF8String],"r");
- if(fp!=NULL)
- {
- fclose(fp);
- return YES;
- }
- else
- {
- return NO;
- }
- }
- +(bool)DirExist:(NSString*)path
- {
- DIR *dir;
- dir = opendir([path UTF8String]);
- if(dir!=NULL)
- {
- closedir(dir);
- return YES;
- }
- else
- {
- return NO;
- }
- }
- +(bool)CreateDir:(NSString*)path
- {
- if(mkdir([path UTF8String], 0644)==0)
- {
- return YES;
- }
- else
- {
- return NO;
- }
- }
- // 获取随机数
- +(int)GetRandNum
- {
- srand(time(0));
- return rand();
- }
- @end