웹마스터 팁

자바로 만든 퍼즐 겜^^;

2002.05.11 11:04

☆봄비ㆀ

여기 html 안먹네요? 분명히 'html사용'으로 했는데 안되여...ㅡ.ㅡ^

글을 첨 올리는 거라서..

밑의 소스를 한 번 실행시켜 보셈^^;

나름대로 신경써서 만든건데...

이제 시간 재는 걸 추가시켜야져...ㅡ.ㅡ;


<html>
<head>
<title>puzzle</title>
<script type = "text/javascript">
<!--
var puz = [[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,""]];
var x, y, i, j, s1, s2, s3, s4, tmp;
var c1,c2, c3, c4;


function go(){
        p1.innerText = "5";
}



function change(c1, c2, c3, c4){
        tmp = puz[c1][c2];
        puz[c1][c2] = puz[c3][c4];
        puz[c3][c4] = tmp;
        in_puz();
}        

function sort(){
        for(i=0;i<30;i++){
                s1 = Math.floor(Math.random()*4);
                s2 = Math.floor(Math.random()*4);
                s3 = Math.floor(Math.random()*4);
                s4 = Math.floor(Math.random()*4);
                tmp = puz[s1][s2];
                puz[s1][s2] = puz[s3][s4];
                puz[s3][s4] = tmp;
        }
        in_puz();        
}

function puzzle(x, y){
        if(x>0&&puz[x-1][y]=="") change(x,y,x-1,y);
        if(x<3&&puz[x+1][y]=="") change(x,y,x+1,y);
        if(y>0&&puz[x][y-1]=="") change(x,y,x,y-1);
        if(y<3&&puz[x][y+1]=="") change(x,y,x,y+1);
}

function in_puz(){
        p1.innerText = puz[0][0];
        p2.innerText = puz[0][1];
        p3.innerText = puz[0][2];
        p4.innerText = puz[0][3];
        p5.innerText = puz[1][0];
        p6.innerText = puz[1][1];
        p7.innerText = puz[1][2];
        p8.innerText = puz[1][3];
        p9.innerText = puz[2][0];
        p10.innerText = puz[2][1];
        p11.innerText = puz[2][2];
        p12.innerText = puz[2][3];
        p13.innerText = puz[3][0];
        p14.innerText = puz[3][1];
        p15.innerText = puz[3][2];
        p16.innerText = puz[3][3];
        test();                
}
function test(){
        var k=1, test_num=1;
        for(i=0;i<=3;i++){
                for(j=0;j<=3;j++){
                        if(puz[i][j] == k++) test_num++;
                }
        }
        if(test_num==16)
                if(confirm("축하합니다! 퍼즐을 완성시켰습니다.n다시 하시겠습니까?")) sort();
        
}        
        
//-->
</script>
<style>
p{font-size:20pt;text-align:center;font-weight:bold;}
td{width:40px;height:40px;cursor:hand}
</style>
</head>
<body>

<table border = "5" cellspacing = "3" bordercolorlight="ddddff" bordercolordark="000088">
<tr>
<td onclick="puzzle(0, 0)"><p id="p1">1</p></td><td onclick="puzzle(0, 1)"><p id="p2">2</p></td>
<td onclick="puzzle(0, 2)"><p id="p3">3</p></td><td onclick="puzzle(0, 3)"><p id="p4">4</p></td>
</tr>
<tr>
<td onclick="puzzle(1, 0)"><p id="p5">5</p></td><td onclick="puzzle(1, 1)"><p id="p6">6</p></td>
<td onclick="puzzle(1, 2)"><p id="p7">7</p></td><td onclick="puzzle(1, 3)"><p id="p8">8</p></td>
</tr>
<tr>
<td onclick="puzzle(2, 0)"><p id="p9">9</p></td><td onclick="puzzle(2, 1)"><p id="p10">10</p></td>
<td onclick="puzzle(2, 2)"><p id="p11">11</p></td><td onclick="puzzle(2, 3)"><p id="p12">12</p></td>
</tr>
<tr>
<td onclick="puzzle(3, 0)"><p id="p13">13</p></td><td onclick="puzzle(3, 1)"><p id="p14">14</p></td>
<td onclick="puzzle(3, 2)"><p id="p15">15</p></td><td onclick="puzzle(3, 3)"><p id="p16"> </p></td>
</tr>
</table>
<br />
<input type="button" value="시작" onclick="sort()" />

</body>
</html>
제목 글쓴이 날짜
보안설정을 하다^^ 유의할점. [3] Dopesoul 2002.10.14
오 이런... 죄송하군요 ㅠ.ㅜ [2] 레드 2002.10.12
나만의 ftp서버 만들기 제2부 -serv-u 4.0- [12] 레드 2002.10.09
나만의 ftp서버 만들기 제1부 -serv-u 4.0- [1] 레드 2002.10.09
추천해드리는 보안공부 사이트 [3] Dopesoul 2002.10.05
리눅스 넋두리. [4] Dopesoul 2002.10.05
Redhat 8.0 release! [22] Dopesoul 2002.10.01
리눅스용 apm 자동설치 스크립트 [10] file 이경재 2002.09.27
웹호스팅할때 좋은 간단한 백업스크립트 [1] 김동현 2002.09.22
웹호스팅꽁수! 어느사용자가 얼만큼의 하드용량을 쓰고있는가? 알아봅시다. [1] Dopesoul 2002.09.22
War3 베틀넷 운영 [5] Dopesoul 2002.09.20
운영체제별 보안 참조사이트 [4] V(^o^)V 2002.09.16
apache + php + mysql + gd + freetype 설치 방법 [1] 꽃게BBS 2002.09.16
PC 한 대에 2 개 또는 그 이상의 랜카드 꽂고 서버 운영하기. [2] 김종환 2002.09.15
자동 apm 설치 쉘스크립트(리눅스) [5] file 김동현 2002.09.15
Win2k 터미널 서비스 연결시 MsTsc.Server 에러 때려잡기!! file KKwang 2002.09.10
레드헷 계열 사용하시는 분들 웹서버에 대해서...(APM연동) [11] lanyan 2002.09.10
[re] 레드헷 계열 사용하시는 분들 웹서버에 대해서...(APM연동) Dopesoul 2002.09.14
PHP에서의 SQL문 보안취약성 [5] 김영빈 2002.09.09
[Apache] 윈도우 NT 계열에 서비스 등록하기 [1] file 스카이 2002.09.08