有一个像素字段和一个用于选择改变颜色的像素的代码:
$(".pixel").click(function() {
$(this).toggleClass("white");
$(this).toggleClass("black");
})
var delta;
var isCall = false;
if (!isCall) {
var zoom = 1;
isCall = true;
}
#art {
width: 101px;
height: 101px;
display: table;
border-spacing: 1px;
background-color: #d8d8d8;
}
.row {
display: table-row;
}
.pixel {
display: table-cell;
}
.black {
background-color: black;
}
.white {
background-color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="art">
<div class="row">
<div class="pixel white" id="1-1"></div>
<div class="pixel white" id="1-2"></div>
<div class="pixel white" id="1-3"></div>
<div class="pixel white" id="1-4"></div>
<div class="pixel white" id="1-5"></div>
</div>
<div class="row">
<div class="pixel white" id="2-1"></div>
<div class="pixel white" id="2-2"></div>
<div class="pixel white" id="2-3"></div>
<div class="pixel white" id="2-4"></div>
<div class="pixel white" id="2-5"></div>
</div>
<div class="row">
<div class="pixel white" id="3-1"></div>
<div class="pixel white" id="3-2"></div>
<div class="pixel white" id="3-3"></div>
<div class="pixel white" id="3-4"></div>
<div class="pixel white" id="3-5"></div>
</div>
<div class="row">
<div class="pixel white" id="4-1"></div>
<div class="pixel white" id="4-2"></div>
<div class="pixel white" id="4-3"></div>
<div class="pixel white" id="4-4"></div>
<div class="pixel white" id="4-5"></div>
</div>
<div class="row">
<div class="pixel white" id="5-1"></div>
<div class="pixel white" id="5-2"></div>
<div class="pixel white" id="5-3"></div>
<div class="pixel white" id="5-4"></div>
<div class="pixel white" id="5-5"></div>
</div>
</div>
但是需要自动填充整个字段,假设我单击某个单元格,随机相邻的单元格会稍微延迟填充(就像多米诺骨牌向各个方向倒下)等等,直到整个字段都被填充。这甚至可以实施吗?我被暗示在KAMI游戏中有类似的算法,但我还没有弄清楚如何做到这一点,所以我希望你的建议。
1 个回答