I'm trying to make a simple game where
you start with 9 circles
when you click on a circle with a thicker border it's going to increment a score and cause new circles to be drawn randomly.
I've already worked on counting stuff but I have a problem, because wherever you click (I mean whatever div) it sums up points. I don't have an idea about how to deactivate div's which do not have a thicker border.
Please tell if this is a good programming approach.
HTML
<body>
<div class="container-fluid">
<div class="row">
<div class="col-md-2">
<h1> Wyniki </h1>
<p> Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet. </p>
</div>
<div class="col-md-8">
<h1> Gra </h1>
<div class="wynik">
<h2> Rezultat </h2>
<p id="zliczenie"> </p>
</div>
<div class="points"> </div>
</div>
<div class="col-md-2">
<h1> Profil </h1>
<p> Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet.Lorem ipsum dolor sit amet. </p>
</div>
</div>
</div>
</body>
CSS
body {
background-color: #ecf0f1;
margin : 2% 2%;
}
.wynik{
border : solid 1px blue;
}
.point {
width : 100px;
height : 100px;
border : solid 1px #000;
border-radius : 100%;
text-align : center;
cursor : pointer;
float : left;
margin : 20px;
}
.point:hover {
color : red;
border-radius : 0%;
}
.points{
width : calc(140px * 3);
margin : 5px auto;
}
JS
window.onload = start;
function start()
{
var div_value = "";
for (i = 0; i < 9; i++)
{
var element = "div_number" + i;
div_value = div_value + '<div class="point" id="'+element+'" onclick="c('+i+')"> Klik </div>';
if((i+1)%3 == 0)
{
div_value = div_value + '<div style="clear:both;"> </div>';
}
}
document.getElementsByClassName("points")[0].innerHTML = div_value;
esthetic();
random_show();
}
// IT SHOWS 1 RANDOM DIV TO START THE GAME
function random_show() {
var a = Math.floor((Math.random() * 8));
var x = document.getElementById("div_number" + a).style.border="10px dotted";
}
var liczby = [];
// IT DROWN LOTS AND COUNT THE SCORE
function c(i)
{
var a = Math.floor((Math.random() * 8));
this.i = a;
var z = document.getElementById("div_number" + i);
var y = document.getElementById("div_number" + a);
if(y.style.border = "10px dotted") {
z.style.border ="5px dotted";
liczby.push(i);
} else {
y.style.border="8px solid";
}
var x = document.getElementById("zliczenie").innerHTML = liczby.length;
}
// IT GIVES EVERY DIV INITIAL style.border
function esthetic()
{
var x = document.getElementsByClassName("point");
for (i = 0; i < 9; i++)
{
x[i].style.border = "5px dotted";
}
}
Thanks a lot for any hints one more time!