-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow_answer.php
executable file
·216 lines (197 loc) · 5.88 KB
/
show_answer.php
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
<html>
<head>
<script src ="http://code.jquery.com/jquery-1.11.1.js"></script>
<title>procon25 program test page </title>
<link rel="stylesheet" href="resources/index.css">
</head>
<body>
<A Href="add_problem.php">問題を追加</A></br>
<?php
// MySQLに接続
require 'info.php';
global $hostname,$user,$pass,$db_name;
$link = mysql_connect($hostname,$user,$pass);
if (!$link) {
die('error');
}
$db_selected = mysql_select_db($db_name, $link);
if(!$db_selected){
die('error');
}
if (!isset($_GET["score_id"])) {
die('error');
}
$sql = <<<EOS
SELECT answer_string FROM answers WHERE score_id=%d
EOS;
$res = mysql_query(sprintf($sql, intval($_GET["score_id"])));
while ($row = mysql_fetch_assoc($res)) {
echo "<pre>";
//echo $row["answer_string"];
echo "</pre>";;
$answer_string = $row["answer_string"];
}
$sql_str = "SELECT problem_id FROM score WHERE score_id=%d";
$respo = mysql_query(sprintf($sql_str,$_GET["score_id"]));
$id_str = mysql_result($respo,0);
$sql_splits = "SELECT columns,rows FROM problem_info WHERE problem_id=%d";
$respon = mysql_query(sprintf($sql_splits,$id_str));
$res_arr = mysql_fetch_array($respon,MYSQL_NUM);
$id_columns = $res_arr[0];
$id_rows = $res_arr[1];
$path = sprintf("imgs/%d/",$id_str);
list($w,$h) = getimagesize($path."00.png");
for($x=0;$x<$id_columns;$x++)
{
for($y=0;$y<$id_rows;$y++)
{
$position = sprintf("%X%X.png",$x,$y);
$img_path=sprintf("%s%s",$path,$position);
$img_id = sprintf("%d_%d",$x,$y);
echo sprintf("<Img Src='%s' id ='%s' style ='position: absolute; top: %d; left: %d;'>",$img_path,$img_id,$h*$y,$w*$x);
$blc_num1 = substr($answer_string, 2, 3);
}
}
$ans_str = json_encode($answer_string);
echo $row["answer_string"];
$version = $row["version"];
echo sprintf("<input style='position: absolute; top: 0; left: %d; 'type='button' name='spd_down' value='加速' onClick='spd_down()'>",50 + $w * $x);
echo sprintf("<input style='position: absolute; top: 0; left: %d; 'type='button' name='spd_up' value='減速' onClick='spd_up()'>",10 + $w * $x);
echo sprintf("<input style='position: absolute; top: 0; left: %d; 'type='button' name='reset' value='リセット' onClick='reset()'>",90 + $w * $x);
echo sprintf("");
echo sprintf("<pre style='position: absolute; top: 70; left: %d;'>", 10 + $w * $x);
echo $answer_string;
echo $version;
echo "</pre>"
?>
<script style ="text/javascript">
var spd = 250;
function spd_up() {
spd += 50;
}
function spd_down() {
spd -= 50;
}
function reset() {
window.location.reload();
}
function parse(answer) {
var lines = answer.split("\r\n"); // 行ごとに切り分ける
var array = []; // 書き出し先の配列
var i = 1; // 行番号 最初の行は飛ばす
// すべての行を読み終えるまで
while (i < lines.length) {
// 選択位置を読む
var sel = lines[i];
var x = parseInt(sel.charAt(0), 16); // 1文字目を16進数として読む
var y = parseInt(sel.charAt(1), 16); // 2文字目を16進数として読む
i++;
//array.push(["S", x, y]); // 選択を追加
array.push(["S"]);
array.push([x+"_"+y]);
i++; // 交換の数は読み飛ばす
// 交換操作を読む
var exchanges = lines[i].split(""); // 1文字ごとに切り分ける
// 交換操作を1つずつ配列に入れる
for (var j = 0; j < exchanges.length; j++) {
array.push([exchanges[j]]);
}
i++;
}
return array;
}
var len = <?php echo $h; ?>;
var wid = <?php echo $w; ?>;
function read_id(str){
var array = str.split("_");
var x_str = array[0];
var y_str = array[1];
var x = parseInt(x_str, 10);
var y = parseInt(y_str, 10);
return [x,y];
}
function write_id(x,y){
return "" + x + "_" + y;
}
function up(position){
$("#"+position).animate({top:"-="+len},spd);
console.log("up"+position);
}
function right(position){
$("#"+position).animate({left:"+="+wid},spd);
console.log("right"+position);
}
function left(position){
$("#"+position).animate({left:"-="+wid},spd);
console.log("left"+position);
}
function down(position){
$("#"+position).animate({top:"+="+len},spd);
console.log("down"+position);
}
//var img_id = "<?php echo $img_id; ?>";
function exchange_id(position1,position2){
$("#"+position1).attr('id',position2 + "_");
$("#"+position2).attr('id',position1);
$("#"+position2 + "_").attr('id', position2);
}
var i = 0;
var position;
var flag = 0;
var change_flg = 0;
function command_controll(){
if(ans_spl[i] == "U"){
var pos_id = read_id(""+position);
var position2 = write_id(pos_id[0],pos_id[1]-1);
$.when(up(position),down(position2)).then(function () {
exchange_id(position,position2);
position = position2;
});
}
if(ans_spl[i] == "R"){
var pos_id = read_id(""+position);
var position2 = write_id(pos_id[0]+1,pos_id[1]);
$.when(right(position),left(position2)).then(function () {
exchange_id(position,position2);
position = position2;
});
}
if(ans_spl[i] == "L"){
var pos_id = read_id(""+position);
var position2 = write_id(pos_id[0]-1,pos_id[1]);
$.when(left(position),right(position2)).then(function () {
exchange_id(position,position2);
position = position2;
});
}
if(ans_spl[i] == "D"){
var pos_id = read_id(""+position);
var position2 = write_id(pos_id[0],pos_id[1]+1);
$.when(down(position),up(position2)).then(function () {
exchange_id(position,position2);
position = position2;
});
}
if(flag > 0){
position = ans_spl[i];
flag-=1;
change_flg+=1;
}
if(ans_spl[i] == "S"){
flag+=1;
change_flg=0;
}
i++;
setTimeout(command_controll, spd);
}
window.onload = function(ans_str)
{
alert("画像に合わせて拡大または縮小してください");
var blc_num = <?php echo $ans_str; ?>;
ans_spl= parse(blc_num);
//setInterval(command_controll,spd);
command_controll();
}
</script>
</body>
</html>