Este juego está diseñado para dos puntos:
Primero, la operación de victoria o derrota
Porque las tijeras de piedra son cíclicas
Tijeras de matar piedras
Tijeras y mortes
Matar de piedra
Tijeras de matar piedras
. . .
Descubra las reglas basadas en las características anteriores y escriba el algoritmo.
Deje que la computadora al azar
Esto es relativamente fácil. He escrito un artículo antes. Si no entiende, puede ir y echar un vistazo a los zapatos de los niños.
Pantalla de pantalla aleatoria
De hecho, este efecto no es la clave del juego, pero se lo agregué para parecer más interactivo y divertido. Aquí se usa un algoritmo de módulo, y el efecto se puede lograr mediante el bucle de acuerdo con el resto.
Captura de pantalla de interfaz
Finalmente, se agrega el código
<! Doctype html> <html> <fead> <meta charset = "utf -8"/> <title> Juego de tela de tijera de JS - Qiongtai Blog </title> <style type = "text/css"> div {margen: 20px Auto; relleno: 10px; border: 2px sólido #999; ancho: 200px; fondo: #ffe;} div#cu {font-weight: bold; font-size: 30px; altura: 40px; color: rojo;} div#la {border: none; fondos: none; visual NULL, TIME = 20, USTED = 0, ARR = NEW Array ('Stone', 'Rag', 'Scissor'); Function P (N) {You = n; document.getElementById ('You'). Innerhtml = s (n); document.getElementById ('st'). discapacited = true; document.getElementById ('mb'). Disability = true; document.getElementById ('jz'). DISCABILICIO = True; document.getElementById ('Cu'). innerhtml = '...'; setInterval ('t ()', 50);} function agin () {document.getElementById ('st'). discapaced = false; document.getElementById ('mb'). DISCABILED = false; document.getElementById ('jz'). DISCABILED = FALSE; document.getElementById ('la'). style.disPlay = 'Ninguno'; document.getElementById ('you'). innerhtml = ''; document.getElementById ('pc'). innerHtml = ''; document.getElementById ('cu'). innerhtml = '' '; document.getElementById (' you '). Innerhtml =' por favor seleccionar ';} function bt () Math.floor (math.random () * 3 +1); document.getElementById ('PC'). InnerHtml = s (PC); var str = '' '; if (pc == you) {str +=' trap ';} más {var b = pc-you; if (b> 0) {if (b == 1) {str +=' computer win ';} más Win ';}} else {b = b*-1; if (b == 1) {str +=' win ';} else {str +=' computer win ';}}} document.getElementById (' la '). Style.display =' block '; document.getElementById (' cuh '). Innerhtml = str;} function function t () {if (time> 0) {document.getElementById ('pc'). innerHtml = arr [time%3]; time-;} más {clearInterval (se); se = null; time = 20; bt ();}} function s (n) {if (n == 1 1) {stone ';} if (n == 2 2 2) 'scissor';}} </script> </head> <body> <div> <p> ¿Qué saliste? <span id = "you"> Seleccione </span> </p> <p> <button id = "st" onClick = "p (1);"> piedra </boton> </p> <p> <button id = "mb" onClick = "p (2);"> trenes </botón> </p> <p> <button id = "jz" onClick = "p (3);"> scissor </boton> </p> </div> <div> <p> computadora? </p> <span style = "" id = "pc"> </span> </iv> <div id = "cu"> </div> <div id = "la"> <botón id = "agin" onClick = "agin ()"> hágalo nuevamente </botón> </div> </body> </html>