muljal bu soxta rang turgan katak nomeri men jadval yaratyotganimda har bir katak uchun id berib ketgan edim :)
JavaScriptda yozilgan to'liq kodim:
/////////////////////////////////////////////////////////
///// /////
///// Rang Tanla O'yini /////
///// /////
/////////////////////////////////////////////////////////
//table td lariga colors class berildi
let log=console.log;
let vaqtEniGlobgal = 500;
let vaqtEni=500;
let score=0; //Natija
let isLose=false;
let win=false;
let alertMsg=true; //Alert chiqarish yoki chiqarmaslik
const prise=50; //Sovg'a olish balli
let scoreGame=document.getElementById("score"); /*O'yindagi Natija maydoni*/ let kod="BULALAR_TM";
let refresh=document.getElementById("refresh");
refresh.style.visibility="hidden";
GameStart();
function GameStart(){
if(!isLose){
let tdNum=Math.floor(Math.random() * 4)+2; //Kataklar soni
var muljal=Math.floor(Math.random()*tdNum*tdNum)+1; //ajralib turgan rang katakdagi nomeri
let rKod=Math.floor(Math.random() * 256); //Qizil
let gKod=Math.floor(Math.random() * 256); //Yashil
let bKod=Math.floor(Math.random() * 256); //Ko'k
var uzgarishNum=15; //RGB Ranglar o'zgarish soni
var realRanglar= {
"newR":nolquy(rKod.toString(16)), //16 lik
"newG":nolquy(gKod.toString(16)), //16 lik
"newB":nolquy(bKod.toString(16)), //16 lik
}
var uzgarish={
"uzgarR": uzgarishNum, //20
"uzgarG": uzgarishNum, //20
"uzgarB": uzgarishNum, //20
}
uzgarish["uzgarR"]=minusUzgar(uzgarish["uzgarR"], rKod); //Manfiy chiqmasligi yoki 255 dan oshib ketmasligi uchun
uzgarish["uzgarG"]=minusUzgar(uzgarish["uzgarG"], gKod);
uzgarish["uzgarB"]=minusUzgar(uzgarish["uzgarB"], bKod);
var fakeRanglar= {
"newR":nolquy((rKod-uzgarish["uzgarR"]).toString(16)),
"newG":nolquy((gKod-uzgarish["uzgarG"]).toString(16)),
"newB":nolquy((bKod-uzgarish["uzgarB"]).toString(16)),
}
var colorReal="#"+realRanglar["newR"]+realRanglar["newG"]+realRanglar["newB"]; //Asl Ranglar
var colorFake="#"+fakeRanglar["newR"]+fakeRanglar["newG"]+fakeRanglar["newB"]; //Soxta Rang
//Asosiy O'yin
let autoFill=""; //Jadvalni Avtomatik ranglash
let gameZone=document.getElementById("gameZone"); //Jadval Id si
var sana=0; //Kataklarga raqam ID berish uchun
for(let tr=0; tr | autoFill+=" "; //qator qo'shish
for(let td=0; td sana++;
//agar soxta rang bo'lmasa
if (sana!=muljal) {
autoFill+="";
}
// soxta rang bo'lsa
else {
autoFill+=" | ";
}
}
gameZone.innerHTML=autoFill; //Avtomatik shakllandi
if (score==1) {
document.getElementById("attention").innerHTML="";
document.getElementById("attention").style.display="none";
}
//////////// Vaqt ////////////
var vaqt = document.getElementById("vaqt");
var tuxta=setInterval(vaqtKet, 120); //Necha sekund kutish
function vaqtKet() {
//Agar vaqt nol bo'lsa
if(win){
win=false;
vaqtEni=vaqtEniGlobgal;
}
if (vaqtEni <= 0) {
isLose=true;
clearInterval(tuxta);
refresh.style.visibility="visible";
document.getElementById("score").className = "lose";
if (score>prise && alertMsg) {
alert("Tabriklaymiz, sizning ochkoingiz "+prise+" ochkodan oshdi. Yozib oling kod: \n"+kod);
alertMsg=false;
}
}
else {
vaqtEni-=0.4;
vaqt.style.width = vaqtEni + 'px';
}
}
}
}
}
//16 likdagi 0 larni to'ldirish
function nolquy(rangKod){
if(!isLose){
if (rangKod.length==1) {
rangKod="0"+rangKod;
}
return rangKod;
}
}
//Soxta rangning RGB kodi manfiy bulmasligi uchun
function minusUzgar(uzgar,kod) {
if(!isLose){
if (kod uzgar=-uzgar;
}
else if (kod+uzgar>255 || kod-uzgar>255){
uzgar=Math.abs(uzgar);
}
else if (Math.floor(Math.random()*2)==1) {
uzgar=-uzgar;
}
return uzgar;
}
}
//////////////////////////////////////////////////////////////
/// Bosilgan rang soxta yoki soxta emasligi va Ochko olish ///
//////////////////////////////////////////////////////////////
function isWin(id, muljal) {
//id Nechinchi pozitsiyadagi rangligi
if(id==muljal){
if(!isLose){
score++;
scoreGame.innerHTML=score;
win=true;
GameStart();
}
}
else {
isLose=true; //Yutquzganini tekshirish
refresh.style.visibility="visible";
document.getElementById("score").className = "lose";
vaqtEni=0;
vaqt.style.width = vaqtEni + 'px';
alert("Afsus, Soxta rangni topa olmadingiz :(\nSiz to'plagan ochko: "+score);
if (score>prise) {
alert("Tabriklaymiz, sizning ochkoingiz "+prise+" ochkodan oshdi. Yozib oling kod: \n"+kod);
}
}
}
|
Do'stlaringiz bilan baham: |