Buenas ,
Hace nada (ayer) me puse a aprender algo de javascript, me pareció entretenido intentar hacer el siguiente 'piedra, papel o tijeras', básicamente es como el clásico, pero con más opciones;
Sería un placer leer sus aportaciones (si pegáis el code en la consola del navegador podréis probarlo);
Hace nada (ayer) me puse a aprender algo de javascript, me pareció entretenido intentar hacer el siguiente 'piedra, papel o tijeras', básicamente es como el clásico, pero con más opciones;
Sería un placer leer sus aportaciones (si pegáis el code en la consola del navegador podréis probarlo);
Código (javascript) [Seleccionar]
function randomnumber() //Número aleatorio (Para asignar a la máquina)
{
var numero = Math.floor( Math.round(Math.random() * 15 ));
return numero;}
function allgame() //Base juego
{
userOption = prompt("Select a one option; \n Gun = 0 \n Lightning = 1 \n Devil = 2 \n Dragon = 3 \n Water = 4 \n Air = 5 \n Paper = 6 \n Sponge = 7 \n Wolf = 8 \n Tree = 9 \n Human = 10 \n Snake = 11 \n Scissors = 12 \n Fire = 13 \n Rock = 14");
alert("Your select " + options[userOption]);
alert("Machine select " + options[machineOption]);
userOption = parseInt(userOption);
switch(userOption){
case 0:
//Gun
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Rock" || machineOption == "Fire" || machineOption == "Scissors" || machineOption == "Snake" || machineOption == "Human" || machineOption == "Tree" || machineOption == "Wolf"){
alert("Yea, you're a winner");
}
else if(machineOption != "Lightning" || machineOption == "Devil" || machineOption == "Dragon" || machineOption == "Water" || machineOption == "Air" || machineOption == "Paper" || machineOption == "Sponge"){
alert("Oh, damn.. you're a loser");
}
continuos;
break;
case 1:
//Lightning
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Gun" || machineOption == "Rock" || machineOption == "Fire" || machineOption == "Scissors" || machineOption == "Snake" || machineOption == "Human" || machineOption == "Tree"){
alert("Yea, you're a winner");
}
else if(machineOption == "Devil" || machineOption == "Dragon" || machineOption == "Water" || machineOption == "Air" || machineOption == "Paper" || machineOption == "Sponge" || machineOption == "Wolf"){
alert("Oh, damn.. you're a loser");
}
break;
case 2:
//Devil
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Lightning" || machineOption == "Gun" || machineOption == "Rock" || machineOption == "Fire" || machineOption == "Scissors" || machineOption == "Snake" || machineOption == "Human"){
alert("Yea, you're a winner");
}
else if(machineOption == "Dragon" || machineOption == "Water" || machineOption == "Air" || machineOption == "Paper" || machineOption == "Sponge" || machineOption == "Wolf" || machineOption == "Tree"){
alert("Oh, damn.. you're a loser");
}
break;
case 3:
//Dragon
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Devil" || machineOption != "Lightning" || machineOption == "Gun" || machineOption == "Rock" || machineOption == "Fire" || machineOption == "Scissors" || machineOption == "Snake"){
alert("Yea, you're a winner");
}
else if(machineOption == "Water" || machineOption == "Air" || machineOption == "Paper" || machineOption == "Sponge" || machineOption == "Wolf" || machineOption == "Tree"|| machineOption == "Human"){
alert("Oh, damn.. you're a loser");
}
break;
case 4:
//Water
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Dragon" || machineOption != "Devil" || machineOption != "Lightning" || machineOption == "Gun" || machineOption == "Rock" || machineOption == "Fire" || machineOption == "Scissors"){
alert("Yea, you're a winner");
}
else if(machineOption == "Air" || machineOption == "Paper" || machineOption == "Sponge" || machineOption == "Wolf" || machineOption == "Tree"|| machineOption == "Human"|| machineOption == "Snake"){
alert("Oh, damn.. you're a loser");
}
break;
case 5:
//Air
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Water" ||machineOption != "Dragon" || machineOption != "Devil" || machineOption != "Lightning" || machineOption == "Gun" || machineOption == "Rock" || machineOption == "Fire"){
alert("Yea, you're a winner");
}
else if(machineOption == "Paper" || machineOption == "Sponge" || machineOption == "Wolf" || machineOption == "Tree"|| machineOption == "Human"|| machineOption == "Snake"|| machineOption == "Scissors"){
alert("Oh, damn.. you're a loser");
}
break;
case 6:
//Paper
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Air" || machineOption != "Water" ||machineOption != "Dragon" || machineOption != "Devil" || machineOption != "Lightning" || machineOption == "Gun" || machineOption == "Rock"){
alert("Yea, you're a winner");
}
else if(machineOption == "Sponge" || machineOption == "Wolf" || machineOption == "Tree"|| machineOption == "Human"|| machineOption == "Snake"|| machineOption == "Scissors"|| machineOption == "Fire"){
alert("Oh, damn.. you're a loser");
}
break;
case 7:
//Sponge
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Paper" || machineOption != "Air" || machineOption != "Water" ||machineOption != "Dragon" || machineOption != "Devil" || machineOption != "Lightning" || machineOption == "Gun"){
alert("Yea, you're a winner");
}
else if(machineOption == "Wolf" || machineOption == "Tree"|| machineOption == "Human"|| machineOption == "Snake"|| machineOption == "Scissors"|| machineOption == "Fire"|| machineOption == "Rock"){
alert("Oh, damn.. you're a loser");
}
break;
case 8:
//Wolf
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Sponge" || machineOption != "Paper" || machineOption != "Air" || machineOption != "Water" ||machineOption != "Dragon" || machineOption != "Devil" || machineOption != "Lightning"){
alert("Yea, you're a winner");
}
else if(machineOption == "Tree"|| machineOption == "Human"|| machineOption == "Snake"|| machineOption == "Scissors"|| machineOption == "Fire"|| machineOption == "Rock"|| machineOption == "Gun"){
alert("Oh, damn.. you're a loser");
}
break;
case 9:
//Tree
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Wolf" || machineOption != "Sponge" || machineOption != "Paper" || machineOption != "Air" || machineOption != "Water" ||machineOption != "Dragon" || machineOption != "Devil"){
alert("Yea, you're a winner");
}
else if(machineOption == "Human"|| machineOption == "Snake"|| machineOption == "Scissors"|| machineOption == "Fire"|| machineOption == "Rock"|| machineOption == "Gun"|| machineOption != "Lightning"){
alert("Oh, damn.. you're a loser");
}
break;
case 10:
//human
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption != "Tree" ||machineOption != "Wolf" || machineOption != "Sponge" || machineOption != "Paper" || machineOption != "Air" || machineOption != "Water" ||machineOption != "Dragon"){
alert("Yea, you're a winner");
}
else if(machineOption == "Snake"|| machineOption == "Scissors"|| machineOption == "Fire"|| machineOption == "Rock"|| machineOption == "Gun"|| machineOption != "Lightning"|| machineOption != "Devil"){
alert("Oh, damn.. you're a loser");
}
break;
case 11:
//Snake
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Snake"||machineOption != "Tree" ||machineOption != "Wolf" || machineOption != "Sponge" || machineOption != "Paper" || machineOption != "Air" || machineOption != "Water"){
alert("Yea, you're a winner");
}
else if(machineOption == "Scissors"|| machineOption == "Fire"|| machineOption == "Rock"|| machineOption == "Gun"|| machineOption != "Lightning"|| machineOption != "Devil"||machineOption != "Dragon"){
alert("Oh, damn.. you're a loser");
}
break;
case 12:
//Scissors
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Scissors"||machineOption == "Snake"|| machineOption != "Tree" ||machineOption != "Wolf" || machineOption != "Sponge" || machineOption != "Paper" || machineOption != "Air"){
alert("Yea, you're a winner");
}
else if(machineOption == "Fire"|| machineOption == "Rock"|| machineOption == "Gun"|| machineOption != "Lightning"|| machineOption != "Devil"||machineOption != "Dragon"|| machineOption != "Water"){
alert("Oh, damn.. you're a loser");
}
break;
case 13:
//Fire
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Fire"||machineOption == "Scissors"||machineOption == "Snake"|| machineOption != "Tree" ||machineOption != "Wolf" || machineOption != "Sponge" || machineOption != "Paper"){
alert("Yea, you're a winner");
}
else if(machineOption == "Rock"|| machineOption == "Gun"|| machineOption != "Lightning"|| machineOption != "Devil"||machineOption != "Dragon"|| machineOption != "Water" || machineOption != "Air"){
alert("Oh, damn.. you're a loser");
}
break;
case 14:
//Rock
if(machineOption == userOption){
alert("tie :O");
}
else if(machineOption == "Rock"|| machineOption == "Fire"||machineOption == "Scissors"||machineOption == "Snake"|| machineOption != "Tree" ||machineOption != "Wolf" || machineOption != "Sponge"){
alert("Yea, you're a winner");
}
else if(machineOption == "Gun"|| machineOption != "Lightning"|| machineOption != "Devil"||machineOption != "Dragon"|| machineOption != "Water" || machineOption != "Air" || machineOption != "Paper"){
alert("Oh, damn.. you're a loser");
}
default:{
alert("Stupid boy, select a one valid option...");
}
}}
var userOption;
var options = ["Gun", "Lightning", "Devil", "Dragon", "Water", "Air", "Paper", "Sponge", "Wolf", "Tree", "Human", "Snake", "Scissors", "Fire", "Rock"];
alert("Hello, I'm the creation, the first creation on javascript, please, select a one option,.. you know rock, paper scrissors?, it's similar");
allgame();
finishgame =false;//condicion para salir/entrar en el do-while
do{
allgame();
alert("You like play again?")
var machineOption = randomnumber();
var answerAgain;
answerAgain = prompt("Please, write 'Yes' or 'No'", "Yes")
if(answerAgain == "Yes" || answerAgain == "YEs"|| answerAgain == "YES"|| answerAgain == "yES"|| answerAgain == "yeS"|| answerAgain == "yEs"|| answerAgain == "yes"){
alert("Reload game..");
finishgame = true;
}
else if(answerAgain == "No" || answerAgain == "no" || answerAgain == "NO" || answerAgain == "nO"){
alert("Leaving game...");
finishgame = false;
}
else{
("Leaving game.. ");
finishgame = false;
}
}while(finishgame)