-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
204 lines (165 loc) · 6.3 KB
/
index.html
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
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<style type="text/css">
table, td, th { border: 1px solid green; }
button { width:200px;height:30px; }
td:hover{ background-color:green; }
.selected { background-color:#FF004D; }
</style>
<script type="text/javascript">
var array;
var table_rows = 7;
var table_cols = 7;
var _drawTable = function ( ){
var row_val = document.getElementById( 'row_value');
var col_val = document.getElementById( 'col_value');
table_rows = row_val.value;
table_cols = col_val.value;
drawTable( row_val.value, col_val.value );
array = new Array (table_rows);
for ( var i =0; i < table_rows; i++){
array[i] = new Array( table_cols);
}
for ( var i = 0; i < table_rows; i++){
for ( var k = 0; k < table_cols; k++){
array[i][k] = -1;
}
}
$(".col").on("click", function(){
if ( $(this).hasClass("selected") ){
$(this).removeClass("selected");
var row = $(this).data("row");
var col = $(this).data("col");
array[row][col] = -1;
}else{
$(this).addClass("selected");
var row = $(this).data("row");
var col = $(this).data("col");
array[row][col] = 1;
}
});
}
var drawTable = function ( row, col ){
var table_tag = "";
for ( var i = 0; i < row; i++) {
var row_tag = "<tr>"
var col_tag = ""
for ( var k = 0; k < col; k++) {
col_tag += "<td data-row=\"" + i + "\" data-col=\"" + k + "\" class=\"col\" width=\"25\" height=\"25\"></td>"
}
row_tag += col_tag;
row_tag += "</tr>";
table_tag += row_tag;
}
var table = document.getElementById('table');
table.innerHTML = table_tag;
}
var makeNemoLogic = function(){
var output_str = "";
for ( var i =0; i < table_rows; i++){
var lastCount = 0;
var row_logic_number = ""
for ( var k = 0; k < table_cols; k++){
if ( ( array[i][k] == -1 ) && ( lastCount > 0) ){
if ( row_logic_number.length > 0 ){
row_logic_number += " / " + lastCount;
} else{
row_logic_number += "" + lastCount;
}
lastCount = 0;
} else if ( array[i][k] > -1 ){
lastCount += 1;
}
}
if ( lastCount > 0 ){
if ( row_logic_number.length > 0 ){
row_logic_number += " / " + lastCount;
} else {
row_logic_number += "" + lastCount;
}
} else if ( lastCount == 0 ){
if ( row_logic_number.length == 0 ) {
row_logic_number = "0";
}
}
console.log ("row " + i + " : " + row_logic_number);
output_str += ("row " + i + " : " + row_logic_number + "<br/>")
}
output_str += "<br/>";
for ( var i =0; i < table_cols; i++){
var lastCount = 0;
var col_logic_number = ""
for ( var k = 0; k < table_rows; k++){
if ( ( array[k][i] == -1 ) && ( lastCount > 0) ){
if ( col_logic_number.length > 0 ){
col_logic_number += " / " + lastCount;
} else{
col_logic_number += "" + lastCount;
}
lastCount = 0;
} else if ( array[k][i] > -1 ){
lastCount += 1;
}
}
if ( lastCount > 0 ){
if ( col_logic_number.length > 0 ){
col_logic_number += " / " + lastCount;
} else {
col_logic_number += "" + lastCount;
}
} else if ( lastCount == 0 ){
if ( col_logic_number.length == 0 ) {
col_logic_number = "0";
}
}
console.log ("col " + i + " : " + col_logic_number);
output_str += ("col " + i + " : " + col_logic_number + "<br/>");
}
$("#nemo_output").html( output_str );
}
</script>
</head>
<body>
<table id="table">
</table>
<div style="margin-top:20px; margin-left:20px;">
<input type="text" value="" size="3" id="row_value" style="height:30px;">
X
<input type="text" value="" size="3" id="col_value" style="height:30px;">
<button type="button" onclick="_drawTable()" > 네모판 만들기 </button>
</div>
<div style="margin-top:20px; margin-left:20px;">
<button type="button" onclick="makeNemoLogic()" > 네모 로직을 만들어줘! </button>
</div>
<div style="margin-top:30px;" id="nemo_output">
</div>
<script type="text/javascript">
(function(){
drawTable ( table_rows, table_cols);
array = new Array (table_rows);
for ( var i =0; i < table_rows; i++){
array[i] = new Array( table_cols);
}
for ( var i = 0; i < table_rows; i++){
for ( var k = 0; k < table_cols; k++){
array[i][k] = -1;
}
}
$(".col").on("click", function(){
if ( $(this).hasClass("selected") ){
$(this).removeClass("selected");
var row = $(this).data("row");
var col = $(this).data("col");
array[row][col] = -1;
}else{
$(this).addClass("selected");
var row = $(this).data("row");
var col = $(this).data("col");
array[row][col] = 1;
}
});
})();
</script>
</body>
</html>