function main(){ var count = 0, randoms = [], randoms2 = [], min = 1, max = 9, ten = document.getElementById("ten"), button = document.getElementById("start"), elems = []; for (let i = 0; i <= 14; i++){ //idの取得 elems[i] = document.getElementById(i); elems[i].src; } function doReload() { // reloadメソッドによりページをリロード window.location.reload(true); } reset.addEventListener("click", doReload, false) //resetボタンが押されたらdoReloadを実行 function dostart() { button.disabled = "true";// ボタンを使用不可にする for(let i = min; i <= max; i++){ while(true){ var tmp = intRandom(min, max); if(!randoms.includes(tmp)){ randoms.push(tmp); break; } } } for(let i = min; i <= max; i++){ while(true){ var tmp2 =intRandom2(min, max) -1; if(!randoms2.includes(tmp2)){ randoms2.push(tmp2); console.log(randoms2[i - 1]); break; } } } function intRandom(min, max){ return Math.floor( Math.random() * (max - min + 1)) + min; } function intRandom2(min, max){ return Math.floor( Math.random() * (max - min + 1)) + min; } for(let i = 0; i <= 8; i++){ elems[i].src = "./"+ String(randoms[i]) + ".png"; } for(let i = 0; i <= 2; i++){ elems[i + 9].src = "./siro.png"; console.log("自分./"+ String(randoms[randoms2[i]]) + ".png"); elems[i + 12].src = "./"+ String(randoms[randoms2[i]]) + ".png"; } // elems[12]の手札を使ったら勝手に消えるようにする elems[12].addEventListener("click", rock12,false); function rock12(){ elems[12].src = ""; if(randoms[randoms2[0]] == 1 || randoms[randoms2[0]] ==4 || randoms[randoms2[0]] ==7){ if(randoms[randoms2[3]] == 2 || randoms[randoms2[3]] == 5 || randoms[randoms2[3]] == 8){ wincount(); } }else if(randoms[randoms2[0]] == 2 || randoms[randoms2[0]] ==5 || randoms[randoms2[0]] ==8){ if(randoms[randoms2[3]] == 3 || randoms[randoms2[3]] == 6 || randoms[randoms2[3]] == 9){ wincount(); } }else if(randoms[randoms2[0]] == 3 || randoms[randoms2[0]] ==6 || randoms[randoms2[0]] ==9){ if(randoms[randoms2[3]] == 1 || randoms[randoms2[3]] == 4 || randoms[randoms2[3]] == 7){ wincount(); } } console.log("./"+ String(randoms[randoms2[3]]) + ".png"); elems[9].src = "./"+ String(randoms[randoms2[3]]) + ".png"; } // elems[13]の手札を使ったら勝手に消えるようにする elems[13].addEventListener("click", rock13,false); function rock13(){ elems[13].src = ""; if(randoms[randoms2[1]] == 1 || randoms[randoms2[1]] ==4 || randoms[randoms2[1]] ==7){ if(randoms[randoms2[4]] == 2 || randoms[randoms2[4]] == 5 || randoms[randoms2[4]] == 8){ wincount(); } }else if(randoms[randoms2[1]] == 2 || randoms[randoms2[1]] ==5 || randoms[randoms2[1]] ==8){ if(randoms[randoms2[4]] == 3 || randoms[randoms2[4]] == 6 || randoms[randoms2[4]] == 9){ wincount(); } }else if(randoms[randoms2[1]] == 3 || randoms[randoms2[1]] ==6 || randoms[randoms2[1]] ==9){ if(randoms[randoms2[4]] == 1 || randoms[randoms2[4]] == 4 || randoms[randoms2[4]] == 7){ wincount(); } } console.log("./"+ String(randoms[randoms2[4]]) + ".png"); elems[10].src = "./"+ String(randoms[randoms2[4]]) + ".png"; } // elems[14]の手札を使ったら勝手に消えるようにする elems[14].addEventListener("click", rock14,false); function rock14(){ elems[14].src = ""; if(randoms[randoms2[2]] == 1 || randoms[randoms2[2]] == 4 || randoms[randoms2[2]] == 7){ if(randoms[randoms2[5]] == 2 || randoms[randoms2[5]] == 5 || randoms[randoms2[5]] == 8){ wincount(); } }else if(randoms[randoms2[2]] == 2 || randoms[randoms2[2]] == 5 || randoms[randoms2[2]] == 8){ if(randoms[randoms2[5]] == 3 || randoms[randoms2[5]] == 6 || randoms[randoms2[5]] == 9){ wincount(); } }else if(randoms[randoms2[2]] == 3 || randoms[randoms2[2]] == 6 || randoms[randoms2[2]] == 9){ if(randoms[randoms2[5]] == 1 || randoms[randoms2[5]] == 4 || randoms[randoms2[5]] == 7){ wincount(); } } console.log("./"+ String(randoms[randoms2[5]]) + ".png"); elems[11].src = "./"+ String(randoms[randoms2[5]]) + ".png"; } } button.addEventListener("click", dostart, false); }; document.addEventListener("DOMContentLoaded", main, false); var count = 0; function wincount(){ count++; ten.innerText = String(count); }