asimryu

축구게임 랜덤 포함(auto/refresh제외)

Oct 27th, 2014
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 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 = (Math.floor((Math.random() * 9) + 1)) * 50;
  33. var by = (Math.floor((Math.random() * 9) + 1)) * 50;
  34. var px = (Math.floor((Math.random() * 9) + 1)) * 50;
  35. var py = (Math.floor((Math.random() * 9) + 1)) * 50;
  36. $("#ball").css({left:bx,top:by});
  37. $("#post").css({left:px,top:py});
  38.  
  39. function goRight(){
  40. bx = bx + 50;
  41. if(bx > 450) bx = 450;
  42. $("#ball").css({left:bx});
  43. }
  44. function goLeft(){
  45. bx = bx - 50;
  46. if(bx < 0) bx = 0;
  47. $("#ball").css({left:bx});
  48. }
  49. function goUp(){
  50. by = by - 50;
  51. if(by < 0) by = 0;
  52. $("#ball").css({top:by});
  53. }
  54. function goDown(){
  55. by = by + 50;
  56. if(by > 450) by = 450;
  57. $("#ball").css({top:by});
  58. }
  59. function checkGoal(){
  60. if( bx == px && by == py ){
  61. alert("Gooooooooal~~!!");
  62. }
  63. }
  64. </script>
  65. </body>
  66. </html>
Advertisement
Add Comment
Please, Sign In to add comment