const Dage = document.querySelector('#ageN'); const Aimg = document.querySelector('#anim') const NameC = document.querySelector('#nameCa') const Djoy = document.querySelector('#joyN'); const Dfood = document.querySelector('#fooN'); const Dclean = document.querySelector('#cleN'); const Dhealth = document.querySelector('#heaN'); const imgTiger = { Normal: { tiger: [ './img/tiger/baby.png', './img/tiger/teen.png', './img/tiger/adult.png', './img/tiger/senior.png' ] }, ////Spring: {}, ////Summer: {}, ////Fall: {}, ////Winter: {}, Dead: './img/dead/tiger.png', Gone: './img/gone/tiger.png' } let attributes = { Name: [], Joy: { value: 10, max: 306, min: -100, abszero: 3.06, }, Hunger: { value: 30, max: 100, min: 0, }, Clean: { value: 50.6, max: 253, min: 0, }, Hp: { value: 100, max: 100, min: 0, }, Age: { value: 0, max: 100, min: 0, }, /*Joy: { value: 10, max: 100, min: -100, }*/ Life: { dead: 0, away: 0, } } window.addEventListener('load',() => { display(); time(); }); function toCPercen(varr){//todo num => % let num = Math.floor((varr.value/(varr.max/100))*10)/10; if(num>100) num = 100; if(num=80){ return `

${num}%

`; }else if(num>=60){ return `

${num}%

`; }else if(num>=40){ return `

${num}%

`; }else if(num>=20){ return `

${num}%

`; }else if(num>=0){ return `

${num}%

`; }else if(num<0){ return `

${num}%

`; } } function display(){ Dage.innerHTML = (attributes.Age.value); Djoy.innerHTML = toCPercen(attributes.Joy); Dfood.innerHTML = toCPercen(attributes.Hunger); Dclean.innerHTML = toCPercen(attributes.Clean); Dhealth.innerHTML = toCPercen(attributes.Hp); if(attributes.Age.value<=6){ NameC.innerHTML = `Junior`; Aimg.src = imgTiger.Normal.tiger[0]; }else if(attributes.Age.value<18){ NameC.innerHTML = `Teen`; Aimg.src = imgTiger.Normal.tiger[1]; }else if(attributes.Age.value<60){ NameC.innerHTML = `Adult`; Aimg.src = imgTiger.Normal.tiger[2]; }else if(attributes.Age.value<100){ NameC.innerHTML = `Senior`; Aimg.src = imgTiger.Normal.tiger[3]; }else{ NameC.innerHTML = `Dead`; attributes.Life.dead = 1; btnHide(); Aimg.src = imgTiger.Dead; } if(attributes.Hp.value<=0){ NameC.innerHTML = `Dead`; attributes.Life.dead = 1; btnHide(); Aimg.src = imgTiger.Dead; } if(attributes.Life.away){ NameC.innerHTML = `Gone`; btnHide(); Aimg.src = imgTiger.Gone; } } function play(){ if(attributes.Joy.value(attributes.Hunger.max/100)*80 && attributes.Joy.value>(attributes.Joy.max/100)*80 && attributes.Clean.value>(attributes.Clean.max/100)*90 && attributes.Hp.value < attributes.Hp.max){ attributes.Hp.value += 0.1; } } function btnHide(){ const actBTN = document.querySelectorAll('.actBTN'); actBTN.forEach((e) => { e.style.display='none'; }); } function sadDetection(){ if((attributes.Joy.value <= attributes.Joy.abszero)&&(attributes.Joy.value<0)){ if(Math.abs(attributes.Joy.value) >= Math.floor(Math.random()*100)){ attributes.Life.away = 1; } } } function addStuff(){ if(!attributes.Life.away && !attributes.Life.dead){ if(attributes.Hunger.value>0) attributes.Hunger.value -= 3; if(attributes.Clean.value>0) attributes.Clean.value--; if(attributes.Joy.value>-100) attributes.Joy.value--; if(attributes.Hp.value>0) attributes.Age.value = (attributes.Age.value*10 + 1)/10; if((attributes.Hunger.value<=0)&&(attributes.Hp.value!=0)) attributes.Hp.value -= 2 } } function time(){ setTimeout (() => { addStuff(); hapiHeal(); sadDetection(); display(); time(); },1000); }