-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutchallenge.h
215 lines (184 loc) · 3.66 KB
/
utchallenge.h
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
#ifndef __UTYPING_CHALLENGE
#define __UTYPING_CHALLENGE
#include "ututil.h"
enum{
CHALLENGE_HIDDEN, /* 隠れるの */
CHALLENGE_SUDDEN, /* 突然現れるの */
CHALLENGE_STEALTH, /* 見えないの */
CHALLENGE_LYRICS_STEALTH, /* 歌詞が見えないの */
CHALLENGE_SIN,
CHALLENGE_COS,
CHALLENGE_TAN,
CHALLENGE_NUM
};
class CChallenge{
public:
CChallenge();
void invalidate();
bool isEasy();
void reset();
void set(int pos);
void reset(int pos);
void flip(int pos);
bool test(int pos)const;
void speedUp();
void speedDown();
double speed()const; /* 流れる速さの標準との比を返す */
void keyUp();
void keyDown();
int key()const;
double frequencyRate()const; /* 周波数が何倍されるか */
void getStr(char *buf)const;
void read(FILE *fp);
void write(FILE *fp)const;
bool operator ==(CChallenge &challenge)const{
return m_isValid && challenge.m_isValid &&
(m_flags == challenge.m_flags && m_key == challenge.m_key);
/* どちらかも有効で、speed以外の項目が等しいとき */
}
private:
bool m_isValid;
bitset<CHALLENGE_NUM> m_flags;
int m_speed; /* 円が流れる速さの標準との比の10倍(intでもつため) */
int m_key;
};
CChallenge::CChallenge(){
reset();
}
void CChallenge::invalidate(){
m_isValid = false;
}
bool CChallenge::isEasy(){
if(m_key < 0){ /* 再生速度を遅くした */
return true;
}
return false;
}
void CChallenge::reset(){
m_isValid = true;
m_flags.reset();
m_speed = 10;
m_key = 0;
}
void CChallenge::set(int pos){
m_flags.set(pos);
}
void CChallenge::reset(int pos){
m_flags.reset(pos);
}
void CChallenge::flip(int pos){
m_flags.flip(pos);
}
bool CChallenge::test(int pos)const{
return m_flags.test(pos);
}
void CChallenge::speedUp(){
if(m_speed < 20){
m_speed++;
}else if(m_speed < 30){
m_speed += 2;
}else if(m_speed < 40){
m_speed += 5;
}
}
void CChallenge::speedDown(){
if(m_speed > 30){
m_speed -= 5;
}else if(m_speed > 20){
m_speed -= 2;
}else if(m_speed > 5){
m_speed--;
}
}
double CChallenge::speed()const{
return m_speed / 10.0;
}
void CChallenge::keyUp(){
if(m_key < 12){
m_key++;
}
}
void CChallenge::keyDown(){
if(m_key > -12){
m_key--;
}
}
int CChallenge::key()const{
return m_key;
}
double CChallenge::frequencyRate()const{
return pow(2.0, m_key / 12.0);
}
void CChallenge::getStr(char *buf)const{
if(!m_isValid){
strcpy(buf, "----");
return;
}
strcpy(buf, "");
{
char tmp[64];
sprintf(tmp, "x%.1f", speed());
strcat(buf, tmp);
}
if(test(CHALLENGE_SUDDEN)){
strcat(buf, "S");
}
if(test(CHALLENGE_HIDDEN)){
strcat(buf, "H");
}
if(test(CHALLENGE_STEALTH)){
strcat(buf, "C");
}
if(test(CHALLENGE_LYRICS_STEALTH)){
strcat(buf, "L");
}
if(m_key != 0){
char tmp[64];
sprintf(tmp, "%+d", m_key);
strcat(buf, tmp);
}
if(test(CHALLENGE_SIN)){
strcat(buf, "s");
}
if(test(CHALLENGE_COS)){
strcat(buf, "c");
}
if(test(CHALLENGE_TAN)){
strcat(buf, "t");
}
}
void CChallenge::read(FILE *fp){
reset();
for(int i=0; i<CHALLENGE_NUM; i++){
if(getc(fp)){
set(i);
}
}
for(int i=CHALLENGE_NUM; i<16; i++){
getc(fp);
}
readInt(m_speed, fp);
readInt(m_key, fp);
if(m_speed == 0){ /* 無効なときはすべて0なので、これを見ればOK */
m_isValid = false;
}else{
m_isValid = true;
}
}
void CChallenge::write(FILE *fp)const{
if(m_isValid){
for(int i=0; i<CHALLENGE_NUM; i++){
putc(test(i)?1:0, fp);
}
for(int i=CHALLENGE_NUM; i<16; i++){
putc(0, fp);
}
writeInt(m_speed, fp);
writeInt(m_key, fp);
}else{
for(int i=0; i<24; i++){
putc(0, fp);
}
}
}
#endif