<meta charset="UTF-8">
<script>
function writetitle (blabla){
document.write("<h1>" + "<big>" + linhabunita + blabla + linhabunita + "</big>" + "</h1>");
jjump();
}
function jump (){
document.write("<br><hr><br>");
}
function jjump (){
document.write("<br><br><br><br>");
}
function writeonscreen(blabla){
document.write("<big>" + blabla + "</big>");
jump();
}
var linhabunita = "___________________________";
var marmotax = Math.round(Math.random() * 10);
var marmotay = Math.round(Math.random() * 10);
function lançamarmotalinha(n, m){
for(marmotax; marmotax > m | marmotax == 0; marmotax = Math.round(Math.random() * n)){}
return marmotax;
}
function lançamarmotacoluna(n, m){
for(marmotay; marmotay > m | marmotay == 0; marmotay = Math.round(Math.random() * n)){}
return marmotay;
}
writetitle("Jogo da Marmota");
lançamarmotalinha(10, 10);
console.log(marmotax);
lançamarmotacoluna(10, 10);
console.log(marmotay);
</script>
<big>Onde você quer cavar x?</big>
<input/>
<br>
<big>Onde você quer cavar y?</big>
<input/>
<br>
_______________________________________<button>Cavar!</button>
<br>
<br>
<script>
var chutex = parseInt(document.querySelector("input"));
var chutey = parseInt(document.querySelector("input"));
function cavar(){
if(chutex.value != marmotax && chutey.value != marmotay){
alert("Essa foi longe! Passe para o próximo jogador e tente mais tarde novamente.");
chutex.value = "";
chutey.value = "";
chutex.focus;
}
if(chutex.value == marmotax && chutey.value != marmotay){
alert("Essa foi perto! Passe para o próximo jogador e tente mais tarde novamente.");
chutex.value = "";
chutey.value = "";
chutex.focus;
}
if(chutex.value != marmotax && chutey.value == marmotay){
alert("Essa foi perto! Passe para o próximo jogador e tente mais tarde novamente.");
chutex.value = "";
chutey.value = "";
chutex.focus;
}
if(chutex.value == marmotax && chutey.value == marmotay){
alert("Parabéns,você encotrou a marmota! Se quiser jogar novamente reinicie o navegador.");
}
}
var button1 = document.querySelector("button");
function terralado(){document.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");}
function terraciba(){document.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" + "<br>");}
function marmotavagaba(){
terraciba();
terraciba();
for(linha = 1; linha <= 10; linha++){
terralado();
for(coluna = 1; coluna <= 10; coluna++){
if(linha == chutex && coluna == coluna){
if(chutex == marmotax && chutey == marmotay){
document.write("M.");
}
if(chutex != marmotax && chutey != marmotay){
document.write("xx.");
}
}else{
document.write("__.");
}
}
terralado();
document.write("<br>");
}
terraciba();
terraciba();
}
button1.onclick = cavar, marmotavagaba;
</script>