mirror of
https://github.com/Febbweiss/js-yahtzee.git
synced 2026-03-04 22:25:40 +00:00
100
css/yahtzee.css
100
css/yahtzee.css
@@ -1,3 +1,9 @@
|
|||||||
|
* {
|
||||||
|
font-family: helvetica, sans-serif;
|
||||||
|
font-weight: 300;
|
||||||
|
font-size: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.possibility {
|
.possibility {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,23 +49,111 @@
|
|||||||
|
|
||||||
.keep {
|
.keep {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
||||||
.trash {
|
.trash {
|
||||||
visibility: hidden;
|
visibility: hidden;
|
||||||
|
color: #ba2323;
|
||||||
}
|
}
|
||||||
|
|
||||||
.score {
|
.score {
|
||||||
font-family: "Zeyada", verdana, arial, helvetica, cursive;
|
font-family: "Zeyada", verdana, arial, helvetica, cursive;
|
||||||
color: blue;
|
color: black;
|
||||||
font-size: 2em;
|
font-size: 2em;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
.score.trashed {
|
.score.trashed {
|
||||||
color: red;
|
color: #ba2323;
|
||||||
}
|
}
|
||||||
|
|
||||||
.progress {
|
.progress {
|
||||||
margin-bottom: 0;
|
height: 20px;
|
||||||
|
background-color: white;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
dt, th {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
#banner {
|
||||||
|
text-align: center;
|
||||||
|
width: 100%;
|
||||||
|
padding: 15px;
|
||||||
|
background-color: white;
|
||||||
|
margin-top: 0px;
|
||||||
|
margin-left: 0px;
|
||||||
|
margin-bottom: 15px;
|
||||||
|
box-shadow: 0px 0px 5px black;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
color: black;
|
||||||
|
font-family: 'Fredericka the Great', helvetica, sans-serif;
|
||||||
|
font-size: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
td, th {
|
||||||
|
padding: 10px;
|
||||||
|
width: 20%;
|
||||||
|
height: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
dd {
|
||||||
|
margin-left: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#scorePanel {
|
||||||
|
border: 1px solid black;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
table {
|
||||||
|
border: 1px solid black;
|
||||||
|
table-layout: fixed;
|
||||||
|
width: 90%;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn a{
|
||||||
|
height: 30px;
|
||||||
|
width: 60px;
|
||||||
|
background-color: #ba2323;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#btn a:hover{
|
||||||
|
background-color: #fcb51b;
|
||||||
|
text-decoration: none;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
background-color: #215fc4;
|
||||||
|
}
|
||||||
|
|
||||||
|
.container {
|
||||||
|
background-color: white;
|
||||||
|
padding: 40px;
|
||||||
|
box-shadow: 0px 0px 5px black;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
min-width: 95%;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
th {
|
||||||
|
background-color: #fcb51b;
|
||||||
|
}
|
||||||
|
|
||||||
|
#upperScore, #lowerScore, #bonus, #totalScore {
|
||||||
|
font-family: "Zeyada", verdana, arial, helvetica, cursive;
|
||||||
|
color: black;
|
||||||
|
font-size: 2em;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|||||||
213
index.html
213
index.html
@@ -1,3 +1,4 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
<!--
|
<!--
|
||||||
Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
Copyright (c) 2013 Fabrice ECAILLE aka Febbweiss
|
||||||
|
|
||||||
@@ -7,7 +8,7 @@ The above copyright notice and this permission notice shall be included in all c
|
|||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
-->
|
-->
|
||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
@@ -21,79 +22,66 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<![endif]-->
|
<![endif]-->
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
|
||||||
<link href='http://fonts.googleapis.com/css?family=Zeyada' rel='stylesheet' type='text/css'>
|
<link href='http://fonts.googleapis.com/css?family=Zeyada' rel='stylesheet' type='text/css'>
|
||||||
|
<link href="https://fonts.googleapis.com/css?family=Fredericka+the+Great" rel="stylesheet">
|
||||||
<script src="lib/jquery-1.7.1.min.js" type="text/javascript" ></script>
|
<script src="lib/jquery-1.7.1.min.js" type="text/javascript" ></script>
|
||||||
|
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.bundle.min.js">
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
<link href="css/yahtzee.css" type="text/css" rel="stylesheet" media="screen, projection" />
|
<link href="css/yahtzee.css" type="text/css" rel="stylesheet" media="screen, projection" />
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div style="width: 50%;float: left;">
|
<div id="banner"class="col-xs-12">
|
||||||
<div class="dice empty" id="dice1"></div>
|
<h1>FEBBWEISS' YAHTZEE!</h1>
|
||||||
<div class="dice empty" id="dice2"></div>
|
|
||||||
<div class="dice empty" id="dice3"></div>
|
|
||||||
<div class="dice empty" id="dice4"></div>
|
|
||||||
<div class="dice empty" id="dice5"></div>
|
|
||||||
<div class="dice empty" id="dice6"></div>
|
|
||||||
<div class="clear"></div>
|
|
||||||
<div>
|
|
||||||
<span>Launch</span>
|
|
||||||
<span id="launch"></span>
|
|
||||||
</div>
|
</div>
|
||||||
<a href="javascript:void(0)" id="launchBtn">Launch</a>
|
<div class="container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-xs-12 col-xl-4">
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<dl>
|
<dl><br>
|
||||||
<dt>Three of a kind</dt>
|
<dt>Three of a kind</dt>
|
||||||
<dd>Three dice showing the same face</dd>
|
<dd>Three dice showing the same face (Ex. Three 3's)</dd>
|
||||||
<dd>Sum of all dice</dd>
|
<dd>Scoring: Sum of all dice</dd>
|
||||||
|
<br>
|
||||||
<dt>Four of a kind</dt>
|
<dt>Four of a kind</dt>
|
||||||
<dd>Four dice showing the same face</dd>
|
<dd>Four dice showing the same face (Ex. Four 5's)</dd>
|
||||||
<dd>Sum of all dice</dd>
|
<dd>Scoring: Sum of all dice</dd>
|
||||||
<dt>Full</dt>
|
<br>
|
||||||
<dd>A three-of-a-kind and a pair</dd>
|
<dt>Full House</dt>
|
||||||
<dd>25 points</dd>
|
<dd>A three-of-a-kind and a pair (Ex. Three 1's and Two 4's)</dd>
|
||||||
|
<dd>Scoring: 25 points</dd>
|
||||||
|
<br>
|
||||||
<dt>Small straight</dt>
|
<dt>Small straight</dt>
|
||||||
<dd>Four sequential dice</dd>
|
<dd>Four sequential dice (Ex. 2, 3, 4, 5)</dd>
|
||||||
<dd>30 points</dd>
|
<dd>Scoring: 30 points</dd>
|
||||||
|
<br>
|
||||||
<dt>Large straight</dt>
|
<dt>Large straight</dt>
|
||||||
<dd>Five sequential dice</dd>
|
<dd>Five sequential dice (Ex. 2, 3, 4, 5, 6)</dd>
|
||||||
<dd>40 points</dd>
|
<dd>Scoring: 40 points</dd>
|
||||||
|
<br>
|
||||||
<dt>Yahtzee</dt>
|
<dt>Yahtzee</dt>
|
||||||
<dd>Five dice showing the same face</dd>
|
<dd>Five dice showing the same face (Ex. Five 4's)</dd>
|
||||||
<dd>50 points</dd>
|
<dd>Scoring: 50 points</dd>
|
||||||
|
<br>
|
||||||
<dt>Chance</dt>
|
<dt>Chance</dt>
|
||||||
<dd>Sum of all dice</dd>
|
<dd>Scoring: Sum of all dice</dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<div id="scorePanel" style="display: none;">
|
|
||||||
<table class="table table-bordered">
|
|
||||||
<tr>
|
|
||||||
<td>Upper grid score</td>
|
|
||||||
<td id="upperScore" style="text-align: center"></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Bonus</td>
|
|
||||||
<td id="bonus" style="text-align: center"></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td>Lower grid score</td>
|
|
||||||
<td id="lowerScore" style="text-align: center"></td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
|
||||||
<td><b>Total</b></td>
|
|
||||||
<td id="totalScore" style="text-align: center"><b></b></td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div style="width: 50%;float: left;">
|
<div class="col-xs-12 col-xl-4">
|
||||||
|
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="text-align: center;">Combinaison</th>
|
<th style="text-align: center;">Combination</th>
|
||||||
<th style="text-align: center;" width="84px">
|
<th style="text-align: center;" width="84px">
|
||||||
Score
|
Score
|
||||||
</th>
|
</th>
|
||||||
<th style="text-align: center;" width="100px"></th>
|
<th style="text-align: center;" width="100px">Options</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -101,7 +89,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="oneLabel">
|
<span id="oneLabel">
|
||||||
One
|
Ones
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -116,7 +104,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="twoLabel">
|
<span id="twoLabel">
|
||||||
Two
|
Twos
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -131,7 +119,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="threeLabel">
|
<span id="threeLabel">
|
||||||
Three
|
Threes
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -146,7 +134,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="fourLabel">
|
<span id="fourLabel">
|
||||||
Four
|
Fours
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -161,7 +149,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="fiveLabel">
|
<span id="fiveLabel">
|
||||||
Five
|
Fives
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -176,7 +164,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="sixLabel">
|
<span id="sixLabel">
|
||||||
Six
|
Sixes
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td style="text-align: center;">
|
<td style="text-align: center;">
|
||||||
@@ -187,19 +175,61 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<a href="javascript:void(0)"id="sixTrash" data-id="six" class="trash">Trash</a>
|
<a href="javascript:void(0)"id="sixTrash" data-id="six" class="trash">Trash</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<span>
|
||||||
|
Upper Score
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
<td style="text-align: center;">
|
||||||
|
<span class="score" id="topScore"></span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
|
||||||
|
<div id="btn">
|
||||||
|
<a href="javascript:void(0)" id="launchBtn">Roll the Dice</a>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
<span>Dice Roll #:</span>
|
||||||
|
<span id="launch"></span>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<div>
|
||||||
|
<div class="dice empty" id="dice1"></div>
|
||||||
|
<div class="dice empty" id="dice2"></div>
|
||||||
|
<div class="dice empty" id="dice3"></div>
|
||||||
|
<div class="dice empty" id="dice4"></div>
|
||||||
|
<div class="dice empty" id="dice5"></div>
|
||||||
|
<div class="dice empty" id="dice6"></div>
|
||||||
|
<div class="clear"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-xs-12 col-xl-4">
|
||||||
<table border="1">
|
<table border="1">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th style="text-align: center;">Combinaison</th>
|
<th style="text-align: center;">Combination</th>
|
||||||
<th style="text-align: center;">Probability</th>
|
<th style="text-align: center;">Probability</th>
|
||||||
<th style="text-align: center;" width="84px">
|
<th style="text-align: center;" width="84px">
|
||||||
Score
|
Score
|
||||||
</th>
|
</th>
|
||||||
<th style="text-align: center;" width="100px"></th>
|
<th style="text-align: center;" width="100px">Options</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@@ -249,7 +279,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="fullLabel">
|
<span id="fullLabel">
|
||||||
Full
|
Full House
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -270,7 +300,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="smallStraightLabel">
|
<span id="smallStraightLabel">
|
||||||
Small straight
|
Small Straight
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -291,7 +321,7 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span id="largeStraightLabel">
|
<span id="largeStraightLabel">
|
||||||
Large straight
|
Large Straight
|
||||||
</span>
|
</span>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -350,38 +380,81 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
|
|||||||
<a href="javascript:void(0)"id="luckTrash" data-id="luck" class="trash">Trash</a>
|
<a href="javascript:void(0)"id="luckTrash" data-id="luck" class="trash">Trash</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<span>
|
||||||
|
Lower Score
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
<td style="text-align: center;">
|
||||||
|
<span id="bottomScore" class="score"></span>
|
||||||
|
</td>
|
||||||
|
|
||||||
|
</tr>
|
||||||
|
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
<br>
|
||||||
|
<div id="scorePanel" style="display: none;">
|
||||||
|
<table class="table table-bordered">
|
||||||
|
<tr>
|
||||||
|
<th>Final Score</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Upper grid score</td>
|
||||||
|
<td id="upperScore" style="text-align: center"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Bonus</td>
|
||||||
|
<td id="bonus" style="text-align: center"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Lower grid score</td>
|
||||||
|
<td id="lowerScore" style="text-align: center"></td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><b>Total</b></td>
|
||||||
|
<td id="totalScore" style="text-align: center"><b></b></td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div> <!-- End of span9 -->
|
|
||||||
|
|
||||||
<script src="js/yahtzee.js" type="text/javascript" ></script>
|
<script src="js/yahtzee.js" type="text/javascript" ></script>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function () {
|
$(document).ready(function ()
|
||||||
$(".dice").click(function(evt) {
|
{
|
||||||
|
$(".dice").click(function(evt)
|
||||||
|
{
|
||||||
if( $(this).hasClass("selected") )
|
if( $(this).hasClass("selected") )
|
||||||
$(this).removeClass("selected");
|
$(this).removeClass("selected");
|
||||||
else
|
else
|
||||||
$(this).addClass("selected");
|
$(this).addClass("selected");
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".keep").click(function(evt) {
|
$(".keep").click(function(evt)
|
||||||
|
{
|
||||||
console.log("Keeping " + $(this).attr('data-id'));
|
console.log("Keeping " + $(this).attr('data-id'));
|
||||||
Yahtzee.keep($(this).attr('data-id'));
|
Yahtzee.keep($(this).attr('data-id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".trash").click(function(evt) {
|
$(".trash").click(function(evt)
|
||||||
|
{
|
||||||
console.log("Trashing " + $(this).attr('data-id'));
|
console.log("Trashing " + $(this).attr('data-id'));
|
||||||
Yahtzee.trash($(this).attr('data-id'));
|
Yahtzee.trash($(this).attr('data-id'));
|
||||||
});
|
});
|
||||||
|
|
||||||
$("#launchBtn").click(function() {
|
$("#launchBtn").click(function()
|
||||||
|
{
|
||||||
Yahtzee.shuffle();
|
Yahtzee.shuffle();
|
||||||
Yahtzee.findCombinaisons();
|
Yahtzee.findCombinations();
|
||||||
if( Yahtzee.launch < 3 )
|
if( Yahtzee.launch < 3 )
|
||||||
Yahtzee.findPossibilities();
|
Yahtzee.findPossibilities();
|
||||||
});
|
});
|
||||||
|
|||||||
255
js/yahtzee.js
255
js/yahtzee.js
@@ -18,11 +18,15 @@ var INCOMPLETE_STRAIGHT_MASK2 = (1 << 1) + (1 << 2) + (1 << 3);
|
|||||||
var INCOMPLETE_STRAIGHT_MASK3 = (1 << 2) + (1 << 3) + (1 << 4);
|
var INCOMPLETE_STRAIGHT_MASK3 = (1 << 2) + (1 << 3) + (1 << 4);
|
||||||
var INCOMPLETE_STRAIGHT_MASK4 = (1 << 3) + (1 << 4) + (1 << 5);
|
var INCOMPLETE_STRAIGHT_MASK4 = (1 << 3) + (1 << 4) + (1 << 5);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Create the Yahtzee object
|
||||||
|
*/
|
||||||
Yahtzee = {
|
Yahtzee = {
|
||||||
|
|
||||||
launch : 0,
|
launch : 0,
|
||||||
dices : [],
|
dices : [],
|
||||||
combinaisons : [],
|
Combinations : [],
|
||||||
pair : false,
|
pair : false,
|
||||||
doublePair : false,
|
doublePair : false,
|
||||||
three_of_a_kind : false,
|
three_of_a_kind : false,
|
||||||
@@ -35,9 +39,13 @@ Yahtzee = {
|
|||||||
|
|
||||||
scoreUp : 0,
|
scoreUp : 0,
|
||||||
scoreDown: 0,
|
scoreDown: 0,
|
||||||
keptCombinaisons: [],
|
keptCombinations: [],
|
||||||
|
|
||||||
clear: function(all) {
|
/*
|
||||||
|
* Reset all values to defaults
|
||||||
|
*/
|
||||||
|
clear: function(all)
|
||||||
|
{
|
||||||
if( all )
|
if( all )
|
||||||
Yahtzee.launch = 0;
|
Yahtzee.launch = 0;
|
||||||
|
|
||||||
@@ -52,42 +60,60 @@ Yahtzee = {
|
|||||||
Yahtzee.straight = 0;
|
Yahtzee.straight = 0;
|
||||||
|
|
||||||
if( all )
|
if( all )
|
||||||
for( var i = 0; i < 5; i++ ) {
|
for( var i = 0; i < 5; i++ )
|
||||||
|
{
|
||||||
Yahtzee.dices[i] = 0;
|
Yahtzee.dices[i] = 0;
|
||||||
$("#dice" + (i+1)).removeClass().addClass("dice").addClass("empty");
|
$("#dice" + (i+1)).removeClass().addClass("dice").addClass("empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
for( var i = 0; i < 6; i++ ) {
|
for( var i = 0; i < 6; i++ )
|
||||||
Yahtzee.combinaisons[i] = 0;
|
{
|
||||||
|
Yahtzee.Combinations[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".possibility").each(function(incr, elt) {
|
$(".possibility").each(function(incr, elt)
|
||||||
|
{
|
||||||
$(elt).removeClass("possibility");
|
$(elt).removeClass("possibility");
|
||||||
$(elt).empty();
|
$(elt).empty();
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".keep").each(function(incr, elt) {
|
$(".keep").each(function(incr, elt)
|
||||||
|
{
|
||||||
$(elt).attr('style', 'visibility:hidden;');
|
$(elt).attr('style', 'visibility:hidden;');
|
||||||
})
|
});
|
||||||
$(".trash").each(function(incr, elt) {
|
|
||||||
|
$(".trash").each(function(incr, elt)
|
||||||
|
{
|
||||||
$(elt).attr('style', 'visibility:hidden;');
|
$(elt).attr('style', 'visibility:hidden;');
|
||||||
})
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
shuffle: function() {
|
/*
|
||||||
|
* Provide random dice rolls
|
||||||
|
*/
|
||||||
|
shuffle: function()
|
||||||
|
{
|
||||||
if($("#launchBtn").hasClass("disabled") )
|
if($("#launchBtn").hasClass("disabled") )
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if( Yahtzee.launch == 3 )
|
if( Yahtzee.launch == 3 )
|
||||||
|
{
|
||||||
Yahtzee.clear(true);
|
Yahtzee.clear(true);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Yahtzee.clear(false);
|
Yahtzee.clear(false);
|
||||||
|
}
|
||||||
|
|
||||||
Yahtzee.launch++;
|
Yahtzee.launch++;
|
||||||
|
|
||||||
for( var i = 0; i < 5; i++ ) {
|
for( var i = 0; i < 5; i++ )
|
||||||
|
{
|
||||||
var html = $("#dice" + (i+1));
|
var html = $("#dice" + (i+1));
|
||||||
if( !html.hasClass("selected") ) {
|
if( !html.hasClass("selected") )
|
||||||
|
{
|
||||||
var value = Math.round(5 * Math.random());
|
var value = Math.round(5 * Math.random());
|
||||||
Yahtzee.dices[i] = value;
|
Yahtzee.dices[i] = value;
|
||||||
html.removeClass().addClass("dice").addClass("face" + (value + 1));
|
html.removeClass().addClass("dice").addClass("face" + (value + 1));
|
||||||
@@ -96,22 +122,37 @@ Yahtzee = {
|
|||||||
|
|
||||||
$("#launch").html(Yahtzee.launch);
|
$("#launch").html(Yahtzee.launch);
|
||||||
if( Yahtzee.launch == 3 )
|
if( Yahtzee.launch == 3 )
|
||||||
|
{
|
||||||
$("#launchBtn").addClass("disabled");
|
$("#launchBtn").addClass("disabled");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
findCombinaisons: function() {
|
|
||||||
for( var i = 0; i < 5; i++) {
|
/*
|
||||||
Yahtzee.combinaisons[Yahtzee.dices[i]]++;
|
* Find valid score combinations in current dice
|
||||||
|
*/
|
||||||
|
findCombinations: function()
|
||||||
|
{
|
||||||
|
for( var i = 0; i < 5; i++)
|
||||||
|
{
|
||||||
|
Yahtzee.Combinations[Yahtzee.dices[i]]++;
|
||||||
Yahtzee.straight = Yahtzee.straight | (1 << Yahtzee.dices[i]);
|
Yahtzee.straight = Yahtzee.straight | (1 << Yahtzee.dices[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for( var i = 0; i < 6; i++ ) {
|
for( var i = 0; i < 6; i++ )
|
||||||
var value = Yahtzee.combinaisons[i];
|
{
|
||||||
switch( value ) {
|
var value = Yahtzee.Combinations[i];
|
||||||
|
switch( value )
|
||||||
|
{
|
||||||
case 2:
|
case 2:
|
||||||
if( Yahtzee.pair )
|
if( Yahtzee.pair )
|
||||||
|
|
||||||
Yahtzee.doublePair = true;
|
Yahtzee.doublePair = true;
|
||||||
|
|
||||||
Yahtzee.pair = true;
|
Yahtzee.pair = true;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
Yahtzee.yahtzee = true;
|
Yahtzee.yahtzee = true;
|
||||||
@@ -126,57 +167,93 @@ Yahtzee = {
|
|||||||
|
|
||||||
Yahtzee.full = Yahtzee.pair && Yahtzee.three_of_a_kind && !Yahtzee.doublePair;
|
Yahtzee.full = Yahtzee.pair && Yahtzee.three_of_a_kind && !Yahtzee.doublePair;
|
||||||
|
|
||||||
if( (Yahtzee.straight & LARGE_STRAIGHT_MASK1) == LARGE_STRAIGHT_MASK1 ) {
|
if( (Yahtzee.straight & LARGE_STRAIGHT_MASK1) == LARGE_STRAIGHT_MASK1 )
|
||||||
|
{
|
||||||
Yahtzee.large_straight = true;
|
Yahtzee.large_straight = true;
|
||||||
Yahtzee.small_straight = true;
|
Yahtzee.small_straight = true;
|
||||||
} else if( (Yahtzee.straight & LARGE_STRAIGHT_MASK2) == LARGE_STRAIGHT_MASK2 ) {
|
} else if( (Yahtzee.straight & LARGE_STRAIGHT_MASK2) == LARGE_STRAIGHT_MASK2 )
|
||||||
|
{
|
||||||
Yahtzee.large_straight = true;
|
Yahtzee.large_straight = true;
|
||||||
Yahtzee.small_straight = true;
|
Yahtzee.small_straight = true;
|
||||||
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK1) == SMALL_STRAIGHT_MASK1 ) {
|
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK1) == SMALL_STRAIGHT_MASK1 )
|
||||||
|
{
|
||||||
Yahtzee.small_straight = true;
|
Yahtzee.small_straight = true;
|
||||||
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK2) == SMALL_STRAIGHT_MASK2 ) {
|
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK2) == SMALL_STRAIGHT_MASK2 )
|
||||||
|
{
|
||||||
Yahtzee.small_straight = true;
|
Yahtzee.small_straight = true;
|
||||||
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK3) == SMALL_STRAIGHT_MASK3 ) {
|
} else if( (Yahtzee.straight & SMALL_STRAIGHT_MASK3) == SMALL_STRAIGHT_MASK3 )
|
||||||
|
{
|
||||||
Yahtzee.small_straight = true;
|
Yahtzee.small_straight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( Yahtzee.three_of_a_kind && Yahtzee.keptCombinaisons.indexOf("threeOfAKind") == -1 )
|
if( Yahtzee.three_of_a_kind && Yahtzee.keptCombinations.indexOf("threeOfAKind") == -1 )
|
||||||
|
{
|
||||||
$("#threeOfAKindKeep").attr('style', 'visibility:visible;');
|
$("#threeOfAKindKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.four_of_a_kind && Yahtzee.keptCombinaisons.indexOf("fourOfAKind") == -1 )
|
}
|
||||||
|
if( Yahtzee.four_of_a_kind && Yahtzee.keptCombinations.indexOf("fourOfAKind") == -1 )
|
||||||
|
{
|
||||||
$("#fourOfAKindKeep").attr('style', 'visibility:visible;');
|
$("#fourOfAKindKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.full && Yahtzee.keptCombinaisons.indexOf("full") == -1 )
|
}
|
||||||
|
if( Yahtzee.full && Yahtzee.keptCombinations.indexOf("full") == -1 )
|
||||||
|
{
|
||||||
$("#fullKeep").attr('style', 'visibility:visible;');
|
$("#fullKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.yahtzee && Yahtzee.keptCombinaisons.indexOf("yahtzee") == -1 )
|
}
|
||||||
|
if( Yahtzee.yahtzee && Yahtzee.keptCombinations.indexOf("yahtzee") == -1 )
|
||||||
|
{
|
||||||
$("#yahtzeeKeep").attr('style', 'visibility:visible;');
|
$("#yahtzeeKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.small_straight && Yahtzee.keptCombinaisons.indexOf("smallStraight") == -1 )
|
}
|
||||||
|
if( Yahtzee.small_straight && Yahtzee.keptCombinations.indexOf("smallStraight") == -1 )
|
||||||
|
{
|
||||||
$("#smallStraightKeep").attr('style', 'visibility:visible;');
|
$("#smallStraightKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.large_straight && Yahtzee.keptCombinaisons.indexOf("largeStraight") == -1 )
|
}
|
||||||
|
if( Yahtzee.large_straight && Yahtzee.keptCombinations.indexOf("largeStraight") == -1 )
|
||||||
|
{
|
||||||
$("#largeStraightKeep").attr('style', 'visibility:visible;');
|
$("#largeStraightKeep").attr('style', 'visibility:visible;');
|
||||||
|
}
|
||||||
|
|
||||||
if( Yahtzee.combinaisons[0] > 0 && Yahtzee.keptCombinaisons.indexOf("one") == -1 )
|
if( Yahtzee.Combinations[0] > 0 && Yahtzee.keptCombinations.indexOf("one") == -1 )
|
||||||
|
{
|
||||||
$("#oneKeep").attr('style', 'visibility:visible;');
|
$("#oneKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.combinaisons[1] > 0 && Yahtzee.keptCombinaisons.indexOf("two") == -1 )
|
}
|
||||||
|
if( Yahtzee.Combinations[1] > 0 && Yahtzee.keptCombinations.indexOf("two") == -1 )
|
||||||
|
{
|
||||||
$("#twoKeep").attr('style', 'visibility:visible;');
|
$("#twoKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.combinaisons[2] > 0 && Yahtzee.keptCombinaisons.indexOf("three") == -1 )
|
}
|
||||||
|
if( Yahtzee.Combinations[2] > 0 && Yahtzee.keptCombinations.indexOf("three") == -1 )
|
||||||
|
{
|
||||||
$("#threeKeep").attr('style', 'visibility:visible;');
|
$("#threeKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.combinaisons[3] > 0 && Yahtzee.keptCombinaisons.indexOf("four") == -1 )
|
}
|
||||||
|
if( Yahtzee.Combinations[3] > 0 && Yahtzee.keptCombinations.indexOf("four") == -1 )
|
||||||
|
{
|
||||||
$("#fourKeep").attr('style', 'visibility:visible;');
|
$("#fourKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.combinaisons[4] > 0 && Yahtzee.keptCombinaisons.indexOf("five") == -1 )
|
}
|
||||||
|
if( Yahtzee.Combinations[4] > 0 && Yahtzee.keptCombinations.indexOf("five") == -1 )
|
||||||
|
{
|
||||||
$("#fiveKeep").attr('style', 'visibility:visible;');
|
$("#fiveKeep").attr('style', 'visibility:visible;');
|
||||||
if( Yahtzee.combinaisons[5] > 0 && Yahtzee.keptCombinaisons.indexOf("six") == -1 )
|
}
|
||||||
|
if( Yahtzee.Combinations[5] > 0 && Yahtzee.keptCombinations.indexOf("six") == -1 )
|
||||||
|
{
|
||||||
$("#sixKeep").attr('style', 'visibility:visible;');
|
$("#sixKeep").attr('style', 'visibility:visible;');
|
||||||
|
}
|
||||||
|
|
||||||
if( Yahtzee.keptCombinaisons.indexOf("luck") == -1 )
|
if( Yahtzee.keptCombinations.indexOf("luck") == -1 )
|
||||||
|
{
|
||||||
$("#luckKeep").attr('style', 'visibility:visible;');
|
$("#luckKeep").attr('style', 'visibility:visible;');
|
||||||
|
}
|
||||||
|
|
||||||
$(".trash").each(function(incr, elt){
|
$(".trash").each(function(incr, elt)
|
||||||
var html = $(elt)
|
{
|
||||||
if( Yahtzee.keptCombinaisons.indexOf(html.attr('data-id')) == -1 )
|
var html = $(elt);
|
||||||
|
if( Yahtzee.keptCombinations.indexOf(html.attr('data-id')) == -1 )
|
||||||
html.attr('style', 'visibility:visible;');
|
html.attr('style', 'visibility:visible;');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
findPossibilities: function() {
|
/*
|
||||||
|
* Calculate probability of rolling a particular dice combination
|
||||||
|
*/
|
||||||
|
findPossibilities: function()
|
||||||
|
{
|
||||||
var possibilities = {
|
var possibilities = {
|
||||||
"threeOfAKind" : 0,
|
"threeOfAKind" : 0,
|
||||||
"fourOfAKind" : 0,
|
"fourOfAKind" : 0,
|
||||||
@@ -186,12 +263,15 @@ Yahtzee = {
|
|||||||
"largeStraight" : 0
|
"largeStraight" : 0
|
||||||
};
|
};
|
||||||
|
|
||||||
if( Yahtzee.three_of_a_kind && !Yahtzee.full) {
|
if( Yahtzee.three_of_a_kind && !Yahtzee.full)
|
||||||
|
{
|
||||||
possibilities["full"] = Math.max( possibilities["full"], 17 );
|
possibilities["full"] = Math.max( possibilities["full"], 17 );
|
||||||
possibilities["fourOfAKind"] = Math.max( possibilities["fourOfAKind"], 31);
|
possibilities["fourOfAKind"] = Math.max( possibilities["fourOfAKind"], 31);
|
||||||
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 3);
|
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 3);
|
||||||
}
|
}
|
||||||
if( Yahtzee.pair ) {
|
|
||||||
|
if( Yahtzee.pair )
|
||||||
|
{
|
||||||
if( !Yahtzee.three_of_a_kind )
|
if( !Yahtzee.three_of_a_kind )
|
||||||
possibilities["threeOfAKind"] = Math.max( possibilities["threeOfAKind"], 42);
|
possibilities["threeOfAKind"] = Math.max( possibilities["threeOfAKind"], 42);
|
||||||
possibilities["fourOfAKind"] = Math.max( possibilities["fourOfAKind"], 7);
|
possibilities["fourOfAKind"] = Math.max( possibilities["fourOfAKind"], 7);
|
||||||
@@ -199,60 +279,72 @@ Yahtzee = {
|
|||||||
possibilities["full"] = Math.max( possibilities["full"], 10);
|
possibilities["full"] = Math.max( possibilities["full"], 10);
|
||||||
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 7);
|
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 7);
|
||||||
}
|
}
|
||||||
if( Yahtzee.four_of_a_kind ) {
|
|
||||||
|
if( Yahtzee.four_of_a_kind )
|
||||||
|
{
|
||||||
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 17);
|
possibilities["yahtzee"] = Math.max( possibilities["yahtzee"], 17);
|
||||||
}
|
}
|
||||||
if( Yahtzee.doublePair ) {
|
|
||||||
|
if( Yahtzee.doublePair )
|
||||||
|
{
|
||||||
possibilities["full"] = Math.max( possibilities["full"], 33);
|
possibilities["full"] = Math.max( possibilities["full"], 33);
|
||||||
}
|
}
|
||||||
if( !Yahtzee.large_straight &&
|
if( !Yahtzee.large_straight &&
|
||||||
((Yahtzee.straight & SMALL_STRAIGHT_MASK1) == SMALL_STRAIGHT_MASK1 || (Yahtzee.straight & SMALL_STRAIGHT_MASK3) == SMALL_STRAIGHT_MASK3) ) {
|
((Yahtzee.straight & SMALL_STRAIGHT_MASK1) == SMALL_STRAIGHT_MASK1 || (Yahtzee.straight & SMALL_STRAIGHT_MASK3) == SMALL_STRAIGHT_MASK3) )
|
||||||
|
{
|
||||||
possibilities["largeStraight"] = Math.max( possibilities["largeStraight"], 17);
|
possibilities["largeStraight"] = Math.max( possibilities["largeStraight"], 17);
|
||||||
} else if( !Yahtzee.large_straight && (Yahtzee.straight & SMALL_STRAIGHT_MASK2) == SMALL_STRAIGHT_MASK2 ) {
|
} else if( !Yahtzee.large_straight && (Yahtzee.straight & SMALL_STRAIGHT_MASK2) == SMALL_STRAIGHT_MASK2 )
|
||||||
|
{
|
||||||
possibilities["largeStraight"] = Math.max( possibilities["largeStraight"], 33);
|
possibilities["largeStraight"] = Math.max( possibilities["largeStraight"], 33);
|
||||||
}
|
}
|
||||||
|
|
||||||
$.each(possibilities, function(key, value) {
|
$.each(possibilities, function(key, value)
|
||||||
|
{
|
||||||
var html = $("#" + key + "Probability");
|
var html = $("#" + key + "Probability");
|
||||||
html.empty().addClass("possibility");
|
html.empty().addClass("possibility");
|
||||||
if( value > 0 && Yahtzee.keptCombinaisons.indexOf(key) == -1 ) {
|
if( value > 0 && Yahtzee.keptCombinations.indexOf(key) == -1 )
|
||||||
|
{
|
||||||
html.append(value + "%");
|
html.append(value + "%");
|
||||||
} else
|
} else
|
||||||
html.append(" ");
|
html.append(" ");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
keep: function(id) {
|
/*
|
||||||
|
* Process user decision to keep a score value
|
||||||
|
*/
|
||||||
|
keep: function(id)
|
||||||
|
{
|
||||||
var score = 0;
|
var score = 0;
|
||||||
switch(id) {
|
switch(id) {
|
||||||
case "one" :
|
case "one" :
|
||||||
score = Yahtzee.combinaisons[0] * 1;
|
score = Yahtzee.Combinations[0] * 1;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "two" :
|
case "two" :
|
||||||
score = Yahtzee.combinaisons[1] * 2;
|
score = Yahtzee.Combinations[1] * 2;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "three" :
|
case "three" :
|
||||||
score = Yahtzee.combinaisons[2] * 3;
|
score = Yahtzee.Combinations[2] * 3;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "four" :
|
case "four" :
|
||||||
score = Yahtzee.combinaisons[3] * 4;
|
score = Yahtzee.Combinations[3] * 4;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "five" :
|
case "five" :
|
||||||
score = Yahtzee.combinaisons[4] * 5;
|
score = Yahtzee.Combinations[4] * 5;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "six" :
|
case "six" :
|
||||||
score = Yahtzee.combinaisons[5] * 6;
|
score = Yahtzee.Combinations[5] * 6;
|
||||||
Yahtzee.scoreUp += score;
|
Yahtzee.scoreUp += score;
|
||||||
break;
|
break;
|
||||||
case "threeOfAKind" :
|
case "threeOfAKind" :
|
||||||
case "fourOfAKind" :
|
case "fourOfAKind" :
|
||||||
case "luck" :
|
case "luck" :
|
||||||
$.each(Yahtzee.dices, function(index, elt){score += (elt + 1)});
|
$.each(Yahtzee.dices, function(index, elt){score += (elt + 1);});
|
||||||
Yahtzee.scoreDown += score;
|
Yahtzee.scoreDown += score;
|
||||||
break;
|
break;
|
||||||
case "full" :
|
case "full" :
|
||||||
@@ -274,37 +366,60 @@ Yahtzee = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$("#" + id + "Score").html(score);
|
$("#" + id + "Score").html(score);
|
||||||
|
$("#topScore").html(Yahtzee.scoreUp);
|
||||||
Yahtzee.keptCombinaisons.push(id);
|
$("#bottomScore").html(Yahtzee.scoreDown);
|
||||||
|
Yahtzee.keptCombinations.push(id);
|
||||||
Yahtzee.clear(true);
|
Yahtzee.clear(true);
|
||||||
|
|
||||||
if( Yahtzee.keptCombinaisons.length < 13 )
|
if( Yahtzee.keptCombinations.length < 13 )
|
||||||
$("#launchBtn").removeClass("disabled");
|
$("#launchBtn").removeClass("disabled");
|
||||||
else
|
else
|
||||||
Yahtzee.show_game_over();
|
Yahtzee.show_game_over();
|
||||||
},
|
},
|
||||||
|
|
||||||
trash : function(id) {
|
/*
|
||||||
|
* Add a zero to the score value of the selected table row
|
||||||
|
*/
|
||||||
|
trash: function(id)
|
||||||
|
{
|
||||||
$("#" + id + "Score").html(0).addClass('trashed');
|
$("#" + id + "Score").html(0).addClass('trashed');
|
||||||
$("#" + id + "Label").attr('style', 'text-decoration:line-through;');
|
$("#" + id + "Label").attr('style', 'text-decoration:line-through;');
|
||||||
Yahtzee.keptCombinaisons.push(id);
|
Yahtzee.keptCombinations.push(id);
|
||||||
Yahtzee.clear(true);
|
Yahtzee.clear(true);
|
||||||
if( Yahtzee.keptCombinaisons.length < 13 )
|
if( Yahtzee.keptCombinations.length < 13 )
|
||||||
|
{
|
||||||
$("#launchBtn").removeClass("disabled");
|
$("#launchBtn").removeClass("disabled");
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
Yahtzee.show_game_over();
|
Yahtzee.show_game_over();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
show_game_over: function() {
|
/*
|
||||||
|
* Calculate and display the final user score
|
||||||
|
*/
|
||||||
|
show_game_over: function()
|
||||||
|
{
|
||||||
$("#upperScore").append(Yahtzee.scoreUp);
|
$("#upperScore").append(Yahtzee.scoreUp);
|
||||||
if( Yahtzee.scoreUp > 63 ) {
|
if( Yahtzee.scoreUp > 63 )
|
||||||
|
{
|
||||||
$("#bonus").append(35);
|
$("#bonus").append(35);
|
||||||
Yahtzee.scoreUp += 35;
|
Yahtzee.scoreUp += 35;
|
||||||
} else
|
|
||||||
$("#bonus").append(0);
|
|
||||||
$("#lowerScore").append(Yahtzee.scoreDown);
|
$("#lowerScore").append(Yahtzee.scoreDown);
|
||||||
$("#totalScore").append(Yahtzee.scoreDown + Yahtzee.upperScore);
|
$("#totalScore").append(Yahtzee.scoreDown + Yahtzee.scoreUp);
|
||||||
|
|
||||||
$("#scorePanel").show();
|
$("#scorePanel").show();
|
||||||
}
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
$("#bonus").append(0);
|
||||||
|
$("#lowerScore").append(Yahtzee.scoreDown);
|
||||||
|
$("#totalScore").append(Yahtzee.scoreDown + Yahtzee.scoreUp);
|
||||||
|
|
||||||
|
$("#scorePanel").show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user