본문 바로가기
TechNical/WMI

[HTA] 탱크 게임

by 강멍멍이 강멍멍이 2020. 2. 23.
반응형

옛날에 아주 머나먼 옛적에 했었던 추억의 탱크 게임이다.

HTA 로 별에 별 짓 다해 보기 시리즈 중에 인공지능(???!!!)이 탑재된 ...... 왠지 미안하다.

조작방법은 숫자키거나 AWSD and Space 키다.

해상도(?)를 상당히 조악하게 만든 이유는 단순히 성능 때문이다...

원래는 탱크 모양이 더 이뻤는데, 테이블 형식으로 구현되어 있다보니

테이블 칸이 많아지면 성능이 기하급수적으로 느려지게 된다.

일단 바둑판 모양으로 판을 짠 다음에 랜덤으로 지우는 방식으로 맵을 만들어 낸다.

중간 중간에 랜덤으로 철벽도 심어 놓았다.

랜덤으로 맵을 만들다 보니까 난이도(라고 할꺼 까지도 없지만...)가 그때그때 다르다. 

 

팩맨이랑은 다르게 벽이 부셔지다 보니까 얘네들 움직임을 잡는데 꽤나 애먹었다.

(팩맨 소스 기반으로 만든거라서 주석에 팩맨의 향기가 많이 남아 있다... 귀찮아서  정리 안 함)

사방이 뚫여 있으니까 움직이던 방향에서 언제 턴을 하느냐를 잘 잡아 줘야 한다.

별에 별짓을 다해서 그나마 이 정도라도 움직인다...

 

적군들을 랜덤으로만 움직이게 만들었더니 난이도가 최최하하가 되어 버려서

내 탱크가 있는 방향으로 움직이도록 살짝 트릭도 넣어 놓았다.

알파고 같은 건 학습을 통해서 스타크레프트까지 한다는데 이건 고작 탱크 따라가기도 바쁘다.

내 탱크 위치를 글로벌로 들고 있고, 적군이 움직일때 내 탱크 위치를 기반으로 랜덤으로 상/하, 좌/우 로 가게 만들었다.

쟤네를 세트로 묶은 이유는... 저렇게 안 하면 아주 지랄발광이 나서 탱크까지 못 간다.

 

[Tank.hta]

