HTML and CSS Reference
In-Depth Information
var ctx;
var dx;
var dy;
var firstturn = true;
Global variable, initialized to the
value true
var point;
Global variable, does not need to
be initialized because it will be set
before use
function throwdice() {
Start of throwdice function
var sum;
Variable to hold the sum of the
values for the 2 dice
var ch = 1+Math.floor(Math.random()*6);
Set ch with the first random value
Assign this to sum
sum = ch;
dx = dicex;
Set dx
dy = dicey;
set dy
drawface(ch);
Draw the first die face
dx = dicex + 150;
Adjust the horizontal position
ch=1 + Math.floor(Math.random()*6);
Set ch with a random value. This
is the one for the second die.
sum += ch;
Add ch to what is already in sum
drawface(ch);
Draw the second die
if (firstturn) {
Now start the implementation of
the rules. Is it a first turn?
switch(sum) {
If it is, start a switch with sum as
the condition
case 7:
For 7
Search WWH ::




Custom Search