반응형
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
 
<html>
 
<body>
    <canvas id="myCanvas" width="300" height="300" style="border:1px solid black">
    </canvas>
    <button onclick="addbody();"></button>
    <img src="heart.png" id="heart">
    <div style="border:1px solid black " id="block1"> 현재 점수 : 0점 입니다</div>
    <div style="border:1px solid black " id="block2"> 기록 <br></div>
    <script>
        var x = 0, y = 0;
        var vx = 1, vy = 0;
        var SnakeX = new Array(100);
        var SnakeY = new Array(100);
        var tall, n;
        var isLive = false;
        var appleCount =0;
        var appleX = 5, appleY = 10;
        var boomX =10, boomY = 20;
        var keyFlag = false;
        var point = new Array(100);
        var gameCount =0;
 
        function draw() {
            var canvas = document.getElementById("myCanvas");
            var ctx = canvas.getContext("2d");
 
            var img = document.getElementById("heart");
            ctx.beginPath();
            ctx.clearRect(00, canvas.width, canvas.height);
 
 
            ctx.fillStyle = "red";
            for (var i=0; i<n; i++)
            {
                ctx.fillRect(SnakeX[i] * 10, SnakeY[i] * 101010);
            }
            ctx.fillStyle = "blue";
            ctx.fillRect(appleX * 10, appleY * 101010);
            ctx.drawImage(img, appleX * 10, appleY * 101010);
            ctx.fillStyle = "black";
            ctx.fillRect(boomX * 10, boomY * 101010);
        }
 
        function collision(x, y)
        {
            for(var i=0; i<n; i++)
            {
                if(x == SnakeX[i] && y == SnakeY[i])
                    return true;
                if(x <0 || x>30||y<0||y>30)
                    return true;
            }
            return false;
        }
 
        function move() {
            if(!isLive)
                return;
            x = x + vx;
            y = y + vy;
            keyFlag=false;
            if (collision(x, y))
            {
                gameCount++;
                point[gameCount] = appleCount;
                document.getElementById("block2").innerHTML += gameCount +'번 째 기록 : '+ point[gameCount] +'점 입니다<br>';
                alert('충돌했네요!! 죽었어요');
                isLive = false;
                return;
            }
 
            if (x == appleX && y == appleY)
            {
                var isInbody = true;
                while(isInbody)
                {
                    appleX =Math.floor(Math.random()*21);
                    appleY = Math.floor(Math.random()*21);
                    isInbody = false;
 
                    for (var i =0;i<tall; i++){
                        if((appleX == SnakeX[i] && appleY == SnakeY[i]) || (appleX == boomX && appleY == boomY)){
                            isInbody = true;
                        }
                    }
                }
                tall = tall + 5;
                appleCount ++;
                document.getElementById("block1").innerHTML = '현재 점수 : '+ appleCount +'점 입니다';
            }
            if (x == boomX && y == boomY){
                gameCount++;
                point[gameCount] = appleCount;
                document.getElementById("block2").innerHTML += gameCount +'번 째 기록 : '+ point[gameCount] +'점 입니다<br>';
                alert('충돌했네요!! 죽었어요');
                isLive = false;
                return;
            }
            /*
                         tall 5, n 5
            SnakeX = [a, b, c, d, e]
                     [b  c  d  e]  n--*/
            if(n >= tall)
            {
                for(var i=0; i<n-1; i++)
                {
                    SnakeX[i]=SnakeX[i+1];
                    SnakeY[i]=SnakeY[i+1];
                }    
                n--;
            }
 
            SnakeX[n] = x;
            SnakeY[n] = y;
            n++;
 
            draw();
        }
        function addbody()
        {
            tall = tall + 5;
        }
        function onkeydown(evt)
        {
            //alert(evt.keyCode);
            if(evt.keyCode == 37&&keyFlag == false){
                if (vx ==1 && vy ==0){
                }
                else {
                vx = -1;
                vy = 0;
                keyFlag=true;
                }    
            }
            if(evt.keyCode == 38&&keyFlag == false){
                if (vx ==0 && vy==1){
                }
                else {
                vy = -1;
                vx = 0;
                keyFlag=true;
                }
            }
            if(evt.keyCode == 39&&keyFlag == false){
                if (vx==-1 && vy ==0){}
                else {
                vx = 1;
                vy = 0;
                keyFlag=true;
                }
            }
            if(evt.keyCode == 40&&keyFlag == false){
                if(vx==0 && vy ==-1){}
                else{
                vx = 0;
                vy = 1;
                keyFlag=true;
                }
            }
            if(evt.keyCode == 32&&keyFlag == false){
                if (isLive == false){
                isLive = true;
                x=0,y=0;
                tall =5;
                n=0;
                vx = 1, vy = 0;
                appleCount=0;
                appleX =Math.floor(Math.random()*21);
                appleY =Math.floor(Math.random()*21);
                document.getElementById("block1").innerHTML = '현재 점수 : '+ appleCount +'점 입니다';
                keyFlag=true;
                }
            }
            draw();
        }
 
        tall = 5;
        n = 0;
 
        draw();
 
        setInterval(move,80);
 
        document.addEventListener("keydown"onkeydown);
        
    </script>
 
    
