-
Notifications
You must be signed in to change notification settings - Fork 0
/
2player.html
87 lines (66 loc) · 2.44 KB
/
2player.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
<!DOCTYPE html>
<!-- 2 sets of dice -->
<html lang="en">
<head>
<title>Dice</title>
<!-- Include the CSS and JS files -->
<link rel="stylesheet" href="diceStyle.css">
<script type="text/javascript" src="dice.js"></script>
<style>
.controls {
margin-top: 30px;
clear: both;
}
.diceArea {
width: 50%;
float: left;
}
</style>
<script type="text/javascript">
var initDiceArea = function(name) {
//diceAreaDiv should be a div containing another div with class 'diceHolder'.
//You're welcome to add elements into th diceArea div, but not the diceHolder div (or they may get clobbered).
var diceAreaDiv = document.getElementById(name);
//The name can be used later to access the object with DiceArea.Areas[name].
var diceArea = new DiceArea(diceAreaDiv, name);
//Optional: this function is called whenever the sum of the values on the dice change.
diceArea.displaySum = function(sum) {
diceAreaDiv.getElementsByClassName('diceTotal')[0].innerHTML = sum;
}
diceArea.addDie();
return;
}
var init = function() {
initDiceArea('diceArea1');
initDiceArea('diceArea2');
}
</script>
</head>
<body onload="init()">
<h1 id="heading">Dice</h1>
<div id="diceArea1" class="diceArea">
<h2>Player 1</h2>
<h2>Total: <span class="diceTotal"></span></h2>
<div id="diceHolder" class="diceHolder">
</div>
<div class="controls">
<button type="button" onClick="DiceArea.Areas['diceArea1'].rollDice()">roll</button>
<button type="button" onClick="DiceArea.Areas['diceArea1'].addDie()">add die</button>
<button type="button" onClick="DiceArea.Areas['diceArea1'].removeLast()">remove die</button>
</div>
</div>
<div id="diceArea2" class="diceArea">
<h2>Player 2</h2>
<h2>Total: <span class="diceTotal"></span></h2>
<div id="diceHolder" class="diceHolder">
</div>
<div class="controls">
<button type="button" onClick="DiceArea.Areas['diceArea2'].rollDice()">roll</button>
<button type="button" onClick="DiceArea.Areas['diceArea2'].addDie()">add die</button>
<button type="button" onClick="DiceArea.Areas['diceArea2'].removeLast()">remove die</button>
</div>
</div>
<footer>
</footer>
</body>
</html>