我正在制作一个 Javascript 游戏,其中一个序列显示在一个网格上(8 个动作,网格总共有 12 个按钮)。用户必须重复该序列,最后我想比较两个序列并给出分数。目前我可以检测到哪个按钮被按下,但我不知道还能做什么
PS:我想要实现的是将用户的选择保存在一个数组中,然后如果选择正确,则与“控制数组”进行比较,给出一个分数。
<!-- Game -->
<div data-role="page" id="page2">
<div id="header" data-theme="a" data-role="header">
<a id="back" data-role="button" data-transition="flip" href="#page1" data-icon="back" data-iconpos="left" class="ui-btn-left">
Back
</a>
<a data-role="button" href="#page1" data-icon="star" data-iconpos="left" class="ui-btn-right">
Score
</a>
<h3 id="title">
Salsa-App
</h3>
</div>
<div data-role="content">
<div id="grid" class="ui-grid-c">
<div class="ui-block-a">
<a id="a1" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
A1
</a>
</div>
<div class="ui-block-b">
<a id="a2" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
A2
</a>
</div>
<div class="ui-block-c">
<a id="a3" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
A3
</a>
</div>
<div class="ui-block-d">
<a id="a4" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
A4
</a>
</div>
<div class="ui-block-a">
<a id="b1" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
B1
</a>
</div>
<div class="ui-block-b">
<a id="b2" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
B2
</a>
</div>
<div class="ui-block-c">
<a id="b3" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
B3
</a>
</div>
<div class="ui-block-d">
<a id="b4" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
B4
</a>
</div>
<div class="ui-block-a">
<a id="c1" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
C1
</a>
</div>
<div class="ui-block-b">
<a id="c2" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
C2
</a>
</div>
<div class="ui-block-c">
<a id="c3" data-role="button" data-transition="flow" href="#page1" data-icon="star" data-iconpos="bottom">
C3
</a>
</div>
<div class="ui-block-d">
<a id="c4" data-role="button" href="#page1" data-icon="star" data-iconpos="bottom">
C4
</a>
</div>
</div>
</div>
</div>
<script>
//App custom javascript
$(document).ready(function() {
$('a[data-role="button"]').click(function(){
var whichButton;
whichButton = $(this).attr("id");
alert(whichButton);
});
});
</script>