-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathAnswer.js
More file actions
173 lines (159 loc) · 5.19 KB
/
Copy pathAnswer.js
File metadata and controls
173 lines (159 loc) · 5.19 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
173
// Answer.js v3.4.1
import { classmgr } from '../pzpr/classmgr.js';
import util from '../pzpr/util.js';
import { lang } from '../pzpr/env.js';
//---------------------------------------------------------------------------
// ★AnsCheckクラス 答えチェック関連の関数を扱う
//---------------------------------------------------------------------------
// 回答チェッククラス
// AnsCheckクラス
classmgr.makeCommon({
//---------------------------------------------------------
AnsCheck: {
initialize: function() {
this.inCheck = false;
this.checkOnly = false;
this.makeCheckList();
},
failcodemode: void 0,
failcode: void 0,
_info: void 0,
checklist: [],
//---------------------------------------------------------------------------
// ans.makeCheckList() 最初にchecklistの配列を生成する
//---------------------------------------------------------------------------
makeCheckList: function() {
/* 当該パズルで使用しないchecklistのアイテムをフィルタリング */
var checklist = this.checklist,
order = [];
for (var i = 0; i < checklist.length; i++) {
var item = checklist[i],
isexist = true,
prio = 0;
if (item.match("@")) {
isexist = util.checkpid(
item.substr(item.indexOf("@") + 1),
this.puzzle.pid
);
item = item.substr(0, item.indexOf("@"));
}
if (isexist) {
prio = (item.match(/\+/) || []).length;
item = item.replace(/\+/g, "");
order.push([this[item], prio]);
}
}
this.checklist_normal = [];
for (var i = 0; i < order.length; i++) {
this.checklist_normal.push(order[i][0]);
}
/* autocheck用のエラーをソートする */
order = order.sort(function(a, b) {
return b[1] - a[1];
});
this.checklist_auto = [];
for (var i = 0; i < order.length; i++) {
this.checklist_auto.push(order[i][0]);
}
},
//---------------------------------------------------------------------------
// ans.check() 答えのチェックを行う
// ans.checkAns() 答えのチェックを行い、エラーコードを返す(nullはNo Error)
//---------------------------------------------------------------------------
check: function(activemode) {
var puzzle = this.puzzle,
bd = this.board;
this.inCheck = true;
if (!!activemode) {
this.checkOnly = false;
this.checkAns(false);
if (!this.failcode.complete) {
bd.haserror = true;
puzzle.redraw(true); /* 描画キャッシュを破棄して描画し直す */
}
} else if (this.failcode === void 0 || this.failcodemode !== activemode) {
/* activemodeでなく、前回の判定結果が残っていない場合はチェックします */
bd.disableSetError();
this.checkOnly = true;
this.checkAns(activemode === false);
this.failcodemode = activemode;
bd.enableSetError();
}
/* activemodeでなく、前回の判定結果が残っている場合はそれを返します */
this.inCheck = false;
return this.failcode;
},
checkAns: function(break_if_error) {
this.failcode = new this.klass.CheckInfo();
var checkSingleError =
!this.puzzle.getConfig("multierr") || break_if_error;
var checklist =
this.checkOnly && checkSingleError
? this.checklist_auto
: this.checklist_normal;
for (var i = 0; i < checklist.length; i++) {
checklist[i].call(this);
if (checkSingleError && this.failcode.length > 0) {
break;
}
}
if (!break_if_error) {
this.failcode.text = this.failcode.gettext();
}
},
//---------------------------------------------------------------------------
// ans.resetCache() 前回のエラー情報等を破棄する
//---------------------------------------------------------------------------
resetCache: function() {
this.failcode = this.failcodemode = void 0;
this._info = {};
}
},
//---------------------------------------------------------------------------
// ★CheckInfoクラス ans.checkで返すインスタンスのクラス
//---------------------------------------------------------------------------
CheckInfo: {
initialize: function(code) {
this.add(code);
},
complete: true,
undecided: false,
text: "",
length: 0,
lastcode: null,
add: function(code) {
if (!code) {
return;
}
if (code !== this.lastcode) {
this[this.length++] = this.lastcode = code;
}
this.complete = false;
},
gettext: function(l_lang) {
var puzzle = this.puzzle,
textlist = puzzle.faillist,
texts = [];
var langcode = (l_lang || lang) === "ja" ? 0 : 1;
if (this.length === 0) {
return textlist.complete[langcode];
}
for (var i = 0; i < this.length; i++) {
var textitem = textlist[this[i]] || textlist.invalid;
texts.push(textitem[langcode]);
}
return texts.join("\n");
},
setUndecided: function() {
this.undecided = true;
}
},
//---------------------------------------------------------------------------
// ★FailCodeクラス 答えの文字列を扱う
//---------------------------------------------------------------------------
// FailCodeクラス
FailCode: {
complete: ["正解です!", "Complete!"],
invalid: ["不明なエラーです", "Invalid Error"]
}
});