ScoreInfo.lua
1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
cc.exports.ScoreInfo = {}
local _map = {};
--积分配置表信息
local function init()
local configStr = cc.FileUtils:getInstance():getStringFromFile("res/config/gd_score.txt");
local function readLineFun(lineStr)
local info;
local contents = StringUtil.split(lineStr,'\t');
if #contents > 1 then
info = {};
info.level = tonumber(contents[1]);
info.score = tonumber(contents[2]);
info.name = contents[3];
end
return info;
end
local index = 1;
local function readLine(str)
local a,b = string.find(str,"\r\n");
if a then
local lineStr = string.sub(str,1,a-1);
if index > 2 then
local info = readLineFun(lineStr);
if info then
_map[info.level] = info;
end
end
index = index + 1;
str = string.sub(str,b+1);
readLine(str);
else
local info = readLineFun(str);
if info then
_map[info.level] = info;
end
end
end
readLine(configStr);
end
init();
--通过级别获取信息
function ScoreInfo.getScoreInfo(level)
return _map[level];
end
--通过积分获取积分信息
function ScoreInfo.getInfoByScore(score)
local info = nil;
for i,v in ipairs(_map) do
if score <= v.score then
info = v;
break;
end
end
if not info then
info = _map[#_map];
end
return info;
end
return ScoreInfo