<html>
    <meta charset="euc-kr">
    <head>
        <title>Tank</title>
        <HTA:APPLICATION 
         ID="강멍멍이"
         APPLICATIONNAME="Tank"
         SCROLL="no"
         SINGLEINSTANCE="yes"
         WINDOWSTATE="normal"
        />
        
        <style>
            BODY {
                font-size:8pt;
                font-family:돋움체;
            }
            
            TABLE, TR, TD {
                font-size:1pt;
                text-indent:-10000px;
                border:0px solid black;
                border-collapse:collapse;
            }            
            
            .hide {
                opacity : 0;
                transition: opacity 1s linear;
                -webkit-transition: opacity 1s linear;
            }
        </style>
     
        <script language="VBScript">
            'text-indent:-10000px;
            Dim interval, levelCnt, levelCntMax , intervalMinus, viewLevel
            
            Dim intRow, intCol
            Dim rowBound, colBound
            Dim aniXDir, aniYDir
            
            Dim packManArr(4,2)
            Dim packManDir
            Dim poewrPackManYn, packManColor, powerCode, powerTime, powerTimeLimit
            
            Dim fireCannonYn ' , cannonRow, cannonCol, cannonDir
            
            Dim enemiesArr(7,5) '적군 갯수
            Dim enemyArr(4,2)
            
            Dim tankCannonArr(10,4) '캐논 위치
            Dim cannonCnt, tankCannoCnt, enemyCannoCnt
            
            Dim endGameYn
            Dim eatFoodCnt
            
            Dim timerID, cannonTimerID, animateTimerID
            
            Dim colorArr
            Dim faceType
            
            Dim packManCode, enemyCode, initWallCode, wallCode, borderWallCode, appleCode
            Dim eagleCode, enemyEagleCode
            Dim myEnergy, enemyEnergy
            Dim enemyResponeCnt
            
            Sub Window_OnLoad
                window.resizeTo 370, 400
                window.moveTo 1200, 350
                
                colorArr = Array("aqua", "lime", "darkkhaki", "darkred", "plum", "salmon", "orange", "pink", "purple")

                rowBound = CInt(labRow.innerHTML)
                colBound = CInt(labCol.innerHTML)
                
                packManCode = "1"
                appleCode = "2"
                enemyCode = "3"
                powerCode = "4"
                eagleCode = "5"
                enemyEagleCode = "6"
                wallCode = "8"
                borderWallCode = "9"                

                '판때기 생성
                For nRow = 1 To rowBound
                    Set tblRow = mainTbl.insertRow()
                
                    For nCell = 1 To colBound
                        Set tblCell = tblRow.insertCell()
                        tblCell.style.width = 2
                        tblCell.style.height = 2
                        tblCell.style.backgroundcolor = "ffffff"
                        tblCell.innerHtml= "0"
                    Next
                Next

                '테두리
                For nRow = 0 To rowBound - 1
                    mainTbl.Rows(nRow).Cells(0).innerHtml = wallCode
                    mainTbl.Rows(nRow).Cells(0).style.backgroundcolor = "gray"
                
                    mainTbl.Rows(nRow).Cells(colBound - 1).innerHtml = wallCode
                    mainTbl.Rows(nRow).Cells(colBound - 1).style.backgroundcolor = "gray"
                Next
                
                For nCol = 0 To colBound - 1
                    mainTbl.Rows(0).Cells(nCol).innerHtml = wallCode
                    mainTbl.Rows(0).Cells(nCol).style.backgroundcolor = "gray"
                
                    mainTbl.Rows(rowBound - 1).Cells(nCol).innerHtml = wallCode
                    mainTbl.Rows(rowBound - 1).Cells(nCol).style.backgroundcolor = "gray"                    
                Next
                                
                aniXDir = 0
                aniYDir = 0
                intRow = CInt(rowBound / 2)
                intCol = CInt(colBound / 2)
                'animateTimerID = window.setTimeOut("animate", 500)
                                
            End Sub

            'sleep 패키지 시작 --------------------------------------------------------------
            Sub doSleep
                Set objSleep = CreateObject("WScript.Shell")
                objSleep.Run "%COMSPEC% /c ECHO " & Chr(7), 0, false
                window.setTimeOut "doNothing", 1  '0.001초 대기 후 doNothing 을 실행한다.            
            End Sub
            
            '처리 현황. 암것도 안 함. 단지 슬립할려고 부른다.
            Sub doNothing
            End Sub
            'sleep 패키지 끝 ----------------------------------------------------------------            

            '게임 시작. 초기화 ----------------------------------------------------------------------------------
            Sub startGame
                document.body.focus()   '시작버튼에 있는 포커스 제거
                loadingDiv.innerHTML = "<center><font size=3pt color=white><b>Loading ...</b></font></center>"
                loadingDiv.style.visibility = "visible"
                doSleep
                window.clearTimeOut(animateTimerID)
                                
                levelCntMax = 100
                intervalMinus = 10
                                
                interval = 180  '성능이 안 받쳐줘서 이거 이하로 내려도 의미 없다.
                levelCnt = 1
                viewLevel = 1
                scoreCnt = 0
                endGameYn = "N"

                eatFoodCnt = 0        
                poewrPackManYn = "N"
                packManColor = "teal"
                powerTime = 0
                powerTimeLimit = 100
                'fireCannonYn = "N"
                cannonCnt = 0
                tankCannoCnt = 0
                enemyCannoCnt = 0
                myEnergy = 3
                enemyEnergy = 7
                enemyResponeCnt = 0
                
                labLevelCnt.innerHTML = viewLevel

                '초기화
                For nRow = 1 To rowBound - 2
                    For nCol = 1 To colBound - 2
                        mainTbl.Rows(nRow).Cells(nCol).innerHtml = 0
                        mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "white"
                    Next
                Next
                
                On Error Resume Next
                'COL 줄 긋기
                For nRow = 0 To rowBound - 1
                    For nCol = 0 To colBound - 1 Step + 7
                        '악당들은 여백이 있어야 최초에 자유로이 움직일 수 있다.
                        IF nRow < rowBound - 7 THEN
                            mainTbl.Rows(nRow).Cells(nCol - 1).innerHtml = wallCode
                            mainTbl.Rows(nRow).Cells(nCol - 1).style.backgroundcolor = "gray"
                        END IF
                    
                        mainTbl.Rows(nRow).Cells(nCol).innerHtml = wallCode
                        mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "gray"
                        
                        Randomize
                        thinYn = Int(3 * Rnd)
                        
                        IF thinYn = 2 THEN
                            mainTbl.Rows(nRow).Cells(nCol + 1).innerHtml = wallCode
                            mainTbl.Rows(nRow).Cells(nCol + 1).style.backgroundcolor = "gray"
                        
                        
                            '양쪽 젤 끝에 통로는 안 막는다.(안 된다..?)
                            'If (nCol > 1 And nCol < colBound - 1) Then
                            '    If (nRow > 0 And nRow < 7) OR (nRow > rowBound - 8 And nRow < rowBound - 1) Then
                            '        mainTbl.Rows(nRow).Cells(nCol).innerHtml = 0
                            '        mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "white"
                            '    End If
                            'End If
                        END IF
                    Next
                Next

                'ROW 줄 긋기
                For nCol = 0 To colBound - 1
                    For nRow = 0 To rowBound - 1 Step + 7                       

                        '악당들은 여백이 있어야 최초에 자유로이 움직일 수 있다.
                        IF nRow < rowBound - 7 THEN
                            mainTbl.Rows(nRow - 1).Cells(nCol).innerHtml = wallCode
                            mainTbl.Rows(nRow - 1).Cells(nCol).style.backgroundcolor = "gray"
                        END IF
                                             
                        mainTbl.Rows(nRow).Cells(nCol).innerHtml = wallCode
                        mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "gray"
                        
                        Randomize
                        thinYn = Int(3 * Rnd)
                        
                        IF thinYn = 2 THEN
                            mainTbl.Rows(nRow + 1).Cells(nCol).innerHtml = wallCode
                            mainTbl.Rows(nRow + 1).Cells(nCol).style.backgroundcolor = "gray"
                        
                            '양쪽 젤 끝에 통로는 안 막는다.
                            'If (nRow > 1 And nRow < rowBound - 1) Then
                            '    If (nCol > 0 And nCol < 7) OR (nCol > colBound - 8 And nCol < colBound - 1) Then
                            '        mainTbl.Rows(nRow).Cells(nCol).innerHtml = 0
                            '        mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "white"
                            '    End If
                            'End If
                        END IF              
                    Next
                Next

                '보더 코드값 변경
                For nRow = 0 To rowBound - 1
                    mainTbl.Rows(nRow).Cells(0).innerHtml = borderWallCode
                    mainTbl.Rows(nRow).Cells(0).style.backgroundcolor = "black"
                
                    mainTbl.Rows(nRow).Cells(colBound - 1).innerHtml = borderWallCode
                    mainTbl.Rows(nRow).Cells(colBound - 1).style.backgroundcolor = "black"                             
                Next
                
                For nCol = 0 To colBound - 1
                    mainTbl.Rows(0).Cells(nCol).innerHtml = borderWallCode
                    mainTbl.Rows(0).Cells(nCol).style.backgroundcolor = "black"
                
                    mainTbl.Rows(rowBound - 1).Cells(nCol).innerHtml = borderWallCode
                    mainTbl.Rows(rowBound - 1).Cells(nCol).style.backgroundcolor = "black"
                Next
                
                '팩맨 초기화
                intRow = 9
                intCol = CInt(colBound / 2) - 2

                packManArr(0, 0) = intRow
                packManArr(0, 1) = intCol
                packManArr(1, 0) = intRow
                packManArr(1, 1) = intCol + 3
                packManArr(2, 0) = intRow + 3 
                packManArr(2, 1) = intCol
                packManArr(3, 0) = intRow + 3
                packManArr(3, 1) = intCol + 3                

                packManDir = 2
                okFalg = drawPackMan(packManArr, intRow, intCol, "teal", "Y", packManDir)
                Call makeStage
                
                loadingDiv.style.visibility = "hidden"
                doSleep
                
                'Call moveRight
                timerID = window.setTimeOut("movePackMan", interval)                
                'cannonTimerID = window.setTimeOut("fireCannonMove 0, 0, 0", 50)                
                cannonTimerID = window.setTimeOut("fireCannonMove", 50)
                
                Call makeEnemies

            End Sub
                        
            '스테이지 렌덤 생성 ----------------------------------------------------------------------------------
            Sub makeStage            
            
                'ROW 내벽 빵꾸 내기
                For nRow = 7 To rowBound - 7 Step + 7
                    wallPos = 0
                    Do While wallPos < colBound - 7
                        Randomize
                        deleteYn = Int(3 * Rnd)
                        
                        If deleteYn = 0 Then
                            For nCol = wallPos + 1 To wallPos + 6
                                If nCol > colBound - 1 Then
                                    Exit For
                                End If
                                mainTbl.Rows(nRow - 1).Cells(nCol).innerHtml = 0
                                mainTbl.Rows(nRow - 1).Cells(nCol).style.backgroundcolor = "white"

                                mainTbl.Rows(nRow).Cells(nCol).innerHtml = 0
                                mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "white"
                                
                                mainTbl.Rows(nRow + 1).Cells(nCol).innerHtml = 0
                                mainTbl.Rows(nRow + 1).Cells(nCol).style.backgroundcolor = "white"                                
                            Next
                        End If                        
                        
                        wallPos = wallPos + 7
                                                
                    Loop
                Next

                'COL 내벽 빵꾸 내기
                For nCol = 7 To colBound - 7 Step + 7
                    wallPos = 0
                    Do While wallPos < rowBound - 7
                        Randomize
                        deleteYn = Int(3 * Rnd)
                        
                        If deleteYn = 0 Then
                            For nRow = wallPos + 1 To wallPos + 6
                                If nRow > rowBound - 1 Then
                                    Exit For
                                End If
                                mainTbl.Rows(nRow).Cells(nCol - 1).innerHtml = 0
                                mainTbl.Rows(nRow).Cells(nCol - 1).style.backgroundcolor = "white"

                                mainTbl.Rows(nRow).Cells(nCol).innerHtml = 0
                                mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "white"

                                mainTbl.Rows(nRow).Cells(nCol + 1).innerHtml = 0
                                mainTbl.Rows(nRow).Cells(nCol + 1).style.backgroundcolor = "white"                                                                
                            Next                        
                        End If      
                        wallPos = wallPos + 7
                    Loop
                Next

                'ROW 철벽 만들기
                For nRow = 7 To rowBound - 7 Step + 7
                    wallPos = 0
                    Do While wallPos < colBound - 7
                        Randomize
                        ironYn = Int(7 * Rnd)
                        
                        '가운데 철벽은 항상 생성한다.
                        IF nRow = 21 AND wallPos = 21 THEN
                           ironYn = 0 
                        END IF
                        
                        If ironYn = 0 Then
                            For nCol = wallPos + 1 To wallPos + 6
                                If nCol > colBound - 1 Then
                                    Exit For
                                End If

                                mainTbl.Rows(nRow).Cells(nCol).innerHtml = borderWallCode
                                mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "black"
                            Next
                        End If
                        
                        wallPos = wallPos + 7
                                                
                    Loop
                Next

                'COL 철벽 만들기
                For nCol = 7 To colBound - 7 Step + 7
                    wallPos = 0
                    Do While wallPos < rowBound - 7
                        Randomize
                        ironYn = Int(7 * Rnd)
                        
                        If ironYn = 0 Then
                            For nRow = wallPos + 1 To wallPos + 6
                                If nRow > rowBound - 1 Then
                                    Exit For
                                End If

                                mainTbl.Rows(nRow).Cells(nCol).innerHtml = borderWallCode
                                mainTbl.Rows(nRow).Cells(nCol).style.backgroundcolor = "black"

                            Next                        
                        End If      
                        wallPos = wallPos + 7
                    Loop
                Next
                                                
                '아군 독수리 만들기
                eagleColSPos = CInt(colBound / 2) - 2
                eagleRowSPos = 2

                For nCol = 1 To 2
                    mainTbl.Rows(eagleRowSPos).Cells(eagleColSPos + nCol).innerHtml = eagleCode
                    mainTbl.Rows(eagleRowSPos).Cells(eagleColSPos + nCol).style.backgroundcolor = "774420"
                Next                
                
                For nRow = 0 To 1
                    For nCol = 0 To 3
                        mainTbl.Rows(eagleRowSPos + 1 + nRow).Cells(eagleColSPos + nCol).innerHtml = eagleCode
                        mainTbl.Rows(eagleRowSPos + 1 + nRow).Cells(eagleColSPos + nCol).style.backgroundcolor = "77aa30"
                    Next
                Next

                mainTbl.Rows(eagleRowSPos + 3).Cells(eagleColSPos + 2).innerHtml = eagleCode
                mainTbl.Rows(eagleRowSPos + 3).Cells(eagleColSPos + 2).style.backgroundcolor = "77a180"
                
                
                '적군 독수리 만들기
                eagleColSPos = CInt(colBound / 2) - 2
                eagleRowSPos = rowBound - 5

                For nCol = 1 To 2
                    mainTbl.Rows(eagleRowSPos).Cells(eagleColSPos + nCol).innerHtml = enemyEagleCode
                    mainTbl.Rows(eagleRowSPos).Cells(eagleColSPos + nCol).style.backgroundcolor = "dd8820"
                Next                
                
                For nRow = 0 To 1
                    For nCol = 0 To 3
                        mainTbl.Rows(eagleRowSPos + 1 + nRow).Cells(eagleColSPos + nCol).innerHtml = enemyEagleCode
                        mainTbl.Rows(eagleRowSPos + 1 + nRow).Cells(eagleColSPos + nCol).style.backgroundcolor = "ddaa30"
                    Next
                Next

                mainTbl.Rows(eagleRowSPos + 3).Cells(eagleColSPos + 2).innerHtml = enemyEagleCode
                mainTbl.Rows(eagleRowSPos + 3).Cells(eagleColSPos + 2).style.backgroundcolor = "dda180"
                                                      
            End Sub

            
            '팩맨, 악당 그리기 전에 현재 이미지 삭제 --------------------------------------------------------------
            Sub deletePackMan(getRow, getCol, isPackMan)
                On Error Resume Next
                For nRow = 0 To 3
                    For nCol = 0 To 3                    
                        '악당은 사과를 먹을 수 없어
                        IF isPackMan = "N" AND mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = appleCode Then
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = appleCode
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "salmon"
                        ELSEIF isPackMan = "N" AND mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = powerCode Then
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = powerCode
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "blue"
                        Else
                            IF mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml <> 7 THEN
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = 0
                            END IF
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "white"
                        End If
                    Next
                Next
            End Sub
            
            '팩맨, 악당 그리기 ----------------------------------------------------------------------------------
            Function drawPackMan(getBodyArr, getRow, getCol, getColor, isPackMan, getDir)

                getBodyArr(0, 0) = getRow
                getBodyArr(0, 1) = getCol
                getBodyArr(1, 0) = getRow
                getBodyArr(1, 1) = getCol + 3
                getBodyArr(2, 0) = getRow + 3 
                getBodyArr(2, 1) = getCol
                getBodyArr(3, 0) = getRow + 3
                getBodyArr(3, 1) = getCol + 3
                
                chk1Row = getBodyArr(0, 0)
                chk1Col = getBodyArr(0, 1)
                chk2Row = getBodyArr(1, 0)
                chk2Col = getBodyArr(1, 1)
                chk3Row = getBodyArr(2, 0)
                chk3Col = getBodyArr(2, 1)
                chk4Row = getBodyArr(3, 0)
                chk4Col = getBodyArr(3, 1)
                
                drawPackMan = "Y"
                
                If isPackMan = "Y" Then
                    markValue = packManCode
                Else
                    markValue = enemyCode
                End If
                
                '상단 벽 체크
                On Error Resume Next
                For chkCol = chk1Col To chk2Col
                    getResult = chkWallAndCrash(chk1Row, chkCol, isPackMan, getColor)
                    IF getResult <> "Y" Then
                        drawPackMan = getResult
                        Exit Function
                    End IF
                Next                
                
                '우측 벽 체크
                For chkRow = chk2Row To chk4Row
                    getResult = chkWallAndCrash(chkRow, chk2Col, isPackMan, getColor)
                    IF getResult <> "Y" Then
                        drawPackMan = getResult
                        Exit Function
                    End IF
                Next
                                
                '하단 벽 체크
                For chkCol = chk3Col To chk4Col
                    getResult = chkWallAndCrash(chk3Row, chkCol, isPackMan, getColor)
                    IF getResult <> "Y" Then
                        drawPackMan = getResult
                        Exit Function
                    End IF
                Next

                '좌측 벽 체크
                For chkRow = chk1Row To chk3Row
                    getResult = chkWallAndCrash(chkRow, chk1Col, isPackMan, getColor)
                    IF getResult <> "Y" Then
                        drawPackMan = getResult
                        Exit Function
                    End IF                                  
                Next

                '나와라 팩맨
                For nRow = 0 To 3
                    For nCol = 0 To 3

                        '악당은 사과를 먹을 수 없어
                        IF isPackMan = "N" AND mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = appleCode Then
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = appleCode
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "salmon"
                        ELSEIF isPackMan = "N" AND mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = powerCode Then
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = powerCode
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "blue"
                        Else 
                            '네모박스로 몽땅 채운 다음에 지워나간다.
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).innerHtml = markValue
                            mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = getColor
                            
                            '체인 상,하 전체
                            If (getDir = 1 OR getDir = 2) AND (nCol = 0 OR nCol = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "black"
                            End If

                            '체인 좌,우 전체
                            If (getDir = 3 OR getDir = 4) AND (nRow = 0 OR nRow = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "black"
                            End If

                            '체인 상 공백
                            If (getDir = 1 AND nRow = 0) AND (nCol = 0 OR nCol = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "white"
                            End If

                            '체인 하 공백
                            If (getDir = 2 AND nRow = 3) AND (nCol = 0 OR nCol = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "white"
                            End If           

                            '체인 좌 공백
                            If (getDir = 3 AND nCol = 0) AND (nRow = 0 OR nRow = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "white"
                            End If            

                            '체인 우 공백
                            If (getDir = 4 AND nCol = 3) AND (nRow = 0 OR nRow = 3) Then
                                mainTbl.Rows(getRow + nRow).Cells(nCol + getCol).style.backgroundcolor = "white"
                            End If
                        End If
                        
                    Next
                Next 
                
                labScore.innerHTML = eatFoodCnt                
                                                
            End Function
            
            '벽, 사과, 악당 만났는지 체크 --------------------------------------------------------------------------
            'drawPackMan에서 상,하,좌,우 체크 할 때 동일한 로직으로 호출 함.
            Function chkWallAndCrash(chkRow, chkCol, isPackMan, getColor)
                chkWallAndCrash = "Y"
                
                '사과를 먹자
                IF mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = appleCode And isPackMan = "Y" THEN
                    mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = 0
                    eatFoodCnt = eatFoodCnt + 1
                END IF
                
                '파워 팩맨 변신
                IF mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = powerCode And isPackMan = "Y" THEN
                    mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = 0
                    eatFoodCnt = eatFoodCnt + 1
                    poewrPackManYn = "Y"
                    packManColor = "red"
                END IF
                                
                '벽을 지나갈 수는 없지
                IF mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = wallCode OR _ 
                   mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = borderWallCode OR _
                   mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = eagleCode OR _
                   mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = enemyEagleCode THEN
                    chkWallAndCrash = "N"
                    Exit Function
                End If                


                '악당이 팩맨을 만나다.
                IF isPackMan = "N" AND endGameYn = "N" AND mainTbl.Rows(chkRow).Cells(chkCol).innerHtml = packManCode THEN
                    IF poewrPackManYn = "Y" THEN
                        chkWallAndCrash = "X"
                        Call destroyEnemy(getColor)
                    ELSE
                        window.clearTimeOut(timerID)
                        window.clearTimeOut(cannonTimerID)
                        loadingDiv.innerHTML = "<center><font size=3pt color=white><b>STAGE FAIL !</b></font></center>"
                        loadingDiv.style.visibility = "visible"
                        doSleep
                        'MsgBox "STAGE FAIL !"
                        endGameYn = "Y"                        
                    END IF
                    
                    Exit Function
                End IF
                
            End Function            
            
            '악당 죽었다 ----------------------------------------------------------------------------------
            Sub destroyEnemy(getEnemyColor)         
            
                For nRow = 0 To UBound(colorArr) - 1  
                    IF colorArr(nRow) = getEnemyColor THEN
                        targetEnemy = nRow
                        Exit For
                    END IF
                Next
                
                enemiesArr(targetEnemy, 4) = "N"   'DIE
                Call deletePackMan(enemiesArr(targetEnemy, 1), enemiesArr(targetEnemy, 2), "N")
                
            End Sub
            
            '악당 만들기 ----------------------------------------------------------------------------------
            Sub makeEnemies
                ennDir = 0
                For ennRow = 0 To UBound(enemiesArr) - 1
                    IF ennRow <> 3 THEN '독수리 자리는 빼고 만든다.
                        ennDir = ennDir + 1
                        IF ennDir > 4 THEN
                            ennDir = ennDir - 1
                        END IF
                        enemy1Row = 44
                        enemy1Col = 44 - (ennRow * 7)
                        enemyArr(0, 0) = enemy1Row
                        enemyArr(0, 1) = enemy1Col
                        enemyArr(1, 0) = enemy1Row
                        enemyArr(1, 1) = enemy1Col + 3
                        enemyArr(2, 0) = enemy1Row + 3
                        enemyArr(2, 1) = enemy1Col
                        enemyArr(3, 0) = enemy1Row + 3
                        enemyArr(3, 1) = enemy1Col + 3
                    
                        enemiesArr(ennRow, 0) = enemyArr
                        enemiesArr(ennRow, 1) = enemy1Row
                        enemiesArr(ennRow, 2) = enemy1Col
                        enemiesArr(ennRow, 3) = ennDir  '악당 방향
                        enemiesArr(ennRow, 4) = "Y"  '살아 있음
                    
                        okFalg = drawPackMan(enemiesArr(ennRow, 0), enemiesArr(ennRow, 1), enemiesArr(ennRow, 2), colorArr(ennRow), "N", enemiesArr(ennRow, 3))
                    END IF
                Next                
            End Sub            
            
            '팩맨 이동 --------------------------------------------------------------------------------
            Sub movePackMan            
                If endGameYn = "Y" Then
                    window.clearTimeOut(timerID)
                    Exit Sub
                    'Call startGame
                End If
                
                IF poewrPackManYn = "Y" Then
                    powerTime = powerTime + 1
                End IF

                '파워 팩맨 끝날때 쯤에 번쩍 번쩍
                IF poewrPackManYn = "Y" AND powerTime > (powerTimeLimit - 15) Then
                    IF packManColor = "red" THEN
                        packManColor = "teal"
                    ELSE
                        packManColor = "red"
                    END IF
                End IF
                
                IF powerTime = powerTimeLimit And poewrPackManYn = "Y" Then
                    powerTime = 0
                    poewrPackManYn = "N"
                    packManColor = "teal"
                End IF           
                
                '악당 먼저 이동(충돌시 악당 색깔을 가져와야 한다)
                Call moveEnemies     

                '팩맨 이동
                If packManDir = 1 Then
                    Call moveUp
                ElseIf packManDir = 2 Then
                    Call moveDown
                ElseIf packManDir = 3 Then       
                    Call moveLeft
                ElseIf packManDir = 4 Then
                    Call moveRight
                End If
                      
                'Call fireCannonMove(cannonRow, cannonCol, cannonDir)
                
                myScoreDiv.style.visibility = "hidden"
                enemyScoreDiv.style.visibility = "hidden"
                                
                window.clearTimeOut(timerID)
                timerID = window.setTimeOut("movePackMan", interval)
            End Sub
            
            '악당 이동 ----------------------------------------------------------------------------------
            Sub moveEnemies
                            
                responeCount.innerHTML = enemyResponeCnt
                
                Randomize
                setTarget = Int(8 * Rnd)
            
                On Error Resume Next
                For enemyRow = 0 To UBound(enemiesArr) - 1
                    IF enemiesArr(enemyRow, 4) = "Y" THEN   '살아 있는 악당만 움직인다.
                        Call deletePackMan(enemiesArr(enemyRow, 1), enemiesArr(enemyRow, 2), "N")
                        
                        moveFlag = enemyChkTurnDir(enemiesArr(enemyRow, 0), enemiesArr(enemyRow, 1), enemiesArr(enemyRow, 2), enemiesArr(enemyRow, 3))
                        
                        enemyColor = colorArr(enemyRow)      
    
                        If moveFlag = "1" Then
                            enemiesArr(enemyRow, 1) = enemiesArr(enemyRow, 1) - 1
                            enemiesArr(enemyRow, 3) = 1
                        ElseIf moveFlag = "2" Then
                            enemiesArr(enemyRow, 1) = enemiesArr(enemyRow, 1) + 1
                            enemiesArr(enemyRow, 3) = 2
                        ElseIf moveFlag = "3" Then       
                            enemiesArr(enemyRow, 2) = enemiesArr(enemyRow, 2) - 1
                            enemiesArr(enemyRow, 3) = 3
                        ElseIf moveFlag = "4" Then
                            enemiesArr(enemyRow, 2) = enemiesArr(enemyRow, 2) + 1
                            enemiesArr(enemyRow, 3) = 4
                        End If
                        
                        okFalg = drawPackMan(enemiesArr(enemyRow, 0), enemiesArr(enemyRow, 1), enemiesArr(enemyRow, 2), enemyColor, "N", enemiesArr(enemyRow, 3))
    
                        '악당 캐논 발사!
                        IF setTarget = enemyRow THEN
                            Call fireCannon(enemiesArr(enemyRow, 1), enemiesArr(enemyRow, 2), enemiesArr(enemyRow, 3), 2)
                        END IF
                    END IF
                    
                    IF enemiesArr(enemyRow, 4) = "N" THEN
                        enemyResponeCnt = enemyResponeCnt + 1
                    END IF

                    '악당 리스폰
                    IF enemyResponeCnt >= 70 AND enemiesArr(enemyRow, 4) = "N" THEN
                        enemy1Row = 44
                        
                        IF setTarget > 3 THEN
                            enemy1Col = 44 - (7 * 4)
                        ELSE
                            enemy1Col = 44 - (7 * 2)
                        END IF
                        enemyArr(0, 0) = enemy1Row
                        enemyArr(0, 1) = enemy1Col
                        enemyArr(1, 0) = enemy1Row
                        enemyArr(1, 1) = enemy1Col + 3
                        enemyArr(2, 0) = enemy1Row + 3
                        enemyArr(2, 1) = enemy1Col
                        enemyArr(3, 0) = enemy1Row + 3
                        enemyArr(3, 1) = enemy1Col + 3
                    
                        enemiesArr(enemyRow, 0) = enemyArr
                        enemiesArr(enemyRow, 1) = enemy1Row
                        enemiesArr(enemyRow, 2) = enemy1Col                        
                        enemiesArr(enemyRow, 4) = "Y"
                        enemyResponeCnt = 1
                    END IF
                Next                                  
            End Sub
            
            '악당 자동 방향 전환 ----------------------------------------------------------------------
            Function enemyChkTurnDir(getBodyArr, getRow, getCol, getDir)
                getBodyArr(0, 0) = getRow
                getBodyArr(0, 1) = getCol
                getBodyArr(1, 0) = getRow
                getBodyArr(1, 1) = getCol + 3
                getBodyArr(2, 0) = getRow + 3 
                getBodyArr(2, 1) = getCol
                getBodyArr(3, 0) = getRow + 3
                getBodyArr(3, 1) = getCol + 3

                chk1Row = getBodyArr(0, 0)
                chk1Col = getBodyArr(0, 1)
                chk2Row = getBodyArr(1, 0)
                chk2Col = getBodyArr(1, 1)
                chk3Row = getBodyArr(2, 0)
                chk3Col = getBodyArr(2, 1)
                chk4Row = getBodyArr(3, 0)
                chk4Col = getBodyArr(3, 1)                
                
                canMoveCnt = 0                
                
                enemyChkTurnDirUp = "N"
                enemyChkTurnDirDown = "N"
                enemyChkTurnDirLeft = "N"
                enemyChkTurnDirRight = "N"                
                
                '상단 벽 체크
                For chkCol = chk1Col To chk2Col
                    IF mainTbl.Rows(chk1Row - 1).Cells(chkCol).innerHtml <> wallCode AND _ 
                       mainTbl.Rows(chk1Row - 1).Cells(chkCol).innerHtml <> borderWallCode AND _ 
                       mainTbl.Rows(chk1Row - 1).Cells(chkCol).innerHtml <> enemyCode AND _
                       mainTbl.Rows(chk1Row - 1).Cells(chkCol).innerHtml <> eagleCode AND _
                       mainTbl.Rows(chk1Row - 1).Cells(chkCol).innerHtml <> enemyEagleCode THEN
                        canMoveCnt = canMoveCnt + 1
                    End If                    
                Next
                
                If canMoveCnt = 4 Then
                    enemyChkTurnDirUp = "Y"
                End If

                canMoveCnt = 0   
                
                '우측 벽 체크
                For chkRow = chk2Row To chk4Row
                    IF mainTbl.Rows(chkRow).Cells(chk2Col + 1).innerHtml <> wallCode AND _ 
                       mainTbl.Rows(chkRow).Cells(chk2Col + 1).innerHtml <> borderWallCode AND _ 
                       mainTbl.Rows(chkRow).Cells(chk2Col + 1).innerHtml <> enemyCode AND _ 
                       mainTbl.Rows(chkRow).Cells(chk2Col + 1).innerHtml <> eagleCode AND _ 
                       mainTbl.Rows(chkRow).Cells(chk2Col + 1).innerHtml <> enemyEagleCode THEN
                        canMoveCnt = canMoveCnt + 1
                    End If
                Next                

                If canMoveCnt = 4 Then
                    enemyChkTurnDirRight = "Y"
                End If                
                
                canMoveCnt = 0
                                
                '하단 벽 체크
                For chkCol = chk3Col To chk4Col                    
                    IF mainTbl.Rows(chk3Row + 1).Cells(chkCol).innerHtml <> wallCode AND _
                       mainTbl.Rows(chk3Row + 1).Cells(chkCol).innerHtml <> borderWallCode AND _
                       mainTbl.Rows(chk3Row + 1).Cells(chkCol).innerHtml <> enemyCode AND _
                       mainTbl.Rows(chk3Row + 1).Cells(chkCol).innerHtml <> eagleCode AND _
                       mainTbl.Rows(chk3Row + 1).Cells(chkCol).innerHtml <> enemyEagleCode THEN
                        canMoveCnt = canMoveCnt + 1
                    End If
                Next

                If canMoveCnt = 4 Then
                    enemyChkTurnDirDown = "Y"
                End If                
                
                canMoveCnt = 0     
                
                '좌측 벽 체크
                For chkRow = chk1Row To chk3Row
                    IF mainTbl.Rows(chkRow).Cells(chk1Col - 1).innerHtml <> wallCode AND _ 
                       mainTbl.Rows(chkRow).Cells(chk1Col - 1).innerHtml <> borderWallCode AND _
                       mainTbl.Rows(chkRow).Cells(chk1Col - 1).innerHtml <> enemyCode AND _
                       mainTbl.Rows(chkRow).Cells(chk1Col - 1).innerHtml <> eagleCode AND _
                       mainTbl.Rows(chkRow).Cells(chk1Col - 1).innerHtml <> enemyEagleCode THEN
                        canMoveCnt = canMoveCnt + 1
                    End If
                Next

                If canMoveCnt = 4 Then
                    enemyChkTurnDirLeft = "Y"
                End If

                Randomize
                rndDir = Int(10 * Rnd)
                                
                '탱크 한테 가자!!(상,하)
                IF rndDir < 5 THEN                    
                    IF chk1Row > intRow AND enemyChkTurnDirUp = "Y" THEN
                        getDir = 1
                        enemyChkTurnDirLeft = "N"
                        enemyChkTurnDirRight = "N"
                        enemyChkTurnDirDown = "N"
                    END IF
                    
                    IF chk1Row < intRow AND enemyChkTurnDirDown = "Y" THEN
                        getDir = 2  
                        enemyChkTurnDirLeft = "N"
                        enemyChkTurnDirRight = "N"
                        enemyChkTurnDirUp = "N"               
                    END IF
                END IF

                '탱크 한테 가자!!(좌,우)
                IF rndDir > 5 THEN                    
                    IF chk1Col > intCol AND enemyChkTurnDirLeft = "Y" THEN
                        getDir = 3
                        enemyChkTurnDirUp = "N"
                        enemyChkTurnDirRight = "N"
                        enemyChkTurnDirDown = "N"
                    END IF
                    
                    IF chk1Col < intCol AND enemyChkTurnDirRight = "Y" THEN
                        getDir = 4  
                        enemyChkTurnDirLeft = "N"
                        enemyChkTurnDirDown = "N"
                        enemyChkTurnDirUp = "N"               
                    END IF
                END IF                
                                                        
                '이동 중인 방향이 정상이고 선택지가 없다면 그 쪽으로 쭉 간다.
                '교차로가 나오면 꺽을 수도 있고 그냥 갈 수도 있다.
                '교차로에서 가던 방향의 반대 방향외의 선택지가 있으면 다른 쪽을 우선적으로 선택한다. (왕복 방지)
                If getDir = 1 And enemyChkTurnDirUp = "Y" Then
                    enemyChkTurnDir = "1"
                    
                    If rndDir > 7 Then
                        '가는 방향으로 문제 없지만 갈림길이 나오면 꺽는다.
                        If enemyChkTurnDirLeft = "Y" AND enemyChkTurnDirRight = "Y" Then
                            enemyChkTurnDir = "3"    
                            If rndDir = 1 Then
                                enemyChkTurnDir = "4"
                            End If
                        ElseIf enemyChkTurnDirLeft = "Y" Then
                            enemyChkTurnDir = "3"    
                        ElseIf enemyChkTurnDirRight = "Y" Then
                            enemyChkTurnDir = "4"
                        End If
                    End If
                    
                ElseIf getDir = 2 And enemyChkTurnDirDown = "Y" Then
                    enemyChkTurnDir = "2"

                    If rndDir > 7 Then
                        If enemyChkTurnDirLeft = "Y" AND enemyChkTurnDirRight = "Y" Then
                            enemyChkTurnDir = "3"    
                            If rndDir = 1 Then
                                enemyChkTurnDir = "4"
                            End If
                        ElseIf enemyChkTurnDirLeft = "Y" Then
                            enemyChkTurnDir = "3"    
                        ElseIf enemyChkTurnDirRight = "Y" Then
                            enemyChkTurnDir = "4"
                        End If
                    End If
                ElseIf getDir = 3 And enemyChkTurnDirLeft = "Y" Then
                    enemyChkTurnDir = "3"

                    If rndDir > 7 Then
                        If enemyChkTurnDirUp = "Y" AND enemyChkTurnDirDown = "Y" Then
                            enemyChkTurnDir = "1"
                            If rndDir = 1 Then
                                enemyChkTurnDir = "2"
                            End If
                        ElseIf enemyChkTurnDirUp = "Y" Then
                            enemyChkTurnDir = "1"    
                        ElseIf enemyChkTurnDirDown = "Y" Then
                            enemyChkTurnDir = "2"
                        End If                  
                    End If                  
                ElseIf getDir = 4 And enemyChkTurnDirRight = "Y" Then
                    enemyChkTurnDir = "4"

                    If rndDir > 7 Then
                        If enemyChkTurnDirUp = "Y" AND enemyChkTurnDirDown = "Y" Then
                            enemyChkTurnDir = "1"
                            If rndDir = 1 Then
                                enemyChkTurnDir = "2"
                            End If
                        ElseIf enemyChkTurnDirUp = "Y" Then
                            enemyChkTurnDir = "1"    
                        ElseIf enemyChkTurnDirDown = "Y" Then
                            enemyChkTurnDir = "2"
                        End If
                    End If
                Else
                    '그 외에는 이동 가능한 방향으로 보낸다.
                    '교차로에서 가던 방향의 반대 방향 외의 선택지가 있으면 다른 쪽을 우선적으로 선택한다. (왕복 방지)
                    detFlag = "N"  
                    If getDir = 1 Or getDir = 2 Then
                        If enemyChkTurnDirLeft = "Y" And enemyChkTurnDirRight = "Y" Then
                            If rndDir = 0 Then
                                enemyChkTurnDir = "3"
                            Else
                                enemyChkTurnDir = "4"
                            End If
                            detFlag = "Y"
                        ElseIf enemyChkTurnDirLeft = "Y" Then
                            enemyChkTurnDir = "3"
                            detFlag = "Y"
                        ElseIf enemyChkTurnDirRight = "Y" Then
                            enemyChkTurnDir = "4"
                            detFlag = "Y"
                        End If                    
                    ElseIf getDir = 3 Or getDir = 4 Then
                        If enemyChkTurnDirUp = "Y" And enemyChkTurnDirDown = "Y" Then
                            If rndDir = 0 Then
                                enemyChkTurnDir = "1"
                            Else
                                enemyChkTurnDir = "2"
                            End If
                            detFlag = "Y"
                        ElseIf enemyChkTurnDirUp = "Y" Then
                            enemyChkTurnDir = "1"
                            detFlag = "Y"
                        ElseIf enemyChkTurnDirDown = "Y" Then
                            enemyChkTurnDir = "2"
                            detFlag = "Y"
                        End If
                    End If             
                    
                    Do While 1 = 1
                        Randomize
                        rndDetDir = Int(4 * Rnd)
                        If enemyChkTurnDirUp = "Y" And rndDetDir = 0 Then
                            enemyChkTurnDir = "1"
                            Exit Do
                        ElseIf enemyChkTurnDirLeft = "Y" And rndDetDir = 1 Then
                            enemyChkTurnDir = "3"
                            Exit Do
                        ElseIf enemyChkTurnDirDown = "Y" And rndDetDir = 2 Then
                            enemyChkTurnDir = "2"
                            Exit Do
                        ElseIf enemyChkTurnDirRight = "Y" And rndDetDir = 3 Then
                            enemyChkTurnDir = "4"
                            Exit Do
                        End If
                        
                        IF enemyChkTurnDirUp <> "Y" AND enemyChkTurnDirLeft <> "Y" AND enemyChkTurnDirDown <> "Y" AND enemyChkTurnDirRight <> "Y" THEN
                            Exit Do
                        END IF
                    Loop

                End If                
                
            End Function
                                

            Sub fireCannon(getRow, getCol, getDir, getType)
                
                IF tankCannoCnt >= 2 THEN
                    EXIT SUB
                END IF

                IF enemyCannoCnt >= UBound(enemiesArr) THEN
                    EXIT SUB
                END IF
                                                
                cannonRow = getRow
                cannonCol = getCol
                cannonDir = getDir
                
                '탱크 방향
                If getDir = 1 Then
                    cannonRow = cannonRow
                    cannonCol = cannonCol + 1
                ElseIf getDir = 2 Then
                    cannonRow = cannonRow + 3
                    cannonCol = cannonCol + 1
                ElseIf getDir = 3 Then
                    cannonRow = cannonRow + 1
                    cannonCol = cannonCol
                ElseIf getDir = 4 Then
                    cannonRow = cannonRow + 1
                    cannonCol = cannonCol + 3
                End If         
                
                mainTbl.Rows(cannonRow).Cells(cannonCol).style.backgroundcolor = "blue"

                cannonCnt = cannonCnt + 1
                
                IF getType = 1 THEN
                    tankCannoCnt = tankCannoCnt + 1
                ELSE
                    enemyCannoCnt = enemyCannoCnt + 1
                END IF

                tankCannonArr(cannonCnt, 0) = cannonRow
                tankCannonArr(cannonCnt, 1) = cannonCol
                tankCannonArr(cannonCnt, 2) = cannonDir
                tankCannonArr(cannonCnt, 3) = getType '탱크/적군 캐논 구분
                
            End Sub

            
            Sub fireCannonMove
            
                IF endGameYn = "Y" THEN
                    EXIT Sub
                END IF
                
                For nRow = 1 To cannonCnt
                    getRow = tankCannonArr(nRow, 0)
                    getCol = tankCannonArr(nRow, 1)
                    getDir = tankCannonArr(nRow, 2)
                    tankType = tankCannonArr(nRow, 3)
                    targetRow = getRow
                    targetCol = getCol
                    
                    '보더벽 맞은 경우
                    IF targetRow >= rowBound - 2 OR targetRow <= 1 THEN
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "white"                            
                        
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1
                        
                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF                        

                        Exit For
                    END IF

                    '보더벽 맞은 경우
                    IF targetCol >= colBound - 2 OR targetCol <= 1 THEN
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "white"

                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                                                    
                        cannonCnt = cannonCnt - 1
                        
                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF                       
                         
                        Exit For
                    END IF
                                        
                    mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "white"
                                            
                    '포탄 방향
                    If getDir = 1 Then
                        targetRow = targetRow - 1
                    ElseIf getDir = 2 Then
                        targetRow = targetRow + 1
                    ElseIf getDir = 3 Then       
                        targetCol = targetCol - 1
                    ElseIf getDir = 4 Then
                        targetCol = targetCol + 1
                    End If
                    
                    tankCannonArr(nRow, 0) = targetRow
                    tankCannonArr(nRow, 1) = targetCol
                    
                    getColor = mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor
                                        
                    IF tankType = 1 THEN '아군포탄
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "222299"
                    ELSE
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "red"  
                    END IF
                    
                    '철벽은 부실수 없다.
                    If mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = borderWallCode Then        
                        mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = borderWallCode                
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = "black"
                        
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                                                    
                        cannonCnt = cannonCnt - 1

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                                                
                        Exit For                        
                    End If
                    
                    '악당이 포탄을 맞았다.
                    IF tankType = 1 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = enemyCode AND getColor <> "black" THEN
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1
                        
                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                
                                        
                        Call destroyEnemy(getColor)
                        Exit For 
                    End IF

                    '탱크가 악당 한테 당했다.
                    IF tankType = 2 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = packManCode THEN
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1
                        
                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF                
                        
                        window.clearTimeOut(cannonTimerID)
                        window.clearTimeOut(timerID)
                        loadingDiv.innerHTML = "<center><font size=3pt color=white><b>STAGE FAIL !</b></font></center>"
                        loadingDiv.style.visibility = "visible"
                        doSleep
                        endGameYn = "Y"
                        
                        Exit For 
                    End IF                    
                    
                    '아군이 아군 독수리 맞추면 그냥 제낌
                    IF tankType = 1 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = eagleCode THEN
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = getColor
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1                           

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                                        
                        Exit For                        
                    END IF
                    

                    '적군이 적군 독수리 맞추면 그냥 제낌
                    IF tankType = 2 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = enemyEagleCode THEN
                        mainTbl.Rows(targetRow).Cells(targetCol).style.backgroundcolor = getColor
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1                           

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                                                
                        Exit For                        
                    END IF                    

                    '적군 독수리 맞았다.
                    IF tankType = 1 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = enemyEagleCode THEN
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1                        

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                        
                        enemyEnergy = enemyEnergy - 1

                        enemyScoreDiv.innerHTML = "<center><font size=8pt color=red><b>" & enemyEnergy & "</b></font></center>"
                        enemyScoreDiv.style.visibility = "visible"
                          
                        IF enemyEnergy = 0 THEN                        
                            window.clearTimeOut(timerID)
                            window.clearTimeOut(cannonTimerID)
                            loadingDiv.innerHTML = "<center><font size=3pt color=white><b>STAGE CLEAR !</b></font></center>"
                            loadingDiv.style.visibility = "visible"
                            doSleep
                            endGameYn = "Y"
                        END IF
                        
                        Exit For 
                    End IF

                    '아군 독수리 맞았다.
                    IF tankType = 2 AND mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = eagleCode THEN
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                        
                        cannonCnt = cannonCnt - 1

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                        
                        myEnergy = myEnergy - 1

                        myScoreDiv.innerHTML = "<center><font size=8pt color=red><b>" & myEnergy & "</b></font></center>"
                        myScoreDiv.style.visibility = "visible"
                                                                        
                        IF myEnergy = 0 THEN
                            window.clearTimeOut(timerID)
                            window.clearTimeOut(cannonTimerID)
                            loadingDiv.innerHTML = "<center><font size=3pt color=white><b>STAGE FAIL !</b></font></center>"
                            loadingDiv.style.visibility = "visible"
                            doSleep
                            endGameYn = "Y"
                        END IF
                        
                        Exit For 
                    End IF                    
                                    
                    '벽 뽀개기
                    If mainTbl.Rows(targetRow).Cells(targetCol).innerHtml = wallCode Then
                        
                        On Error Resume Next
                        For brkRow = 0 To 3
                            For brkCol = 0 To 3
                                '내벽만 뽀갤 수 있다
                                IF mainTbl.Rows(targetRow + brkRow - 1).Cells(targetCol + brkCol - 1).innerHtml = wallCode THEN
                                    mainTbl.Rows(targetRow + brkRow - 1).Cells(targetCol + brkCol - 1).innerHtml = 0
                                    mainTbl.Rows(targetRow + brkRow - 1).Cells(targetCol + brkCol - 1).style.backgroundcolor = "white"
                                END IF
                            Next
                        Next
                        
                        '포탄 갯수 줄이기
                        For rRow = nRow To cannonCnt
                            tankCannonArr(rRow, 0) = tankCannonArr(rRow + 1, 0)
                            tankCannonArr(rRow, 1) = tankCannonArr(rRow + 1, 1)
                            tankCannonArr(rRow, 2) = tankCannonArr(rRow + 1, 2)
                            tankCannonArr(rRow, 3) = tankCannonArr(rRow + 1, 3)
                        Next
                                                    
                        cannonCnt = cannonCnt - 1

                        IF tankType = 1 THEN
                            tankCannoCnt = tankCannoCnt - 1
                        ELSE
                            enemyCannoCnt = enemyCannoCnt - 1
                        END IF
                                                
                        Exit For                        
                    End If
                Next               
                
                window.clearTimeOut(cannonTimerID)
                cannonTimerID = window.setTimeOut("fireCannonMove", 50)
            End Sub
            
            Sub moveUp
                Call deletePackMan(intRow, intCol, "Y")
                intRow = intRow - 1
                packManDir = 1
                okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                IF okFalg = "N" THEN
                    intRow = intRow + 1
                    okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                END IF                
            End Sub
                            
            Sub moveDown
                Call deletePackMan(intRow, intCol, "Y")
                intRow = intRow + 1
                packManDir = 2
                okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                IF okFalg = "N" THEN
                    intRow = intRow - 1    
                    okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                END IF               
            End Sub
            
            Sub moveLeft     
                Call deletePackMan(intRow, intCol, "Y")
                intCol = intCol - 1                
                packManDir = 3
                okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                IF okFalg = "N" THEN
                    intCol = intCol + 1    
                    okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                END IF
            End Sub            

            Sub moveRight
                Call deletePackMan(intRow, intCol, "Y")
                intCol = intCol + 1                
                packManDir = 4
                okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                IF okFalg = "N" THEN
                    intCol = intCol - 1    
                    okFalg = drawPackMan(packManArr, intRow, intCol, packManColor, "Y", packManDir)
                END IF
            End Sub
            
            Sub chekKeyPress
                
                'msgbox window.event.Keycode    '키 값을 알고 싶다면?
                
                If endGame <> "Y" Then
                    IF (window.event.Keycode = 119 Or window.event.Keycode = 56) THEN    'w키, 상
                        Call moveUp
                    END IF
    
                    IF (window.event.Keycode = 115 Or window.event.Keycode = 53) THEN    's키, 하
                        Call moveDown
                    END IF
                                    
                    IF (window.event.Keycode = 97 Or window.event.Keycode = 52) THEN    ' a키, 좌
                        Call moveLeft
                    END IF
    
                    IF (window.event.Keycode = 100 Or window.event.Keycode = 54) THEN    'd키, 우
                        Call moveRight
                    END IF

                    IF (window.event.Keycode = 32) THEN    '스페이스키, 파이어!
                        Call fireCannon(intRow, intCol, packManDir, 1)
                    END IF

                    IF (window.event.Keycode = 27) THEN    'ESC 중지/시작
                        MsgBox "일시중지!!"
                    END IF
                End If
            End Sub
            
            Sub animate
                Randomize                
                aniDir = Int(2 * Rnd)
                
                If aniDir = 0 Then
                    If aniXDir = 0 Then
                        intRow = intRow + 1
                    Else
                        intRow = intRow - 1
                    End If                
            
                    If intRow = colBound - 2 Then
                        aniXDir = 1
                    End If
    
                    If intRow = 1 Then
                        aniXDir = 0
                    End If
                End If

                Randomize                
                aniDir = Int(2 * Rnd)

                If aniDir = 0 Then
                    If aniYDir = 0 Then
                        intCol = intCol + 1
                    Else
                        intCol = intCol - 1
                    End If
                
                    If intCol = rowBound - 2 Then
                        aniYDir = 1
                    End If
    
                    If intCol = 1 Then
                        aniYDir = 0
                    End If
                End If
                
                On Error Resume Next
                Randomize                
                aniColor = Int(10 * Rnd)
                mainTbl.Rows(intRow).Cells(intCol).style.backgroundcolor = colorArr(aniColor)
                window.clearTimeOut(animateTimerID)
                animateTimerID = window.setTimeOut("animate", 100)
            End Sub
                        
        </script>
    </head>
    
    <body onKeyPress="chekKeyPress">
        <button onClick="startGame" style="width:35px;height:20px">Start</button>
        [Row:<label id="labRow">50</label>
        Col:<label id="labCol">50</label>]
        lv:<label id="labLevelCnt">1</label>
        Sc:<label id="labScore">0</label>
        Rsp:<label id="responeCount">0</label>
        <br>
        <div style="float:left;width:100%;height:95%;margin:3px;">
            <table id="mainTbl" style="width:100%;height:100%"></table>

            <div id="loadingDiv" style="position:absolute;border:2px solid;padding:5px;top:50%;left:25%;width:55%;height:5%;overflow:none;background-color:black;visibility:hidden;">
            <center><font size=3pt color=white><b>Loading ...</b></font></center>
            </div>        

            <div id="myScoreDiv" style="position:absolute;border:0px solid;padding:5px;top:10%;left:40%;width:20%;height:3%;overflow:none;background-color:none;visibility:hidden;">
            <center><font size=8pt color=red><b>5</b></font></center>
            </div> 
            
            <div id="enemyScoreDiv" style="position:absolute;border:0px solid;padding:5px;top:82%;left:40%;width:20%;height:3%;overflow:none;background-color:none;visibility:hidden;">
            <center><font size=8pt color=red><b>5</b></font></center>
            </div>            
        </div>
    </body>
</html>

 

보기에는 허접하지만 나름대로 꽤나 머리를 써서 만든 코드라서 아까워서 불펌은 절대 금지 합니다.

출처 표기도 안 되요 그냥 여기에 고이 놔둬 주세요. 부탁드려요 :)

반응형

댓글0