asimryu

javascript 축구 게임 1(스크립트포함)

Sep 28th, 2014
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>coding game 1</title>
  6. <style>
  7. #buttons {}
  8. #buttons div {width:20px; height:20px; font-family:Arial;font-size:15px;background:#000;color:#fff;line-height:20px;text-align:center;display:inline-block;}
  9. #buttons div:hover {background:#00f;color:#ff0;cursor:pointer;}
  10. #box {width:500px;height:500px;border:1px solid #000;position:relative;background:url(http://webskills.kr/images/grid.png);}
  11. #post, #ball {width:50px;height:50px;position:absolute;}
  12. #post { background:url(http://webskills.kr/images/post.jpg);}
  13. #ball { background:url(http://webskills.kr/images/ball.jpg);}
  14. </style>
  15. </head>
  16. <body>
  17. <div id="buttons">
  18. <div onclick="goLeft();">←</div>
  19. <div onclick="goRight();">→</div>
  20. <div onclick="goUp();">↑</div>
  21. <div onclick="goDown();">↓</div>
  22. <div onclick="goAuto();" title="자동으로">A</div>
  23. <div onclick="checkGoal();" title="골체크">C</div>
  24. <div onclick="goRefresh();" title="새로시작">R</div>
  25. </div>
  26. <div id="box">
  27. <div id="post"></div>
  28. <div id="ball"></div>
  29. </div>
  30. <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
  31. <script>
  32. var bx = 100;
  33. var by = 100;
  34. var px = 300;
  35. var py = 300;
  36. $("#ball").css({left:bx,top:by});
  37. $("#post").css({left:px,top:py});
  38. function goLeft(){
  39. bx = bx - 50;
  40. checkGoal();
  41. }
  42. function goRight(){
  43. bx = bx + 50;
  44. checkGoal();
  45. }
  46. function goUp(){
  47. by = by - 50;
  48. checkGoal();
  49. }
  50. function goDown(){
  51. by = by + 50;
  52. checkGoal();
  53. }
  54. function checkGoal(){
  55. $("#ball").animate({left:bx,top:by});
  56. if( bx == px && by == py ) {
  57. alert("Goooooooooooal !!!!");
  58. }
  59. }
  60. function goRefresh(){
  61. bx = 100;
  62. by = 100;
  63. checkGoal();
  64. }
  65. function goAuto(){
  66. goRefresh();
  67. for(var i=1;i<=4;i++){
  68. goRight();
  69. }
  70. for(var i=1;i<=4;i++){
  71. goDown();
  72. }
  73. }
  74. </script>
  75. </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment