このゲームは2つのポイントに設計されています。
まず、勝利または敗北の操作
ストーンハサミは周期的だからです
ストーンキルシザー
はさみと布の殺害
ストーンキル
ストーンキルシザー
。 。 。
上記の特性に基づいてルールを見つけ、アルゴリズムを書きます。
コンピューターをランダムにします
これは比較的簡単です。以前に記事を書いたことがあります。わからない場合は、子供の靴を見に行くことができます。
ランダムな画面スワイプ
実際、この効果はゲームの鍵ではありませんが、よりインタラクティブで楽しく見えるように追加しました。ここでは弾性アルゴリズムが使用され、残りに応じてループすることで効果を達成できます。
インターフェイススクリーンショット
最後に、コードが追加されます
< #999; width:200px; background:#ffe;} div#cu {font-weight:bold; font-size:30px; height:40px; color:red;} div#la {border:none; none; none; display:none;} span;} span {color:color:red; font-weigh:bold;} </stircr> <spelipt> null、time = 20、you = 0、arr = new array( 'stone'、 'rag'、 'scissor'); function p(n){you = n; document.getElementById( 'you')。innerhtml = s(n); document.getElementbyid( 'st')。disabled = true; document.getElementByid( 'mb')。disabled = true; document.getElementbyid( 'z') setInterval( 't()'、50);} function agin(){document.getElementById( 'st')。disabled = false; document.getElementByid( 'mb') 'none'; document.getElementByid( 'you')。innerhtml = ''; document.getElementById( 'pc')。innerhtml = ''; document.getElementById( 'cu')。 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> 0){(b == 1){str += 'computer +=' computer win win win ';}} else {b = b*-1; if(b == 1){str +=' you win ';} else {str +=' computer win ';}}} document.getElementbyid(' la ')。style.display=' block '; document.getelementbyid(' cu ')。 t(){if(time> 0){document.getElementbyId( 'pc')。innerhtml = arrhtml = arr [time%3]; time - ;} else {clearinterval(se); se = null; time = 20; bt();}} function s(n){if(n == 1){return 'stone';} firs '; 'scissor';}} </script> </head> <body> <div> <p>何が出てきましたか? <span id = "you">選択してください</span> </p> <p> <ボタンid = "st" onclick = "p(1);"> stone </button> </p> <p> <button id = "mb" onclick = "p(2);" onclick = "p(3);"> scissor </button> </p> </div> <div> <p>コンピュータアウト? </p> <span style = "" id = "pc"> </span> </div> <div id = "cu"> </div> <div id = "la"> <button id = "agin" onclick = "agin()">再び</button> </div> </body> </html>