Game ini dirancang untuk dua poin:
Pertama, operasi kemenangan atau kekalahan
Karena gunting batu bersifat siklik
Gunting Batu Bunuh
Gunting dan Kain Bunuh
Batu Bunuh
Gunting Batu Bunuh
. . .
Cari tahu aturan berdasarkan karakteristik di atas dan tuliskan algoritma.
Biarkan komputer secara acak
Ini relatif mudah. Saya telah menulis artikel sebelumnya. Jika Anda tidak mengerti, Anda dapat pergi dan melihat sepatu anak -anak.
Geser layar acak
Faktanya, efek ini bukan kunci permainan, tetapi saya menambahkannya untuk terlihat lebih interaktif dan menyenangkan. Algoritma modulus digunakan di sini, dan efeknya dapat dicapai dengan melingkar sesuai dengan sisanya.
Screenshot Antarmuka
Akhirnya, kode ditambahkan
<! Doctype html> <html> <head> <meta charset = "utf -8"/> <itement> JS's Scissor Cloth Game - Qonftai Blog </iteme> <style type = "Text/CSS"> Div {margin: 20px auto; padding: 10px; Border: 2px Solid #999; Lebar: 200px; latar belakang: #ffe;} div#cu {font-weight: bold; font-size: 30px; tinggi: 40px; warna: merah;} div#la {border: none; tidak ada; display: none;} span {warna: red; font-font-font: bold;} </none; null, waktu = 20, Anda = 0, arr = array baru ('batu', 'rag', 'scissor'); fungsi p (n) {Anda = n; document.geteLementById ('you'). innerHtml = s (n); document.geteLementById ('st'). Disable = true; document.getElementById ('mb'). Disable = true; document.geteLementById ('jz'). Disabled = true; document.getelementbyid ('cUnn. setInterval ('t ()', 50);} function agin () {document.geteLementById ('st'). disabled = false; document.geteLementById ('mb'). disabled = false; document.geteLementById ('jz'). Donabled = false; document.getElementByid ('lAm') 'none'; document.geteLementById ('you'). innerHtml = ''; document.geteLementById ('pc'). innerHtml = ''; document.geteLementById ('cu'). innerHtml = ''; document.getElementById ('you'). 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>0){if(b==1){str += 'Computer Win';}else{str += 'You 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 = arr [waktu%3]; waktu-;} else {clearInterval (se); se = null; waktu = 20; bt ();} {non=) {n) {if == 1) {{{n) {n) {{n) {nule {nule {nl= 1) 'scissor';}} </script> </head> <body> <div> <p> Apa yang Anda keluar? <span id = "you"> Pilih </span> </p> <p> <tombol id = "st" ontClick = "p (1);"> Stone </buton> </p> <p> <tombol id = "mb" ontClick = "p (2);"> Train </buton> </p> <p> <tombol id = "jz" OnClick = "p (3);"> Scissor </button> </p> </div> <v> <p> Komputer keluar? </p> <span style = "" id = "pc"> </span> </div> <div id = "cu"> </div> <div id = "la"> <tombol id = "agin" onclick = "agin ()"> Lakukan lagi </button> </div> </body> </html>