vendredi 27 mars 2015

How to create a random computer choice, except the choice you already choose?

I'am making a boxing game. The user can choose between three boxers. The computer can choose between the remainder two(that you don't have choosen). http://ift.tt/19YeB8Q My HTML is



<p id="printNames0"></p>

<div id="jouwbokser">
<h1>Kies Jouw Bokser!</h1>
<img id="bokser1" onClick="gevecht1()" src="img/bokser1.png" alt="bokserlinks" />
<img id="bokser2" onClick="gevecht2()" src="img/bokser2.png" alt="boksermidden" />
<img id="bokser3" onClick="gevecht3()" src="img/bokser3.png" alt="bokserrechts" />

</div>


My javascript is:



var bokser = ['bokser1', 'bokser2', 'boker3' ];
var userChoice;
var comChoice;



//functie die laat zien welke bokser je hebt gekozen.
function greet(){
return ("Je hebt" + userChoice.toLowerCase() + "gekozen");
}

//functie die tekst showt in html
function printToPage(test){
var content = document.getElementsByTagName('body')[0];
content.innerHTML = ("<p>" + test + "</p>" + content.innerHTML);

}


//bokser object
var bokser1 = {
hitpoints: 100,
attack1: 2,
attack2:5,
attack3:8,
attack4:12
};

var bokser2 = {
hitpoints:100,
attack1:2,
attack2:5,
attack3:8,
attack4:12
};

var bokser3 = {
hitpoints:100,
attack1:2,
attack2:5,
attack3:8,
attack4:12
};



//kies bokser
//andere boksers worden display none als bokser gekozen is
//kies bokser1
function gevecht1(){
document.getElementById("bokser2").style.display = "none";
document.getElementById("bokser3").style.display = "none";
userChoice = bokser[0];
printToPage(greet());
}

//kies bokser2
function gevecht2(){
document.getElementById("bokser1").style.display = "none";
document.getElementById("bokser3").style.display = "none";
userChoice = bokser[1];
printToPage(greet());
}

//kies bokser3
function gevecht3(){
document.getElementById("bokser1").style.display = "none";
document.getElementById("bokser2").style.display = "none";
userChoice = bokser[2];
printToPage(greet());
}


Has anyone an idea how to create the computer choice random, except the one you choose before.





Aucun commentaire:

Enregistrer un commentaire