-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmong_kor.html
More file actions
1074 lines (929 loc) · 27.5 KB
/
mong_kor.html
File metadata and controls
1074 lines (929 loc) · 27.5 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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="ko">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-4YZHC1G9FN"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-4YZHC1G9FN');
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover" />
<title>워퍼즈몽 - 큰 격자 단어 찾기 게임 | Soosooland</title>
<!-- SEO Meta Tags -->
<meta name="description" content="컴퓨터와 큰 격자에서 단어 대결! 많은 단어와 전략적 플레이. 고급 난이도 워퍼즐 게임.">
<meta name="keywords" content="워퍼즈몽, 워퍼즈, 어려운단어게임, 고급단어게임, 어휘력게임, 대형격자, 전략게임, 두뇌게임, 치매예방">
<meta name="author" content="Soosooland">
<!-- Open Graph -->
<meta property="og:title" content="워퍼즈몽 - 큰 격자 단어 찾기 게임">
<meta property="og:description" content="컴퓨터와 큰 격자에서 단어 대결! 고급 난이도 워퍼즐">
<meta property="og:type" content="website">
<meta property="og:url" content="https://soosooland.com/mong/mong_kor.html">
<meta property="og:image" content="https://soosooland.com/images/worpuzz.jpeg">
<meta property="og:site_name" content="Soosooland">
<link rel="canonical" href="https://soosooland.com/mong/mong_kor.html">
<link rel="alternate" hreflang="ko" href="https://soosooland.com/mong/mong_kor.html">
<link rel="alternate" hreflang="en" href="https://soosooland.com/mong/mong_eng.html">
<link rel="stylesheet" href="https://soosooland.com/css/protection.css">
<script src="https://soosooland.com/js/protection.js"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: Arial, sans-serif;
background: #145454;
color: #fff;
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
padding: 10px;
}
.screen-warning {
display: none;
text-align: center;
padding: 40px;
font-family: Arial, sans-serif;
max-width: 400px;
margin: 100px auto;
background-color: #f8f9fa;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.screen-warning h2 {
color: #dc3545;
margin-bottom: 20px;
}
.screen-warning p {
color: #666;
line-height: 1.6;
}
.back-button {
position: absolute;
top: 20px;
left: 20px;
padding: 8px 10px; /* 모바일 기본 */
font-size: 2em;
font-weight: bold;
background-color:#145454 ;
color: #CFF9FF;
border-radius: 12px;
border: none;
cursor: pointer;
transition: all 0.3s ease;
z-index: 100;
}
.back-button:hover {
background-color: #1baf8f;
color: #fff;
}
h1 {
position: center;
font-size: 2em;
margin: 80px 0 10px;
color: #EF0;
}
p {
margin: 0 0 10px;
font-size: 1.3em;
color: #EF0;
text-align: center;
line-height: 1.4;
}
/* 난이도 선택 화면 */
#difficultyScreen {
display: flex;
flex-direction: column;
align-items: center;
gap: 20px;
margin-top: 50px;
}
#difficultyScreen h2 {
font-size: 1.5em;
color: #FFE680;
margin-bottom: 10px;
}
.difficulty-buttons {
display: flex;
gap: 20px;
flex-wrap: wrap;
justify-content: center;
}
.difficulty-btn {
font-size: 1.3em;
width:200px;
background-color: #CFF9FF;
color: #0A6A79;
padding: 20px 40px;
border: none;
border-radius: 12px;
cursor: pointer;
font-weight: bold;
transition: all 0.3s;
}
.difficulty-btn:hover {
background-color: #1baf8f;
color: #fff;
transform: scale(1.05);
}
.difficulty-btn.active {
background-color: #4CAF50; /* 또는 원하는 색상 */
border: 2px solid #45a049;
}
.game-area {
display: flex;
justify-content: center;
gap: 20px;
margin-bottom: 20px;
}
.game-button {
font-size: 18px;
background-color: #FFD6BA;
padding: 10px 22px;
margin: 8px;
color: #7A2E2E;
border: none;
border-radius: 6px;
cursor: pointer;
}
.game-button:hover {
background-color: #FF9494;
color: white;
transform: scale(1.05);
}
/* 데스크톱: 가로 배치 */
.container {
display: flex;
align-items: flex-start;
gap: 20px;
margin-bottom: 10px;
width: 100%;
max-width: 544px;
justify-content: center;
}
.cell {
width: 100%;
height: 100%;
aspect-ratio: 1 / 1;
background-color: #CFF9FF;
color: #0A6A79;
display: flex;
justify-content: center;
align-items: center;
font-size: 1.6em;
cursor: pointer;
user-select: none;
border-radius: 4px;
}
.revealed {
background-color: #fff;
font-size: 1.6em; /* 이것도 함께 추가! */
}
.revealed.clover {
background-color: #fff;
font-size: 1.6em;
}
.revealed.clover span {
font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
.revealed.daisy {
background-color: #fff4e0;
font-size: 1.6em;
}
.revealed.daisy span {
font-family: "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
}
/* 데스크톱 점수판 */
#npcScore, #userScore {
background: #209087;
color: #fff;
width: 180px;
height: 544px;
padding: 15px;
box-sizing: border-box;
border-radius: 12px;
flex-shrink: 0;
}
#npcScore h2, #userScore h2 {
font-size: 1.2em;
margin-top: 0;
margin-bottom: 10px;
}
#npcScore p, #userScore p {
font-size: 1.2em;
margin: 5px 0;
text-align: left; /* 이 줄 추가 */
}
/* 모바일 점수판 - 기본적으로 숨김 */
.score-container {
display: none;
}
.word-owned-user {
background-color: #a0fab5;
}
.word-owned-npc {
background-color: #f7cdf7;
}
#currentTurn {
font-size: 20px;
margin: 10px;
color: #FFE680;
font-weight: bold;
}
#game {
display: grid;
grid-template-columns: repeat(12, 1fr);
grid-template-rows: repeat(12, 1fr);
grid-gap: 4px;
padding: 10px;
background-color: #0E756D;
border-radius: 12px;
width: 544px;
height: 544px;
box-sizing: border-box;
flex-shrink: 0;
}
.btn-container {
display: flex;
gap: 10px;
margin: 15px;
}
button {
font-size: 1.1em;
padding: 10px 20px;
cursor: pointer;
background-color: #CFF9FF;
color: #0A6A79;
border-radius: 12px;
border: none;
}
button:hover {
background-color: #1baf8f;
color: #fff;
}
/* 모바일 반응형 */
@media (max-width: 950px) {
h1 {
font-size: 2em;
margin: 15px 0 5px;
}
p {
font-size: 1.3em;
margin: 0 10px 15px;
}
#difficultyScreen h2 {
font-size: 1.5em;
}
.difficulty-btn {
font-size: 1.1em;
padding: 15px 30px;
}
.container {
flex-direction: column;
align-items: center;
width: 100%;
gap: 0;
}
#game {
width: 95%;
max-width: 632px;
height: auto;
aspect-ratio: 1 / 1;
grid-gap: 3px;
}
/* 데스크톱 점수판 숨김 */
#npcScore, #userScore {
display: none !important;
}
/* 모바일 점수판 표시 */
.score-container {
display: flex !important;
flex-direction: column;
gap: 10px;
width: 490px;
margin-top: 15px;
}
.score-container > div {
background-color: #0E756D;
color: #fff;
width: 100%;
padding: 12px;
box-sizing: border-box;
border-radius: 12px;
}
.score-container h2 {
font-size: 1em;
margin: 0 0 8px;
}
.score-container p {
font-size: 0.95em;
display: inline-block;
margin: 3px 6px;
color: #fff;
text-align: left; /* 이 줄 추가 */
}
.btn-container {
margin: 15px 0;
width: 95%;
max-width: 530px;
justify-content: center;
}
button {
font-size: 1em;
padding: 12px 25px;
flex: 1;
max-width: 150px;
}
}
</style>
</head>
<body>
<div class="screen-warning" id="warning">
<h2>Screen Too Small</h2>
<p>이 게임은 두 사용자가 큰 격자에서 대결하는 모드로 최소 660px 이상의 화면에서 플레이하도록 디자인되었습니다</p>
<p>660px 보다 작은 화면에서는 워퍼즈를 이용하세요</p>
<button onclick="location.href='https://soosooland.com/worpuzz/'" class="game-button"> 워퍼즈<br> 하러가기</button>
</div>
<button class="back-button" onclick="location.href='index.html'">←</button>
<div class="game-header">
<h1 id="game-title">게임 제목</h1>
<p id="game-desc">게임 설명</p>
<!-- 난이도 선택 화면 -->
<div id="difficultyScreen">
<div class="difficulty-buttons">
<button class="difficulty-btn active" onclick="setDifficulty('easy')">쉬움</button>
<button class="difficulty-btn" onclick="setDifficulty('normal')">보통</button>
</div>
</div>
<!-- 게임 화면 -->
<div id="gameScreen">
<div id="currentTurn"></div>
<!-- 데스크톱: 게임판 + 양쪽 점수판 -->
<div class="container">
<div id="npcScore">
<h2>컴퓨터:</h2>
</div>
<div id="game"></div>
<div id="userScore">
<h2>사용자:</h2>
</div>
</div>
<!-- 모바일: 게임판 아래 점수판 -->
<div class="score-container">
<div id="npcScore-mobile">
<h2>컴퓨터:</h2>
</div>
<div id="userScore-mobile">
<h2>사용자:</h2>
</div>
</div>
<div class="btn-container">
<button id="retryBtn">↻ 다시 시작</button>
</div>
</div>
<script>
function checkScreenSize() {
const warning = document.getElementById('warning');
const gameTitle = document.getElementById('game-title');
const gameDesc = document.getElementById('game-desc');
const backButton = document.querySelector('.back-button');
const difficultyScreen = document.getElementById('difficultyScreen');
const gameScreen = document.getElementById('gameScreen');
if (window.innerWidth < 660) {
warning.style.display = 'block';
if (gameTitle) gameTitle.style.display = 'none';
if (gameDesc) gameDesc.style.display = 'none';
if (backButton) backButton.style.display = 'none';
if (difficultyScreen) difficultyScreen.style.display = 'none';
if (gameScreen) gameScreen.style.display = 'none';
} else {
warning.style.display = 'none';
if (gameTitle) gameTitle.style.display = 'block';
if (gameDesc) gameDesc.style.display = 'block';
if (backButton) backButton.style.display = 'block';
if (difficultyScreen) difficultyScreen.style.display = 'flex';
// gameScreen은 hidden 클래스로 제어됨
}
}
// DOMContentLoaded로 먼저 체크
document.addEventListener('DOMContentLoaded', function() {
checkScreenSize();
});
window.addEventListener('resize', checkScreenSize);
// Prevent zoom/scroll
document.addEventListener('touchmove', function(e) {
if (e.scale !== 1) {
e.preventDefault();
}
}, { passive: false });
document.addEventListener('gesturestart', function(e) {
e.preventDefault();
});
document.addEventListener('gesturechange', function(e) {
e.preventDefault();
});
document.addEventListener('gestureend', function(e) {
e.preventDefault();
});
let lastTouchEnd = 0;
document.addEventListener('touchend', function(event) {
const now = (new Date()).getTime();
if (now - lastTouchEnd <= 300) {
event.preventDefault();
}
lastTouchEnd = now;
}, false);
// 전역 변수 선언
const gridSize = 12;
const totalCells = gridSize * gridSize;
let npcDifficulty = 'easy'; // 맨 위 변수 선언부에 추가
function setDifficulty(level) {
npcDifficulty = level;
// 모든 버튼에서 active 제거
document.querySelectorAll('.difficulty-btn').forEach(btn => {
btn.classList.remove('active');
});
// 클릭한 버튼에만 active 추가
event.target.classList.add('active');
}
const difficultyScreen = document.getElementById('difficultyScreen');
const gameScreen = document.getElementById('gameScreen');
let board, revealed, wordMap, foundWords, currentPlayer, foundBy, words, usedIndexes;
let clovers = new Set(), daisies = new Set();
let resultShown = false;
let npcTimeoutId = null;
const gameEl = document.getElementById('game');
const userScoreEl = document.getElementById('userScore');
const npcScoreEl = document.getElementById('npcScore');
const userScoreMobileEl = document.getElementById('userScore-mobile');
const npcScoreMobileEl = document.getElementById('npcScore-mobile');
const retryBtn = document.getElementById('retryBtn');
const currentTurnEl = document.getElementById('currentTurn');
function startGame(difficulty) {
npcDifficulty = difficulty;
init();
}
function getAdjacentCells(index) {
const x = index % gridSize;
const y = Math.floor(index / gridSize);
const adjacent = [];
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx >= 0 && nx < gridSize && ny >= 0 && ny < gridSize) {
const nIdx = ny * gridSize + nx;
if (!revealed[nIdx]) {
adjacent.push(nIdx);
}
}
}
}
return adjacent;
}
function isNextToSpecial(index) {
const x = index % gridSize;
const y = Math.floor(index / gridSize);
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx >= 0 && nx < gridSize && ny >= 0 && ny < gridSize) {
const nIdx = ny * gridSize + nx;
// 이미 열린 아이템만 피하기
if ((clovers.has(nIdx) || daisies.has(nIdx)) && revealed[nIdx]) {
return true;
}
}
}
}
return false;
}
window.onload = () => {
const urlParams = new URLSearchParams(window.location.search);
const poolFile = urlParams.get('pool');
if (!poolFile) {
// 임시로 기본 단어들 설정
words = ["계륵","기우","각골난망", "각양각색", "각인각색", "각자도생", "각주구검", "간난신고", "간담상조", "감개무량", "감언이설", "감지덕지", "갑론을박","개과천선","거두절미","격세지감","견물생심","가화만사성"];
init();
return;
}
fetch('wordpools/' + poolFile + '.json')
.then(res => res.json())
.then(data => {
document.getElementById('game-title').textContent = data.title || '게임 제목';
const rawText = data.description || '게임 설명';
const htmlText = rawText.replace(/\n/g, '<br>');
document.getElementById('game-desc').innerHTML = htmlText;
words = [];
for (let length in data.words) {
const count = data.wordCount[length] || 0;
words.push(...getRandomSample(data.words[length], count));
}
console.log('총 단어 수:', words.length);
console.log('단어 목록:', words);
init();
})
.catch(err => {
document.body.innerHTML = '<p>❌ 워드풀 로딩 중 오류 발생: ' + err.message + '</p>';
});
};
function shuffle(arr) {
for (let i = arr.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[arr[i], arr[j]] = [arr[j], arr[i]];
}
}
function getRandomSample(arr, count) {
if (count >= arr.length) return [...arr];
const shuffled = [...arr];
shuffle(shuffled);
return shuffled.slice(0, count);
}
function init() {
board = Array(totalCells).fill(null);
revealed = Array(totalCells).fill(false);
wordMap = {};
foundWords = new Set();
foundBy = { user: [], npc: [] };
currentPlayer = 'user';
usedIndexes = new Set();
clovers.clear();
daisies.clear();
resultShown = false;
if (npcTimeoutId) {
clearTimeout(npcTimeoutId);
npcTimeoutId = null;
}
createGrid();
if (placeAllWordsWithVariety()) {
console.log('모든 단어가 성공적으로 배치되었습니다.');
} else {
console.log('방향 검증 실패 - 기본 배치로 진행');
let placedWords = [];
const sortedWords = [...words].sort((a, b) => b.length - a.length);
for (let word of sortedWords) {
let placed = false;
for (let attempt = 0; attempt < 500; attempt++) {
if (placeWord(word)) {
placedWords.push(word);
placed = true;
break;
}
}
if (!placed) {
console.log('배치 실패한 단어:', word);
}
}
console.log('실제 배치된 단어 수:', placedWords.length);
}
placeDaisies(14);
placeClovers(14);
fillEmptyCells();
updateScore();
updateTurnDisplay();
checkGameEnd();
}
function createGrid() {
gameEl.innerHTML = '';
for (let i = 0; i < totalCells; i++) {
const cell = document.createElement('div');
cell.className = 'cell';
cell.onclick = () => {
if (!resultShown && currentPlayer === 'user') {
handleClick(i);
}
};
gameEl.appendChild(cell);
}
}
function canPlaceWord(word, x, y, dx, dy) {
for (let i = 0; i < word.length; i++) {
let nx = x + dx * i, ny = y + dy * i;
if (nx < 0 || ny < 0 || nx >= gridSize || ny >= gridSize) return false;
let idx = ny * gridSize + nx;
if (board[idx] && board[idx] !== word[i]) return false;
if (usedIndexes.has(idx)) return false;
}
return true;
}
function placeWord(word) {
const directions = [
{ x: 1, y: 0 },
{ x: 0, y: 1 },
{ x: 1, y: 1 },
];
const shuffledDirections = directions.sort(() => Math.random() - 0.5);
for (let dir of shuffledDirections) {
const startY = Math.floor(Math.random() * gridSize);
for (let i = 0; i < gridSize; i++) {
const y = (startY + i) % gridSize;
for (let x = 0; x < gridSize; x++) {
if (canPlaceWord(word, x, y, dir.x, dir.y)) {
let positions = [];
for (let i = 0; i < word.length; i++) {
let nx = x + dir.x * i, ny = y + dir.y * i, idx = ny * gridSize + nx;
board[idx] = word[i];
usedIndexes.add(idx);
positions.push(idx);
}
wordMap[word] = {
positions: positions,
direction: [dir.x, dir.y]
};
return true;
}
}
}
}
return false;
}
function checkDirectionVariety() {
let directionCount = {
'1,0': 0,
'0,1': 0,
'1,1': 0
};
for (let word in wordMap) {
const direction = wordMap[word].direction;
const key = direction[0] + ',' + direction[1];
if (directionCount.hasOwnProperty(key)) {
directionCount[key]++;
}
}
console.log('방향별 사용 횟수:', directionCount);
return directionCount['1,0'] > 0 && directionCount['0,1'] > 0 && directionCount['1,1'] > 0;
}
function placeAllWordsWithVariety() {
let attempts = 0;
const maxAttempts = 10;
do {
board = Array(totalCells).fill(null);
usedIndexes.clear();
wordMap = {};
let allPlaced = true;
const sortedWords = [...words].sort((a, b) => b.length - a.length);
for (let word of sortedWords) {
if (!placeWord(word)) {
allPlaced = false;
break;
}
}
if (allPlaced && checkDirectionVariety()) {
console.log(`성공! ${attempts + 1}번째 시도에서 3방향 모두 사용됨`);
return true;
}
attempts++;
console.log(`${attempts}번째 시도 실패 - 다시 시도`);
} while (attempts < maxAttempts);
console.log('최대 시도 횟수 초과 - 기본 배치로 진행');
return false;
}
function placeClovers(count) {
let placed = 0;
let attempts = 0;
while (placed < count && attempts < 1000) {
const idx = Math.floor(Math.random() * totalCells);
if (!usedIndexes.has(idx) && !clovers.has(idx) && !daisies.has(idx)) {
if (isSafeForSpecial(idx)) {
clovers.add(idx);
placed++;
}
}
attempts++;
}
console.log('배치된 클로버 수:', clovers.size);
}
function placeDaisies(count) {
let placed = 0;
let attempts = 0;
while (placed < count && attempts < 1000) {
const idx = Math.floor(Math.random() * totalCells);
if (!usedIndexes.has(idx) && !clovers.has(idx) && !daisies.has(idx)) {
if (isSafeForSpecial(idx)) {
daisies.add(idx);
placed++;
}
}
attempts++;
}
console.log('배치된 데이지 수:', daisies.size);
}
function isSafeForSpecial(idx) {
const x = idx % gridSize;
const y = Math.floor(idx / gridSize);
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx >= 0 && nx < gridSize && ny >= 0 && ny < gridSize) {
const nIdx = ny * gridSize + nx;
if (clovers.has(nIdx) || daisies.has(nIdx)) {
return false;
}
}
}
}
return true;
}
function fillEmptyCells() {
const filler = '같갛개거건걸것게고괴교국궁그근금기긴까깜깨꺾껴꼼꽁꾸끔난내넘넣네놀놈누뉴는니님다닥대댄더던덩데도동두드득든듣들등디딜딱때땡똑뚫뛰라락란람랐랑래랜러레려력렸로롭르른를리린림마만맛맞맨머먼멀메멘며몰무묻뭘미민바받방버벅번봐봤부붙브블비빈빌빔빠빡빨빼뻥사새생서섭섰세숙쉬슴실싶쌍쓰씌씻아악알았애야어엄업없었엉에여열옛오온올와왔왜우울원위유윤으을음의익인잃있잊작잖잘저전제져좋주줬짜짝찍차착참창채척천청체쳤초출췄취치친카켜코콜크테토트튼폭핀하학한할해햄했행현호혼화환히희'.split('');
shuffle(filler);
let i = 0;
for (let j = 0; j < totalCells; j++) {
if (!board[j] && !clovers.has(j) && !daisies.has(j)) {
board[j] = filler[i++ % filler.length];
}
}
}
function reveal(index) {
if (revealed[index]) return;
revealed[index] = true;
const cell = gameEl.children[index];
if (clovers.has(index)) {
cell.innerHTML = '<span>🍀</span>';
cell.classList.add('clover');
const directions = [-gridSize, gridSize, -1, 1];
for (let d of directions) {
const newIdx = index + d;
if (newIdx >= 0 && newIdx < totalCells) {
if (d === -1 || d === 1) {
if (Math.floor(index / gridSize) === Math.floor(newIdx / gridSize)) {
reveal(newIdx);
}
} else {
reveal(newIdx);
}
}
}
} else if (daisies.has(index)) {
const img = document.createElement('img');
img.src = 'daisy_64x64.png';
img.alt = '데이지';
img.style.width = '24px';
img.style.height = '24px';
cell.appendChild(img);
const x = index % gridSize;
const y = Math.floor(index / gridSize);
for (let dy = -1; dy <= 1; dy++) {
for (let dx = -1; dx <= 1; dx++) {
if (dx === 0 && dy === 0) continue;
const nx = x + dx;
const ny = y + dy;
if (nx >= 0 && nx < gridSize && ny >= 0 && ny < gridSize) {
const nIdx = ny * gridSize + nx;
if (!revealed[nIdx]) reveal(nIdx);
}
}
}
} else {
cell.textContent = board[index];
}
cell.classList.add('revealed');
}
function updateScore() {
const userHTML = `<h2>사용자:</h2>` + foundBy.user.map(w => `<p>${w}</p>`).join("");
const npcHTML = `<h2>컴퓨터:</h2>` + foundBy.npc.map(w => `<p>${w}</p>`).join("");
userScoreEl.innerHTML = userHTML;
npcScoreEl.innerHTML = npcHTML;
userScoreMobileEl.innerHTML = userHTML;
npcScoreMobileEl.innerHTML = npcHTML;
}
function updateTurnDisplay() {
if (resultShown) return;
const name = currentPlayer === 'user' ? 'USER' : 'NPC';
const difficultyText = npcDifficulty === 'easy' ? '(쉬움)' : '(보통)';
currentTurnEl.textContent = `${name}의 차례입니다. ${currentPlayer === 'npc' ? difficultyText : ''}`;
}
function switchTurn(extra) {
if (!extra) {
currentPlayer = currentPlayer === 'user' ? 'npc' : 'user';
}
updateTurnDisplay();
if (currentPlayer === 'npc' && !resultShown) {
npcTimeoutId = setTimeout(() => {
npcMove();
}, 1000);
}
}
function npcMove() {
if (resultShown) return;
let selectedCell;
if (npcDifficulty === 'easy') {
// 쉬움: 완전 랜덤
const availableCells = [];
for (let i = 0; i < totalCells; i++) {
if (!revealed[i]) {
availableCells.push(i);
}
}
if (availableCells.length === 0) return;
const randomIndex = Math.floor(Math.random() * availableCells.length);
selectedCell = availableCells[randomIndex];
} else {
// 보통: 똑똑한 전략
let nearRevealedCells = [];
for (let i = 0; i < totalCells; i++) {
if (revealed[i]) {
const adjacent = getAdjacentCells(i);
nearRevealedCells.push(...adjacent);
}
}
nearRevealedCells = [...new Set(nearRevealedCells)];
let smartCells = nearRevealedCells.filter(idx => !isNextToSpecial(idx));
if (smartCells.length > 0) {
const randomIndex = Math.floor(Math.random() * smartCells.length);
selectedCell = smartCells[randomIndex];
} else if (nearRevealedCells.length > 0) {
const randomIndex = Math.floor(Math.random() * nearRevealedCells.length);
selectedCell = nearRevealedCells[randomIndex];
} else {
const availableCells = [];
for (let i = 0; i < totalCells; i++) {
if (!revealed[i]) {
availableCells.push(i);
}
}
if (availableCells.length === 0) return;
const randomIndex = Math.floor(Math.random() * availableCells.length);
selectedCell = availableCells[randomIndex];
}
}
handleClick(selectedCell, true);
}
function handleClick(index, isnpcMove = false) {
if (revealed[index] || resultShown) return;
// NPC 차례일 때 유저 클릭 차단
if (currentPlayer === 'npc' && !isnpcMove) {
console.log('NPC 차례입니다. 유저 클릭 무시됨');
return;
}