-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathranklistScene.cpp
More file actions
172 lines (82 loc) · 3.48 KB
/
ranklistScene.cpp
File metadata and controls
172 lines (82 loc) · 3.48 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//this is ranklistScene.cpp
#include "ranklistScene.h"
#define setInt UserDefault::getInstance()->setIntegerForKey
#define getInt UserDefault::getInstance()->getIntegerForKey
using namespace std;
USING_NS_CC;
ranklistScene::ranklistScene(){
}
ranklistScene::~ranklistScene(){
}
bool ranklistScene:: init(){
if (!Layer::init()) {
return false;
}
Size visibleSize = Director::getInstance()->getVisibleSize();
Vec2 origin = Director::getInstance()->getVisibleOrigin();
//background
auto background = Sprite::create("bg_ending.jpg");
background->setScale(0.5);
background->setPosition(Vec2(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));
this->addChild(background, 0);
//"返回"button
auto backButton = MenuItemImage::create("button_back.png", "button_back_selected.png", CC_CALLBACK_1(ranklistScene::backCallback, this));
backButton->setAnchorPoint(Vec2(1,0));
backButton->setPosition(Vec2::ZERO);
backButton->setScale(0.3);
auto menu = Menu::create(backButton, NULL);
menu->setPosition(Vec2(visibleSize.width + origin.x, origin.y));
this->addChild(menu);
//title
auto title = Label::create("Ranklist", "Arial", 30);
title->setAnchorPoint(Vec2(0.5, 1));
title->setPosition(Vec2(visibleSize.width*0.5 + origin.x, visibleSize.height*0.95 + origin.y));
title->setColor(Color3B::WHITE);
this->addChild(title);
//data
auto no1 = Label::create("No.1 0", "Arial", 25);
no1->setAnchorPoint(Vec2(0, 0.5));
no1->setPosition(Vec2(visibleSize.width*0.35+origin.x, visibleSize.height*0.625+origin.y));
no1->setColor(Color3B::WHITE);
this->addChild(no1);
auto no2 = Label::create("No.2 0", "Arial", 25);
no2->setAnchorPoint(Vec2(0, 0.5));
no2->setPosition(Vec2(visibleSize.width*0.35+origin.x, visibleSize.height*0.5+origin.y));
no2->setColor(Color3B::WHITE);
this->addChild(no2);
auto no3 = Label::create("No.3 0", "Arial", 25);
no3->setAnchorPoint(Vec2(0, 0.5));
no3->setPosition(Vec2(visibleSize.width*0.35+origin.x, visibleSize.height*0.375+origin.y));
no3->setColor(Color3B::WHITE);
this->addChild(no3);
//更新游戏数据
sortScores();
no1->setString(StringUtils::format("No.1 %d",getInt("score1")));
no2->setString(StringUtils::format("No.2 %d",getInt("score2")));
no3->setString(StringUtils::format("No.3 %d",getInt("score3")));
return true;
}
Scene* ranklistScene:: createScene(){
auto layer = ranklistScene::create();
auto scene = Scene::create();
scene->addChild(layer);
return scene;
}
void ranklistScene:: toMainScene(){
auto scene = MenuLayer::createScene();
Director::getInstance()->replaceScene(scene);
}
void ranklistScene:: backCallback(Ref* pSender){
toMainScene();
}
void ranklistScene::sortScores(){
vector<int> scores;
scores.push_back(getInt("score1"));
scores.push_back(getInt("score2"));
scores.push_back(getInt("score3"));
scores.push_back(getInt("score"));
sort(scores.begin(), scores.end());
setInt("score1", scores[3]);
setInt("score2", scores[2]);
setInt("score3", scores[1]);
}