이 게임은 두 가지 점으로 설계되었습니다.
먼저, 승리 또는 패배 작전
석재 가위는 주기적이기 때문입니다
석재 킬 가위
가위와 천사
스톤 킬
석재 킬 가위
. . .
위의 특성을 기반으로 규칙을 찾아 알고리즘을 작성하십시오.
컴퓨터를 무작위로 두십시오
이것은 비교적 쉽습니다. 나는 전에 기사를 썼다. 이해하지 못하면 가서 어린이 신발을 살펴볼 수 있습니다.
임의의 화면 스 와이프
사실,이 효과는 게임의 열쇠가 아니지만 더 대화식적이고 재미있게 보이기 위해 추가했습니다. 여기에는 계수 알고리즘이 사용되며 나머지에 따라 반복하여 효과를 달성 할 수 있습니다.
인터페이스 스크린 샷
마지막으로 코드가 추가됩니다
<! doctype html> <html> <head> <meta charset = "utf -8"/> <title> JS의 가위 골 게임 -qiongtai 블로그 </title> <style type = "text/css"> div {margin : 20px auto; 패딩 : 10px; 테두리 : 2px solid #999; 너비 : 200px; 배경 : #ffe;} div#cu {font-weight : bold; font size : 30px; 높이 : 40px; 컬러 : 빨간색;} div#la {border : none; none; display : none; <script type = "text/javascript"> null, time = 20, you = 0, arr = new Array ( 'stone', 'rag', 'scissor'); function p (n) {you = n; document.getElementById ( 'you'). innerHtml = s (n); docum setInterVal ( 't ()', 50);} 함수 agin () {document.getElementById ( 'st'). disabled = false; document.getElementById ( 'mb'). disabled = false; document.getElementById ( 'jz') 'none'; getElementById ( 'you'). innerhtml = ''; hoceptml = '. innerHtml =' '; hoceptelementById ('cu '). innerHtml =' '; document.getElementById ('you '). innerHtml ='innerHtml = '; math.floor (math.random () * 3 +1); document.getElementById ( 'pc'). innerHtml = s (pc); var str = '; if (pc == you) {str +='trap ';} else {var b = pc-you; if (b == 1) {str +='computer Win '; win ';}} else {b = b*-1; if (b == 1) {str +='you win ';} else {str +='computer win ';}}} document.getElementById ('la '). style.display ='block '; getElementById ('cu '). t () {if (time> 0) {docut '가위';}} </script> </head> <body> <div> <p> 무엇이 나왔습니까? <span id = "you"> </span> </p> <p> <버튼 id = "st"onclick = "p (1);"> 스톤 </p> <p> <버튼 id = "mb"onclick = "p (2);"> train </button> </p> <p> <button id = "jz" onclick = "p (3);"> 가위 </button> </p> </div> <div> <p> 컴퓨터 아웃? </p> <span style = ""id = "pc"> </span> </div> <div id = "cu"> </div> <div id = "la"> <button id = "agin"onclick = "agin ()"> 다시 수행 </div> </div> </html>