(() => {
var mogura1;
var mogura2;
var mogura3;
	
var tensu;
var sum;
var owari = false;
var button;


function startgame(){
    mogura1 = document.getElementById("image1");
    mogura2 = document.getElementById("image2");
    mogura3 = document.getElementById("image3");
    sum = document.getElementById("ten");

    button = document.getElementById("start");
    button.onclick = function(){
	owari = false;
	tensu = 0;
	sum.innerHTML = tensu;
	startgame();
    }
    
    
    mogura1.onclick = function(){
	mogura1.src="mogurax.png"
	setTimeout(modosu1,1000);
	tensu = tensu + 1;
	goukei.innerHTML = tensu;
    }
    mogura2.onclick = function(){
	mogura2.src="mogurax.png"
	setTimeout(modosu2,1000);
	tensu = tensu + 1;
	goukei.innerHTML = tensu;
    }
    mogura3.onclick = function(){
	mogura3.src="mogurax.png"
	setTimeout(modosu3,1000);
	tensu = tensu + 1;
	goukei.innerHTML = tensu;
    }
    
    
    var ransu1 = Math.random()*3*1000
    setTimeout(hidden1,ransu1);
    
     var ransu2 = Math.random()*3*1000
    setTimeout(hidden2,ransu2);
    
     var ransu3 = Math.random()*3*1000
    setTimeout(hidden3,ransu3);



    setTimeout(endgame,10000);
}



function endgame(){
    alert("おしまい!!!")
    owari = true;
	
}



function modoru1(){
    mogura1.src="mogura.png"
}

function modoru2(){
    mogura2.src="mogura.png"
}

function modoru3(){
    mogura3.src="mogura.png"
}



function hidden1(){
    mogura1.style.visibility = "hidden";
	if(owari == false){
    var ransu = Math.random()*3*1000
    setTimeout(visible1,ransu);
}
}
function hidden2(){
    mogura2.style.visibility = "hidden";
     if(owari == false){
    var ransu = Math.random()*3*1000
    setTimeout(visible2,ransu);
     }
}
function hidden3(){
    mogura3.style.visibility = "hidden";
     if(owari == false){
    var ransu = Math.random()*3*1000
    setTimeout(visible3,ransu);
     }
}



function visible1() {
     if(owari == false){
    mogura1.style.visibility ="visible";
}
    var ransu = Math.random()*3*1000
    setTimeout(hidden1,ransu);
}

function visible2() {
     if(owari == false){
    mogura2.style.visibility ="visible";
}
    var ransu = Math.random()*3*1000
    setTimeout(hidden2,ransu);
     }
     
function visible3() {
     if(owari == false){
	 mogura3.style.visibility ="visible";
     }
    var ransu = Math.random()*3*1000
    setTimeout(hidden3,ransu);
}
})();
