-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.html
More file actions
318 lines (290 loc) · 13.4 KB
/
main.html
File metadata and controls
318 lines (290 loc) · 13.4 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
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
<!DOCTYPE html>
<html>
<head>
<title>main</title>
<script src="https://code.jQuery.com/jQuery-3.4.1.js"></script>
<script>
var y = 35;
var speed = 15;
var score = 0;
//충돌 감지
function collision () {
if (!($('#game_window').css('display') == 'none'))
{
var target = document.getElementById('character');
var obj1_target = document.getElementById('obj1');
var obj2_target = document.getElementById('obj2');
var obj3_target = document.getElementById('obj3');
var targetLeft = target.getBoundingClientRect().left;
var targetTop = target.getBoundingClientRect().top;
var obj1_targetLeft = obj1_target.getBoundingClientRect().left;
var obj1_targetTop = obj1_target.getBoundingClientRect().top;
var obj2_targetLeft = obj2_target.getBoundingClientRect().left;
var obj2_targetTop = obj2_target.getBoundingClientRect().top;
var obj3_targetLeft = obj3_target.getBoundingClientRect().left;
var obj3_targetTop = obj3_target.getBoundingClientRect().top;
//충돌 조건 계산
if ((obj1_targetLeft >= targetLeft && obj1_targetTop >= targetTop &&
obj1_targetTop <= targetTop + $('#character').height()) ||
(obj2_targetLeft >= targetLeft && obj2_targetTop >= targetTop &&
obj2_targetTop <= targetTop + $('#character').height()) ||
(obj3_targetLeft >= targetLeft && obj3_targetTop >= targetTop &&
obj3_targetTop <= targetTop + $('#character').height()))
{
$('#game_window').hide();
$('#result_score').html("score : " + score);
$('#gameOver_window').show();
score = 0;
}
}
}
window.onkeydown = function character_move() {
if(!($('#game_window').css('display') == 'none')) //현재 창이 활성화 된 상태인지 확인
{
// 방향키 조작
var character = document.getElementById('character');
if (event.keyCode == 38 && y > 35) //위 방향키 누름
{
y -= speed;
character.style.top = y + 'px';
}
else if (event.keyCode == 40 && y < 360) //아래 방향키 누름
{
y += speed;
character.style.top = y + 'px';
}
}
}
window.onload = function () {
// 도움말 창 켜기/끄기
var help = document.getElementById('help');
help.onclick = function () {
$('#help_window').show();
}
document.getElementById('help_close').onclick = function () {
$('#help_window').hide();
}
// 게임 창 켜기/끄기
var game = document.getElementById('game');
game.onclick = function () {
$('#game_window').show();
score = 0;
$('#score').html("점수 : 0");
}
document.getElementById('game_close').onclick = function () {
$('#game_window').hide();
}
//게임 결과창 끄기
var gameOver = document.getElementById('gameOver_close').onclick = function () {
$('#gameOver_window').hide();
}
// 충돌 감지
setInterval("collision()", 1000/10);
//게임 시스템
setInterval(function () {
var count = Math.floor(Math.random() * 3) + 1; // 1부터 3까지의 랜덤 정수
var obj_y = Math.floor(Math.random() * 400) + 35; //35부터 400까지 랜덤 정수
var obj1 = document.getElementById('obj1');
var obj2 = document.getElementById('obj2');
var obj3 = document.getElementById('obj3');
if(!($('#game_window').css('display') == 'none'))
{
switch(count)
{
case 1: //장애물 1개 등장
obj1.style.top = obj_y + 'px';
$('#obj1').show();
$('#obj1').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj1.style.left = 0;
})
break;
case 2: //장애물 2개 등장
obj1.style.top = obj_y + 'px';
$('#obj1').show();
$('#obj1').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj1.style.left = 0;
})
obj_y = Math.floor(Math.random() * 410) + 35;
obj2.style.top = obj_y + 'px';
$('#obj2').show();
$('#obj2').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj2.style.left = 0;
})
break;
case 3: //장애물 3개 등장
obj1.style.top = obj_y + 'px';
$('#obj1').show();
$('#obj1').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj1.style.left = 0;
})
obj_y = Math.floor(Math.random() * 410) + 35;
obj2.style.top = obj_y + 'px';
$('#obj2').show();
$('#obj2').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj2.style.left = 0;
})
obj_y = Math.floor(Math.random() * 410) + 35;
obj3.style.top = obj_y + 'px';
$('#obj3').show();
$('#obj3').animate({left: '550px'}, 1500, 'linear', function () {
$(this).hide(); obj3.style.left = 0;
})
break;
}
score += 100;
$('#score').html("점수 : " + score);
}
}, 2000)
// 시간 함수
var clock = document.getElementById('clock');
setInterval(function () {
var now = new Date();
var year = now.getFullYear(); //년도
var month = now.getMonth() + 1; //월
var date = now.getDate(); //일
var day = now.getDay(); //요일
switch(day)
{
case 0:
day = '(일)';
break;
case 1:
day = '(월)';
break;
case 2:
day = '(화)';
break;
case 3:
day = '(수)';
break;
case 4:
day = '(목)';
break;
case 5:
day = '(금)';
break;
case 6:
day = '(토)';
break;
}
var hours = now.getHours(); //시간
var min = now.getMinutes(); //분
var sec = now.getSeconds(); //초
clock.innerHTML = year + '/' + month + '/' + date + ' ' + day + ' ' + hours + ':' + min + ':' + sec;
}, 1000);
}
</script>
<!-- 컴퓨터 디자인 -->
<link rel="stylesheet" href="computer_style.css">
<!-- 그 외 디자인(게임창) -->
<style>
#character {
z-index: 6;
position: absolute;
right: 0;
top: 35px;
}
#bar {
z-index: 5;
position: absolute;
right: 0;
top: 32px;
width: 20px; height: 463px;
}
.object {
z-index: 7;
position: absolute;
width: 70px; height: 70px;
left: 0px; top: 40px;
border-radius: 50%;
display: none;
}
#game_window header {
background: rgb(255, 255, 255);
position: absolute;
left: 0; top: 0;
margin-left: 0;
margin-top: 0;
width: 600px;
}
#score {
text-align: center;
width: 600px;
margin: 0;
}
body {
background-color: rgb(255, 255, 184);
}
</style>
</head>
<body>
<div id="front">
<div class="icon">
<button id="help"><img src="memo.png"><br>도움말</button>
<button id="game"><img src="cat_icon.png"><br>CAT</button>
</div>
<div class="active_window">
<div id="help_window">
<div>
<button id="help_close"><img src="close.png"></button>
</div>
<div>
<br>
**게임 플레이 방법**
<br>
↑(위 방향키) : 위로 이동
<br>
↓(아래 방향키) : 아래로 이동
<br><br>
고양이가 털실에 맞으면 게임 오버!
<br>
오래 피할수록 점수는 올라간다.
<br>
최대한 장애물을 피하면서 살아남자!
<br><br>
*팁 : 피하기 어려울 때는 털실에 머리를
<br>
가까이 하면 어느정도 피할 수 있다!
</div>
</div>
<div id="game_window">
<div>
<button id="game_close"><img src="close.png"></button>
</div>
<div>
<header>
<h2 id="score">점수 : 0</h2>
</header>
<section>
<img id="character" src="cat_character.png">
<img id="bar" src="bar_back.png">
<img class="object" id="obj1" src="sillgong.png">
<img class="object" id="obj2" src="sillgong2.png">
<img class="object" id="obj3" src="sillgong3.png">
</section>
</div>
</div>
<div id="gameOver_window">
<div>
<button id="gameOver_close"><img src="close.png"></button>
</div>
<div>
<h1>Game Over</h1>
<p id="result_score">score : </p>
</div>
</div>
</div>
<div id="monitor_footer">
<ul id="menu">
<li><button><img src="window.png"></button></li>
<li><button><img src="pile.png"></button></li>
<li><button><img src="chrome.png"></button></li>
</ul>
<div id="clock"></div>
</div>
</div>
<div id="back"></div>
<div id="foot"></div>
<div id="foot_2"></div>
</body>
</html>