JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<div class="window-wrapper">
<div class="window-frame">
<div class="window">
<center>
<table cellspacing="0" cellpadding="0" border="0" width="703" height="254">
<tr>
<td valign="middle" align="center" width="20%">
<div class="slot-1" data-value="2"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-2" data-value="2"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-3" data-value="2"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-4" data-value="2"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-5" data-value="2"></div>
</td>
</tr>
<tr class="center">
<td valign="middle" align="center" width="20%">
<div class="slot-5" data-value="4"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-4" data-value="4"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-3" data-value="4"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-2" data-value="4"></div>
</td>
<td valign="middle" align="center" width="20%">
<div class="slot-1" data-value="4"></div>
</td>
</tr>
<tr>
<td valign="middle" align="center" width="20%">
<div class="slot-3" data-value="8"></div>
...
CSS
/*= CORE
========================= */
body{
background-color: #0e0e0e;
font-family: 'Open Sans', sans-serif;
margin: 0;
padding: 0;
font-size: 9pt;
color: #8A8A8A;
}
@font-face{
font-family: 'Open Sans', sans-serif;
src: (http://fonts.googleapis.com/css?family=Open+Sans:400,600,300,700);
}
/*= Content
========================= */
#wrapper{
margin: 0 auto;
width: 903px;
height: 704px;
}
div.content{
background-image: url("./images/bg.png");
background-repeat: no-repeat;
width: 904px;
height: 704px;
margin: 125px 0 0 0;
padding: 30px;
position: relative;
}
div.content > div.stats{
position: absolute;
top: 50px;
left: 55px;
}
div.content > div.stats > div:first-child{
color: #ca660b;
cursor: pointer;
}
div.content > div.stats > div:first-child:hover{
color: #894507;
cursor: pointer;
}
div.window-wrapper{
margin: 0 auto;
margin-top: 10px;
width: calc(100% - 80px);
height: 314px;
}
div.window-frame{
background-image: url("http://i.epvpimg.com/xFG4c.png");
background-repeat: no-repeat;
position: absolute;
z-index: 12;
}
div.window{
background-color: rgba(0, 0, 0, 0.5);
width: 703px;
height: 254px;
overflow: hidden;
margin: 30px;
}
div.window table tr td{
height: 85px;
}
div.window table tr td > div{
opacity: 0.5;
cursor: pointer;
}
div.window table tr.center td > div{
opacity: 1;
}
div.notice{
width: calc(100% - 61px);
text-align: center;
font-family: 'Open Sans', sans-serif;
font-weight: 600;
font-size: 9pt;
margin-top: 25px;
display: none;
}
div.notice.error{
color: #a92828;
}
div.notice.success{
color: #1b7123;
}
div.level{
margin: 25px;
position: absolute;
bottom: 80px;
}
div.stakes{
margin: 25px;
position: absolute;
bottom: 80px;
right: 86px;
}
div.main{
margin: 25px;
position: absolute;
bottom: 80px;
left: 324px;
}
div.total-bet-window{
margin: 25px;
position: absolute;
bottom: 155px;
right: 91px;
}
div.total-bet{
...
JavaScript
/* items to be shuffled in the slots ...*/
var items = ["slot-1", "slot-2", "slot-3", "slot-4", "slot-5"];
/* items pattern/layout that the user should match to win ...*/
var winningItemsPattern = ["slot-1", "slot-2", "slot-2", "slot-1", "slot-1"];
/* const to hold the middle row index of the display ...*/
var MIDDLE_ROW_INDEX = 1;
/* rows */
var $rows = $("div.window table tr");
/* slots */
var $slots = $("div.window table tr td");
/* success/error message .... */
var $notice = $("#notice");
var $noticePattern = $("#notice-pattern");
/* spinner ... */
var $spinner = $(".shoot");
/* performs a virtual spinning by shuffling the items in all the slots.... */
function spin() {
$slots.each(function (idx, elm) {
/* COMMENTED FOR TESTING */
/* $(elm).find('div').attr("class", items[Math.floor(Math.random() * items.length)]); */
$(elm).find('div').attr("class", items[Math.floor(Math.random() * 2)]);
});
}
/* returns the slots values of the middle row, as an array... */
function getSlotValues() {
return $($rows[MIDDLE_ROW_INDEX]).find('td > div').map(function (idx, elm) { return $(elm).attr("class"); });
}
/* checks if selected items are matching the winning pattern ... */
function areItemsMatchingWinningPattern(selectedItems, winningItemsPattern) {
return !!selectedItems && !!winningItemsPattern && (selectedItems.length == winningItemsPattern.length) && selectedItems.every(function (elm, idx) {
return elm === winningItemsPattern[idx];
})
}
/* checks if all selected items are same .... */
function areAllItemsMatching(source) {
return !!source && source.length > 0 && source.every(function (elm, idx, array) {
return idx === 0 || array[idx - 1] == elm;
});
}
$spinner.on('click', function () {
spin();
var values = getSlotValues().toArray();
/* 1. checking if all slots item in the middile row are the SAME */
var result = areAllItemsMatching(values);
$notice.removeClass(result ? "error" : "success").addClass(result ?...