</body>
 
</html>
cs

html-0921-jhs.zip



 

반응형

'Study > html' 카테고리의 다른 글

HTML - Array, updownGame  (0) 2018.09.20
HTML 실습  (0) 2018.09.14
반응형
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
<html>
    <head> 
        <meta charset ="utf-8"> <!--문자 코드셋 정의 -->
    </head>
<body>
 
        <input id="age" type="text"/> <!-- input text box-->
        <button onclick="btnclick()">button!</button><!-- button -->
 
    <div style="border:1px solid black " id="block1"> ...</div>
    <script>
 
        var p=10;
        var q=10;
        var r="문자열";
        
        function btnclick(){
            var a = (parseInt(document.getElementById("age").value)); 
            console.log(a);
            if(isNaN(a)){
                console.log("숫자가 아닙니다.");
            }
            else {
                document.getElementById("block1").innerHTML += '입력된 값은'+ a +'입니다<br>';
            }
        }
    </script>
</body>
</html>
cs

 

 

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
<html>
    <head> 
        <meta charset ="utf-8"> <!--문자 코드셋 정의 -->
    </head>
<body>
 
        <input id="age" type="text"/> <!-- input text box-->
        <input id="password" type="password"/> <!-- input password box-->
        <input id="date" type="date"/> <!-- input date box-->
        <input id="email" type="email"/> <!-- input email box-->
        <button onclick="btnclick()">button!</button><!-- button -->
 
    <div style="position:relative; border:1px solid black; border-radius : 10px; padding:5px; box-shadow: 10px 10px 5px silver " id="block1" onmousemove ="movemouse()"> 눌러보세요</div>
    <img id = "img1"></body>
    <script>
        var a = [10"안녕하세요"20"하이"];
        var b= new Array(10);
 
        function btnclick(){ // btn func
            for (var i =0; i<a.length;i++){
                a[i]=a[i]+1;
                console.log(a[i]);
            }
            for (var i = 0; i<b.length;i++){
                console.log("B index="+i+":"+b[i]);
            }
            if(document.getElementById("age").value == "1")
                document.getElementById("block1").innerHTML += a[0];
 
            a.push(document.getElementById("age").value);
        }
        function movemouse(){ // mouse hover func
            document.getElementById("block1").style.top = (Math.random()*500)+"px";
        }
        var i =0;
        var mytop =0;
        var velocity =0;
        setInterval (function() { // block1 move
            i++;
            document.getElementById("block1").style.top = (mytop*5+"px";
            mytop = mytop +velocity;
            if(mytop >100){
                mytop =100;
                velocity = -velocity*0.8;
            }
            else {
                velocity = velocity +0.5;
            }
            console.log("Hi"+i);
        }, 50);
    
    </script>
</body>
</html>
cs

 

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
<html>
    <head> 
        <meta charset ="utf-8"> <!--문자 코드셋 정의 -->
    </head>
<body>
    <input id="number" type="text" onkeypress = "if (event.keyCode ==13) btnclick();">
    <button onclick="btnclick()"> 확인! </button><!-- button --><br><br>
    <div style="position:relative; border:1px solid black; border-radius : 10px; padding:5px; box-shadow: 10px 10px 5px silver  "id="block1"> 1부터 500까지 숫자를 입력하세요. </div><br><br>
    <img id = "img" >
 
</body>
    <script>
        var result = Math.round(Math.random()*500);
        var count =0;
            function btnclick(){
                count ++;
            var a = (parseInt(document.getElementById("number").value)); 
            if(document.getElementById("number").value==result){
                document.getElementById("img").src = "3.jpg";
                document.getElementById("block1").innerHTML += '<br>값은'+ a +'입니다, '+ count +' 번 만에 맞추셨네요';
            }
            else if(document.getElementById("number").value >result && document.getElementById("number").value <=500){ 
                document.getElementById("block1").innerHTML += '<br>값은'+ a +'보다 작습니다';
                document.getElementById("img").src = "2.jpg";
            }
            else if(document.getElementById("number").value < result){
                document.getElementById("img").src = "1.jpg";
                document.getElementById("block1").innerHTML += '<br>값은'+ a +'보다 큽니다';
            }
            else if(document.getElementById("number").value >500){
                count --;
                alert("1에서 500사이의 숫자를 입력해 주세요.");
            }
        }
    </script>
 
</body>
</html>
cs

 

 

 

html-0920(updown).zip

 

반응형

'Study > html' 카테고리의 다른 글

HTML,JSP - Snake game  (0) 2018.09.27
HTML 실습  (0) 2018.09.14
반응형

 

// HTML 실습

font : 폰트 색상

br : 줄바꿈

a href : 링크

H1, H2, H3 : 소중대 제목

img src : 이미지

<img width ="100" height="100" src="cat.jpg">

<img width ="100%" height="100" src="cat.jpg"> // 100%로 화면에 꽉차게 넣을 수 있다.

주석 : <!-- 주석 다는 방법-->

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<html>
    <meta charset='UTF-8'>
        <body>
            HTML : <font color ="blue">Hyper-text Markup Language<br>
            <font color="black">
            helo world<br>
 
            <a href="http://google.co.kr"> http://google.co.kr</a><br>
            <a href ="second.html"> Move_SecondPage!<br></a>
            <font color="red"> FontColor =RED
            <font color="black">
        <H1>
            H1 Tag            
        </H1>
        <h2>
            H2 Tag
        </h2>
        <h3>
            H3 Tag
        </h3>
    <img src="cat.jpg">
    </body>
</html>
 
cs

 

 

 

 

 ******참고 링크******

https://www.w3schools.com/

 

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
<html>
    <meta charset='UTF-8'>
        <body style = "background-color: #000000; font-size: 20px; color: white">
            HTML : <font color ="blue">Hyper-text Markup Language<br>
            
            helo world<br>
 
            <a href="http://google.co.kr"> http://google.co.kr</a><br>
            <a href ="second.html"> Move_SecondPage!<br></a>
            <font color="red"> FontColor =RED
            <font color="pink">
        <H1>
            H1 Tag            
        </H1>
        <h2>
            H2 Tag
        </h2>
        <h3>
            H3 Tag
        </h3>
    <img width ="100" height="100" src="cat.jpg">
    <div style="background-image: ('cat.jpg')"></div>
    <div style="color: red"> next line move </div>
    <div> next line move </div>
    <span style="color:blue"> I don't want to next line move </span>
    <span style="color: green"> I don't want to next line move </span>
    </body>
</html>
 
cs

 

 

반응형

'Study > html' 카테고리의 다른 글

HTML,JSP - Snake game  (0) 2018.09.27
HTML - Array, updownGame  (0) 2018.09.20

+ Recent posts