-
Notifications
You must be signed in to change notification settings - Fork 0
/
RollerMain.html
153 lines (145 loc) · 5.76 KB
/
RollerMain.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<title>App for rolling dice in ShadowRun</title>
<meta content="width=device-width, initial-scale=1" name="viewport">
<link href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css"
rel="stylesheet" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"></script>
</head>
<body>
<div id="mainPage" data-role="page"
style="margin:0 auto; margin-left:auto; margin-right:auto; align:center; text-align:center;">
<div id="content" data-role="content">
<div class="ui-grid-d">
<div class="ui-block-a">
</div>
<div class="ui-block-b">
<label for="basic"># hits</label>
<input id="hitCount" name="name" type="text" value="" />
<br>
<label for="basic"># 1s</label>
<input id="oneCount" name="name" type="text" value="" />
</div>
<div class="ui-block-c">
</div>
<div class="ui-block-d">
<label for="basic">ttl hits</label>
<input id="hitTotal" name="name" type="text" value="" />
<br>
<label for="basic">ttl rolls</label>
<input id="rollCount" name="name" type="text" value="" />
</div>
<div class="ui-block-e">
</div>
</div>
<!-- /grid-a -->
<br>
<input id="slider-0" data-mini="true" data-theme="a"
data-track-theme="b" max="40" min="1" name="slider"
type="range" value="1" />
<label for="slider-0">Number of Dice to Roll</label>
<br>
<input id="diceResults" data-mini="true" data-theme="a"
data-track-theme="b" name="name" type="text" value="" />
<label for="diceResults">Dice Roll Results</label>
<br>
<div class="ui-grid-b">
<div class="ui-block-a">
<a id="rollButton" data-inline="true" data-role="button"
data-theme="b" href="#">Roll Dice</a>
<br>
<label for="flip6">exploding 6s</label>
<select id="flip6" data-role="slider" data-theme="a"
name="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<div class="ui-block-b">
</div>
<div class="ui-block-c">
<a id="clearButton" data-inline="true" data-role="button"
href="#">Clear</a>
<br>
<label for="flipX">ext. test</label>
<select id="flipX" data-role="slider" data-theme="a"
name="slider">
<option value="off">Off</option>
<option value="on">On</option>
</select>
</div>
<br>
</div>
<!-- /grid-c -->
</div>
<!-- /content -->
</div>
<!-- /page -->
</body>
</html>
<script>
//global variables
var hTotal = 0,
rTotal = 0,
allRolls=[];
// $('#slider-0').bind( "keypress", function(e){ //nothing seemed to work to add events to the slider
$(document).keypress(function(e) {
if(e.which == 13 ) {rollDice()};
})
$('#clearButton').click(function () {
clear();
$('select').val('off').slider('refresh');
})
function clear() {
$('input').val('');
$('#slider-0').val($('#slider-0').attr('min')).slider('enable');
hTotal = 0;
rTotal = 0;
allRolls.length = 0;
}
$('#rollButton').click(function(){
rollDice();
})
function rollDice(){
rTotal++;
var inDice=$('#slider-0').val(),
i=0,
sixes=0,
rolls=[];
while (i<inDice){
rolls[i]=1 + Math.floor(Math.random() * 6)
if(rolls[i]==6) {sixes++}; //6
i++;
}
if ($('#flip6').val()=='on') {allRolls=allRolls.concat(rolls)} else {allRolls=rolls};
i=0;
var outDice = '',
hits = 0,
ones = 0;
for (i=0; i < allRolls.length; i++) {
if (allRolls[i]==6 || allRolls[i]==5) {hits++};
if (allRolls[i]==1) {ones++};
}
outDice = allRolls.join(',');
if ($('#flipX').val()=='on') {hTotal=hTotal+hits};
$('#diceResults').val(outDice);
$('#hitCount').val(hits);
$('#oneCount').val(ones);
$('#rollCount').val(rTotal);
if ($('#flipX').val()=='on') {$('#hitTotal').val(hTotal)};
if ($('#flip6').val()=='on' && sixes>0 ) {$('#slider-0').val(sixes).slider('disable')}; //6
if ($('#flip6').val()=='on' && sixes==0 ) {$('#slider-0').val(0).slider('disable')};
}
$('#flip6').bind( "change", function () {
if($('#flip6').val()=='on')
$('#flipX').val('off').slider('refresh');
clear();
})
$('#flipX').bind( "change", function () {
if($('#flipX').val()=='on')
$('#flip6').val('off').slider('refresh');
clear();
})
</script>