This is the final vesion of the board game. When you land on most squares, you collect a certain amount, with an option to buy it, in which case you collect from anyone else who lands on it. You have to pay if you land on someone else’s square. Some squares require anothe roll and depending on the roll’s value you gain or lose. Circling the board also gains. A player can sell a square to either the bank, at a discount, or to another player.
This is how the board looks.
This is the code:
<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head profile=”http://gmpg.org/xfn/11″>
<title>Board Game</title>
<style>
body {margin-left:0;margin-right:0;font:italic normal 600 16px Georgia; background: green}
a{ text-decoration: }:link { color: rgb(0, 0, 255) }:visited {color :rgb(100, 0,100) }:hover { }:active { }
#board{position: relative; top: -7px; width: 720px; height: 720px;}
#die1, #die2{position:relative; display: inline; top: 100px; height:100px;width:100px; }
#button1, #button2, #button3, #button4 {position: absolute; left: 20px; top: 20px; font:normal normal 700 24px Arial;}
#button2 {top: 60px}
#button3 {top: 100px}
#button4 {top: 140px}
#cp{position:absolute; left: 1150px; top: 20px; }
input{font:normal normal 700 22px Arial}
</style>
</head>
<body>
<input type=”button” id=”button1″ name=”button1″ value=”Roll” onclick = ‘rol();’ /> <input type=”button” id=”button2″ name=”button2″ value=”Buy” onclick = ‘buy();’ /> <input type=”button” id=”button3″ name=”button3″ value=”Sell” onclick = ‘sell();’ /> <input type=”button” id=”button4″ name=”button4″ value=”Request Buy” onclick = ‘rbuy();’ />
<center><div id=”board”><div id=”die1″><img src=”One.gif ” width=”100px ” height=”100px ” alt= ” ” /></div> <div id=”die2″><img src=”One.gif ” width=”100px ” height=”100px ” alt= ” ” /></div></div></center>
<div id=”cp”>
<select id=”s1″ name=”s1″ onchange=’setup();’>
<option ># Players</option><option >1</option><option >2</option><option >3</option><option >4</option><option >5</option>
</select><br /><br />
</div></center>
<center><div id= “inpt” style=”visibility: hidden; background: white; width: 500px; padding: 0 0 0 20px” onclick=’setNames2();’><input type=”text” id=”ntr” name=”ntr” style=”width:500px” value=”” placeholder = “What is your input” /></div></center>
<center><div id= “inpt2″ style=”visibility: hidden; background: white; width: 1200px; padding: 0 0 0 20px” onclick=’close2();’><input type=”text” id=”ntr2″ name=”ntr” style=”width:1200px” value=”” placeholder = “What is your input”/></div></center>
Â
<script type=”text/javascript”>
var lft = 0; var ran; var ran2; var l1 = [-35,-35,-35,-35,-35]; var tp1 = [1,13,25,37,49]; var sm = [0,0,0,0,0]; var sm2 = [0,0,0,0,0]; var sm3 = [0,0,0,0,0]; var sm4 = [0,0,0,0,0]; var pno = -1; var piece = []; var nt = []; var no; var no2; var tot = [200,200,200,200,200]; var dbl = false; var nam = []; var cnt = -1; var owner = []; var ch; var dn = false; var str = “”; var selar = []; var t; var tm; var propVal = [0,0,0,0,0];
for (var i = 0; i <= 43; i ++) {
owner[i] = “none”;
if (i <= 11) document.getElementById(“board”).innerHTML += ‘<div id=”B’ + i + ‘” style=”position: absolute; left: ‘ + (60 * i) + ‘px; top: 0; width: 60px; height: 60px; text-align: center “></div>’;
if (i > 11 && i <= 22) document.getElementById(“board”).innerHTML += ‘<div id=”B’ + i + ‘” style=”position: absolute; left: 660px; top: ‘ + (60 * (i – 11)) + ‘px ; width: 60px; height: 60px; text-align: center “></div>’;
if (i > 22 && i <= 33) document.getElementById(“board”).innerHTML += ‘<div id=”B’ + i + ‘” style=”position: absolute; left: ‘ + (660 – (i – 22) * 60) + ‘px; top: 660px; width: 60px; height: 60px; text-align: center “></div>’;
if (i > 33 ) document.getElementById(“board”).innerHTML += ‘<div id=”B’ + i + ‘” style=”position: absolute; left: 0; top: ‘ + (660 – (i – 33) * 60) + ‘px; width: 60px; height: 60px; text-align: center “></div>’;
if (i % 3 == 0) {
document.getElementById(“B” + i).style.backgroundColor = “#ffcccc”;
if (i % 9 > 1) document.getElementById(“B” + i).innerHTML = ‘<span style = “background: white”><br />’ + (i + 1) + ‘ 12$</span>’;
}
if (i % 3 == 1) {
document.getElementById(“B” + i).style.backgroundColor = “#ccffcc”;
if (i % 9 != 1 && i != 43 || i == 1) document.getElementById(“B” + i).innerHTML = ‘<span style = “background: white”><br />’ + (i + 1) + ‘ 25$</span>’;
}
if (i % 3 == 2) {
document.getElementById(“B” + i).style.backgroundColor = “#ccccff”;
document.getElementById(“B” + i).innerHTML = ‘<span style = “background: white”><br />’ + (i + 1) + ‘ 5$</span>’;
}
if (i == 0 ) document.getElementById(“B” + i).style.backgroundColor = “#dddddd”;
if (i == 43) document.getElementById(“B” + i).style.backgroundColor = “#bbbbbb”;
}
document.getElementById(“board”).innerHTML += ‘<center><div id=”win” style = “position: relative; top: 250px; font:italic normal 800 48px Georgia; color: #ff0055; visibility: hidden”>The winner is Player 1</div></center>’;
document.getElementById(“board”).innerHTML += ‘<center><div id=”sl” style=”position: relative;top: 25px; padding: 10px; background: white; visibility: hidden; width: 250px; height: 300px”><input type=”button” id=”button5″ name=”button4″ value=”Done” onclick = \’document.getElementById(“sl”).style.visibility = “hidden”;\’ /><br />’;
document.getElementById(“sl”).innerHTML += ‘<select id = “sel” ><option>Click squares to sell</option></select>’;
document.getElementById(“sl”).innerHTML += ‘<select id = “sel2″ onclick=\’sell2();\’><option>Bank</option></select><br /><input type=”text” id=”sale” style=”width: 240px” placeholder=”transaction amount” /></div></center>’;
document.getElementById(“ntr”).onkeypress = setNames;
document.onkeyup = addNumber;
function addNumber(e) {
tm = parseInt(document.getElementById(“ntr”).value.substr(0,2));
if (e.keyCode == 17) document.getElementById(“ntr”).value += ” ” + owner[tm] ;
if (e.keyCode == 18) document.getElementById(“inpt”).style.visibility = “hidden”;
}
function buy() {
if (owner[sm[pno]] != “none”) alert(“This square is already owned!”);
if (tot[pno] < 0) {
alert(“You are not allowed to make a purchase”)
} else {
if (owner[sm[pno]] == “none”) {
if ((sm[pno] – 1) % 3 == 0 && (sm[pno] – 1) % 9 > 0) {
dn = true;
tot[pno] -= 25;
propVal[pno] +=25;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#ff9999”;
setTimeout(‘timedAlert(“You purchased a $12 square for $25”,3000)’,1000);
}
if ( (sm[pno] – 1) % 3 == 1 && (sm[pno] – 1) % 9 > 1 || sm[pno] == 2 ) {
dn = true;
tot[pno] -= 50;
propVal[pno] +=50;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#88ff88”;
setTimeout(‘timedAlert(“You purchased a $25 square for $50”,3000)’,1000);
}
if ((sm[pno] – 1) % 3 == 2) {
dn = true;
tot[pno] -= 12;
propVal[pno] +=12;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#9999ff”;
setTimeout(‘timedAlert(“You purchased a $5 square for $12”,3000)’,1000);
}
}
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
no = pno + 1;
if (no == no2 + 1) no = 0;
document.getElementById(“tname”).value = nam[no] ;
dbl = false;
}
}
function rbuy() {
enterInput2(“Enter # as 2 digits(eg: 06)add space add bid & doubleclick”);
}
function sell () {
str = “”;
// t = sm[pno];
document.getElementById(“sel”).innerHTML = “<option>Click squares to sell</option>”;
document.getElementById(“sel2”).innerHTML = “<option>Bank</option>”;
for (var i = 0; i < 44; i ++) {
t = i;
if(owner[t] == nam[pno]) {
str += t;
if (t % 3 == 1) str += ” $25,”
if (t % 3 == 2 ) str += ” $50,”
if (t % 3 == 0) str += ” $12,”
}
}
str = str.substr(0, str.length);
selar = str.split(‘,’);
document.getElementById(“sl”).style.visibility = “visible”;
if (selar.length > 6) {
document.getElementById(“sel”).size = selar.length + 1;
document.getElementById(“sel2”).size = selar.length + 1;
} else {
document.getElementById(“sel2”).size = 6;
document.getElementById(“sel”).size = 6;
}
var ht = 22 * (selar.length + 2) + “px”;
document.getElementById(“sl”).style.height = ht;
for (var i = 0; i <= selar.length – 1 ; i ++) {
document.getElementById(“sel”).innerHTML += ‘<option>’ + selar[i] + ‘</option>’;
}
for (var i = 0; i < nam.length ; i ++) {
if (nam[i] != “”) document.getElementById(“sel2”).innerHTML += ‘<option>’ + nam[i] + ‘</option>’;
}
if (selar.length > 6) {
var ht = 22 * (selar.length + 2) + “px”;
} else {
ht = 22 * 8 + “px”;
}
document.getElementById(“sl”).style.height = ht;
//alert(document.getElementById(“sel”).innerHTML);
}
function sell2() {
if (sel2.value == “Bank”) {
if (document.getElementById(“sel”).value.indexOf(“$25”) > -1) {
tot[pno] += 22;
propVal[pno] -=25;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
if (document.getElementById(“sel”).value.indexOf(“$12”) > -1) {
tot[pno] += 9;
propVal[pno] -=12;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
if (document.getElementById(“sel”).value.indexOf(“$50”) > -1) {
tot[pno] += 45;
propVal[pno] -=50;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
} else {
owner[pno] = “none”;
var trans = document.getElementById(“sel2”).selectedIndex – 1;
var t = parseInt(document.getElementById(“sel”).value.substr(0,2));
owner[t] = nam[trans];
tot[pno] += parseInt(document.getElementById(“sale”).value);
propVal[pno] -=parseInt(document.getElementById(“sale”).value);
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
tot[trans] -= parseInt(document.getElementById(“sale”).value);
document.getElementById(“t” + (trans + 2)).value = nam[trans] + ‘ ‘ + tot[trans] + ‘$’;
}
var ind = document.getElementById(“sel”).value;
if (ind.substr(0,2) % 3 == 1) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ffcccc”;
owner[t] = “none”;
}
}
if (ind.substr(0,2) % 3 == 2) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccffcc”;
owner[t] = “none”;
}
}
if (ind.substr(0,2) % 3 == 0) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccccff”;
owner[t] = “none”;
}
}
bankrupt();
}
function setup() {
no2 = document.getElementById(“s1”).selectedIndex – 1;
enterInput(“What is your name?”);
}
function setup2() {
document.getElementById(“cp”).innerHTML += ‘<input type=”text” id=”tname” name=”tname” value=”‘ + nam[0] + ‘” /><br />’;
for (var i = 0; i <= no2; i ++) {
//document.getElementById(“cp”).innerHTML += ‘<input type=”text” id=”t’ + (i) + ‘” value= “‘ + nam[i] + ‘ ‘ + tot[i] + ‘$ “/><br /><br />’;
document.getElementById(“cp”).innerHTML += ‘<input type=”text” id=”t’ + (i) + ‘” style = “position: relative; top: 10px” value= “‘ + nam[i] + ‘ ‘ + tot[i] + ‘$ “/>’;
nt[i] = tp1[i];
document.getElementById(“board”).innerHTML += ‘<div id = “piece[‘ + i + ‘]” style = ” position: absolute; top: ‘ + tp1[i] + ‘px; left: ‘ + 1[i] + ‘px; width: 10px; height: 10px; background: #ff0055; border: 1px solid white”></div>’;
if (i == 1) document.getElementById(“piece[1]”).style.backgroundColor = “#0000cc”;
if (i == 2) document.getElementById(“piece[2]”).style.backgroundColor = “black”;
if (i == 3) document.getElementById(“piece[3]”).style.backgroundColor = “#00cc00”;
if (i == 4) document.getElementById(“piece[4]”).style.backgroundColor = “#cc00cc”;
}
document.getElementById(“board”).innerHTML += ‘<center><div id=”alrt” style=”position: relative; top: -130px; width: 250px; padding:5px; font:normal normal 700 20px Arial; border-radius: 10px; background: white; visibility:hidden”>This is a test</div></center>’;
}
function setNames(e) {
if (e.keyCode == 13) {
cnt ++;
nam[cnt] = document.getElementById(“ntr”).value;
document.getElementById(“ntr”).value = “”;
document.getElementById(“ntr”).focus();
if ( cnt == no2) {
document.getElementById(“inpt”).style.visibility = “hidden”;
setup2();
}
}
}
function setNames2() {
cnt ++;
nam[cnt] = document.getElementById(“ntr”).value;
document.getElementById(“ntr”).value = “”;
document.getElementById(“ntr”).focus();
if ( cnt == no2) {
document.getElementById(“inpt”).style.visibility = “hidden”;
setup2();
}
}
function close2() {
document.getElementById(“inpt”).style.visibility = “hidden”;
roll2();
}
function enterInput(ph) {
document.getElementById(“ntr”).placeholder = ph;
document.getElementById(“inpt”).style.visibility = “visible”;
document.getElementById(“ntr”).focus();
}
function enterInput2(ph) {
document.getElementById(“ntr”).placeholder = ph;
document.getElementById(“inpt”).style.visibility = “visible”;
document.getElementById(“ntr”).focus();
}
function rol() {
document.getElementById(“die1″).innerHTML='<img src=”Three.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
document.getElementById(“die2″).innerHTML='<img src=”Three.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (! dbl) pno ++;
if (nam[pno] == “”) pno ++;
if (pno == no2 + 1) pno = 0;
document.getElementById(“tname”).value = nam[pno];
setTimeout(“rol2()”,1000);
}
function rol2() {
ran = Math.floor(6*Math.random()+ 1);
if (ran == 1) document.getElementById(“die1″).innerHTML='<img src=”One.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran == 2) document.getElementById(“die1″).innerHTML='<img src=”Two.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran == 3) document.getElementById(“die1″).innerHTML='<img src=”Three.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran == 4) document.getElementById(“die1″).innerHTML='<img src=”Four.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran == 5) document.getElementById(“die1″).innerHTML='<img src=”Five.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran == 6) document.getElementById(“die1″).innerHTML='<img src=”Six.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
ran2 = Math.floor(6*Math.random()+ 1);
if (ran2 == 1) document.getElementById(“die2″).innerHTML='<img src=”One.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran2 == 2) document.getElementById(“die2″).innerHTML='<img src=”Two.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran2 == 3) document.getElementById(“die2″).innerHTML='<img src=”Three.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran2 == 4) document.getElementById(“die2″).innerHTML='<img src=”Four.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran2 == 5) document.getElementById(“die2″).innerHTML='<img src=”Five.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
if (ran2 == 6) document.getElementById(“die2″).innerHTML='<img src=”Six.gif ” width=”100px ” height=”100px ” alt= ” ” />’ ;
dn = false;
if (! dbl){
setTimeout(“roll2()”, 2000);
} else {
setTimeout(“roll3()”, 6000);
}
}
function roll2() {
if (! dbl) {
if (sm[pno] + (ran + ran2) < 13 ) {
l1[pno] += 60 * (ran + ran2);
tp1[pno] = nt[pno];
}
sm[pno] += (ran + ran2);
if (sm[pno] > 12) sm2[pno] = sm[pno] – 12;
if (sm2[pno] > 11) sm3[pno] = sm2[pno] – 11;
if (sm3[pno] > 11 ) sm4[pno] = sm3[pno] – 11;
if (sm4[pno] > 11) {
sm[pno] = sm4[pno] – 11;
sm2[pno] = 0;
sm3[pno] = 0;
sm4[pno] = 0;
tp1[pno] = nt[pno];
l1[pno] = 25 + 60 * (sm[pno] – 1);
tot[pno] += 50;
timedAlert(“Congratulations!<br />You have won<br />50$<br />You Now Have<br />” + tot[pno] + “$”,2000);
//document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
setTimeout(“roll3()”,5000);
}
if (sm2[pno] > 0) {
tp1[pno] = 60 * sm2[pno] + nt[pno];
if (sm2[pno] > 10) tp1[pno] = 660 + nt[pno];
l1[pno] = 685;
}
if (sm3[pno] > 0) {
l1[pno] = 685 – 60 * sm3[pno];
if (sm3[pno] > 10) l1[pno] = 25;
tp1[pno] = 661 + nt[pno];
}
if (sm4[pno] > 0) {
l1[pno] = 25;
tp1[pno] = 661 + nt[pno] – 60 * sm4[pno];
}
document.getElementById(“piece[” + pno + “]”).style.left = l1[pno] + “px”;
document.getElementById(“piece[” + pno + “]”).style.top = tp1[pno] + “px”;
if ( (sm[pno] – 1) % 9 == 0 && (sm[pno] – 1) > 1) {
dbl = true;
timedAlert(“Roll the dice. if you roll 2,4,6,9,or 11 you win $20</br /></br />roll 7 you win $10<br /></br /> 3,5,8,10 or 12 you lose $5”, 6000);
} else if ( (sm[pno] – 1) % 9 == 1 && (sm[pno] – 1) > 1) {
dbl = true;
timedAlert(“Roll the dice. if you roll 2,4,6,9,or 11 you win $40</br /></br />roll 7 you win $20<br /></br /> 3,5,8,10 or 12 you lose $10”,6000);
}
}
if (dbl) {
if ( (sm[pno] – 1) != 0) setTimeout(“roll3()”,6000);
} else {
if ( (sm[pno] – 1) != 0) setTimeout(“roll3()”,2000);
}
}
function roll3() {
if (! dbl) {
if ( sm[pno] > 1 && (sm[pno] – 1) % 3 == 0 && (sm[pno] – 1) % 9 != 0 && (owner[sm[pno]] == “none” || owner[sm[pno]] == nam[pno])) {
tot[pno] += 5;
setTimeout(‘timedAlert(“You made<br />5$<br />You Now Have<br />” + tot[pno] + “$”, 5000)’,2000);
} else if ((sm[pno] – 1) % 3 == 0 && owner[sm[pno]] != nam[pno]) {
for (var i = 0; i <= no2; i ++) {
if (nam[i] == owner[sm[pno]] ) {
tot[pno] -= 12;
tot[i] += 12;
timedAlert(“This square is owned by ” + nam[i] + “<br />Pay ” + nam[i] + ” $12<br />You Now Have<br />” + tot[pno] + “$”,4000);
document.getElementById(“t” + (i + 2)).value = nam[i] + ‘ ‘ + tot[i] + ‘$’;
}
}
}
if ( sm[pno] > 2 && (sm[pno] – 1) % 3 == 1 && (sm[pno] – 1) % 9 != 1 && owner[sm[pno]] == “none” || (owner[sm[pno]] == nam[pno] && (sm[pno] – 1) % 3 == 1)|| sm[pno] == 2) {
tot[pno] += 7;
setTimeout(‘timedAlert(“You made<br />7$<br />You Now Have<br />” + tot[pno] + “$”, 5000)’,2000);
} else if ((sm[pno] – 1) % 3 == 1 && owner[sm[pno]] != nam[pno] ) {
for (var i = 0; i <= no2; i ++) {
if (nam[i] == owner[sm[pno]] ) {
tot[pno] -= 25;
tot[i] += 25;
timedAlert(“This square is owned by ” + nam[i] + “<br />Pay ” + nam[i] + ” $25<br />You Now Have<br />” + tot[pno] + “$”,4000);
document.getElementById(“t” + (i + 2)).value = nam[i] + ‘ ‘ + tot[i] + ‘$’;
}
}
}
if ( (sm[pno] – 1) % 3 == 2 && (owner[sm[pno]] == “none” || owner[sm[pno]] == nam[pno])) {
tot[pno] += 3;
setTimeout(‘timedAlert(“You made<br />3$<br />You Now Have<br />” + tot[pno] + “$”, 5000)’,2000);
} else if ((sm[pno] – 1) % 3 == 2 && owner[sm[pno]] != nam[pno]) {
for (var i = 0; i <= no2; i ++) {
if (nam[i] == owner[sm[pno]] ) {
tot[pno] -= 5;
tot[i] += 5;
timedAlert(“This square is owned by ” + nam[i] + “<br />Pay ” + nam[i] + ” $5<br />You Now Have<br />” + tot[pno] + “$”,4000);
document.getElementById(“t” + (i + 2)).value = nam[i] + ‘ ‘ + tot[i] + ‘$’;
}
}
}
}
if (! dbl) {
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
no = pno + 1;
if (nam[no] == “”) no ++;
if (no == no2 + 1) no = 0;
document.getElementById(“tname”).value = nam[no] ;
}
if (dbl && (sm[pno] – 1) % 9 == 0) {
var rl = ran + ran2;
if (rl == 2 || rl == 4 || rl == 6 || rl ==9 || rl == 11) tot[pno] += 20;
if (rl == 7) tot[pno] += 10;
if (rl == 3 || rl == 5 || rl == 8 || rl ==10 || rl == 12) tot[pno] -= 5;
timedAlert(“You rolled ” + rl + ” You Now Have<br />” + tot[pno] + “$”, 2000);
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
no = pno + 1;
if (nam[no] == “”) no ++;
if (no == no2 + 1) no = 0;
document.getElementById(“tname”).value = nam[no] ;
//dbl = false;
}
if (dbl && (sm[pno] – 1) % 9 == 1) {
var rl = ran + ran2;
if (rl == 2 || rl == 4 || rl == 6 || rl ==9 || rl == 11) tot[pno] += 40;
if (rl == 7) tot[pno] += 20;
if (rl == 3 || rl == 5 || rl == 8 || rl ==10 || rl == 12) tot[pno] -= 10;
timedAlert(“You rolled ” + rl + ” You Now Have<br />” + tot[pno] + “$”, 2000);
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
no = pno + 1;
if (nam[no] == “”) no ++;
if (no == no2 + 1) no = 0;
document.getElementById(“tname”).value = nam[no] ;
dbl = false;
}
if (tot[pno] > 999) {
document.getElementById(“win”).innerHTML = ‘The winner is ‘ + nam[pno] ;
document.getElementById(“win”).style.visibility = “visible”;
}
dbl = false;
setTimeout(“bankrupt()”,5000);
}
function timedAlert(param,dur) {
document.getElementById(“alrt”).innerHTML = param;
document.getElementById(“alrt”).style.border = “1px solid black”;
document.getElementById(“alrt”).style.visibility = “visible”;
setTimeout(“clse()”, dur);
}
function clse() {
document.getElementById(“alrt”).style.visibility = “hidden”;
}
function bankrupt() {
if (tot[pno] < 0 && tot[pno] + propVal[pno] >= 0) timedAlert(“You must sell something”, 5000);
if (tot[pno] + propVal[pno] < 0) {
timedAlert(“Your total worth is less than zero. You are now bankrupt!”, 5000);
tot[pno] = 0;
propVal[pno] = 0;
document.getElementById(“piece[” + pno + “]”).remove();
document.getElementById(“t” + pno).value = “”;
for (var i = 0; i < 44; i ++) {
t = i;
if(owner[t] == nam[pno]) {
if (t % 3 == 1) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ffcccc”;
if (t % 3 == 2) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccffcc”;
if (t % 3 == 0) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccccff”;
owner[t] = “”;
}
}
document.getElementById(“tname”).value = nam[pno + 1];
if (pno + 1 > no2) document.getElementById(“tname”).value = nam[0];
nam[pno] = “”;
document.getElementById(“t” + pno).remove();
}
}
</script>
</body></html>
It is too long to discuss eveything so I will just mention a few new things.
This is the code fo buying a square:
function buy() {
if (owner[sm[pno]] != “none”) alert(“This square is already owned!”);
if (tot[pno] < 0) {
alert(“You are not allowed to make a purchase”)
} else {
if (owner[sm[pno]] == “none”) {
if ((sm[pno] – 1) % 3 == 0 && (sm[pno] – 1) % 9 > 0) {
dn = true;
tot[pno] -= 25;
propVal[pno] +=25;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#ff9999”;
setTimeout(‘timedAlert(“You purchased a $12 square for $25”,3000)’,1000);
}
if ( (sm[pno] – 1) % 3 == 1 && (sm[pno] – 1) % 9 > 1 || sm[pno] == 2 ) {
dn = true;
tot[pno] -= 50;
propVal[pno] +=50;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#88ff88”;
setTimeout(‘timedAlert(“You purchased a $25 square for $50”,3000)’,1000);
}
if ((sm[pno] – 1) % 3 == 2) {
dn = true;
tot[pno] -= 12;
propVal[pno] +=12;
owner[sm[pno]] = nam[pno];
document.getElementById(“B” + (sm[pno] – 1)).style.backgroundColor = “#9999ff”;
setTimeout(‘timedAlert(“You purchased a $5 square for $12”,3000)’,1000);
}
}
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
no = pno + 1;
if (no == no2 + 1) no = 0;
document.getElementById(“tname”).value = nam[no] ;
dbl = false;
}
}
There is code for each vaslue of square.
There ae two functions fo selling:
function sell () {
str = “”;
// t = sm[pno];
document.getElementById(“sel”).innerHTML = “<option>Click squares to sell</option>”;
document.getElementById(“sel2”).innerHTML = “<option>Bank</option>”;
for (var i = 0; i < 44; i ++) {
t = i;
if(owner[t] == nam[pno]) {
str += t;
if (t % 3 == 1) str += ” $25,”
if (t % 3 == 2 ) str += ” $50,”
if (t % 3 == 0) str += ” $12,”
}
}
str = str.substr(0, str.length);
selar = str.split(‘,’);
document.getElementById(“sl”).style.visibility = “visible”;
if (selar.length > 6) {
document.getElementById(“sel”).size = selar.length + 1;
document.getElementById(“sel2”).size = selar.length + 1;
} else {
document.getElementById(“sel2”).size = 6;
document.getElementById(“sel”).size = 6;
}
var ht = 22 * (selar.length + 2) + “px”;
document.getElementById(“sl”).style.height = ht;
for (var i = 0; i <= selar.length – 1 ; i ++) {
document.getElementById(“sel”).innerHTML += ‘<option>’ + selar[i] + ‘</option>’;
}
for (var i = 0; i < nam.length ; i ++) {
if (nam[i] != “”) document.getElementById(“sel2”).innerHTML += ‘<option>’ + nam[i] + ‘</option>’;
}
if (selar.length > 6) {
var ht = 22 * (selar.length + 2) + “px”;
} else {
ht = 22 * 8 + “px”;
}
document.getElementById(“sl”).style.height = ht;
//alert(document.getElementById(“sel”).innerHTML);
}
function sell2() {
if (sel2.value == “Bank”) {
if (document.getElementById(“sel”).value.indexOf(“$25”) > -1) {
tot[pno] += 22;
propVal[pno] -=25;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
if (document.getElementById(“sel”).value.indexOf(“$12”) > -1) {
tot[pno] += 9;
propVal[pno] -=12;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
if (document.getElementById(“sel”).value.indexOf(“$50”) > -1) {
tot[pno] += 45;
propVal[pno] -=50;
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
}
} else {
owner[pno] = “none”;
var trans = document.getElementById(“sel2”).selectedIndex – 1;
var t = parseInt(document.getElementById(“sel”).value.substr(0,2));
owner[t] = nam[trans];
tot[pno] += parseInt(document.getElementById(“sale”).value);
propVal[pno] -=parseInt(document.getElementById(“sale”).value);
document.getElementById(“t” + pno).value = nam[pno] + ‘ ‘ + tot[pno] + ‘$’;
tot[trans] -= parseInt(document.getElementById(“sale”).value);
document.getElementById(“t” + (trans + 2)).value = nam[trans] + ‘ ‘ + tot[trans] + ‘$’;
}
var ind = document.getElementById(“sel”).value;
if (ind.substr(0,2) % 3 == 1) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ffcccc”;
owner[t] = “none”;
}
}
if (ind.substr(0,2) % 3 == 2) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccffcc”;
owner[t] = “none”;
}
}
if (ind.substr(0,2) % 3 == 0) {
t = ind.substr(0,2);
if (sel2.value == “Bank”) {
document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccccff”;
owner[t] = “none”;
}
}
bankrupt();
}
They create a list of squares the seller owns and transfer the squares either back to the bank or to a new owner.
There is also a bankrupt function to determine a true bankruptcy or whether a same of owned squares could cover a negative cash level, in which case the player would be removed:
function bankrupt() {
if (tot[pno] < 0 && tot[pno] + propVal[pno] >= 0) timedAlert(“You must sell something”, 5000);
if (tot[pno] + propVal[pno] < 0) {
timedAlert(“Your total worth is less than zero. You are now bankrupt!”, 5000);
tot[pno] = 0;
propVal[pno] = 0;
document.getElementById(“piece[” + pno + “]”).remove();
document.getElementById(“t” + pno).value = “”;
for (var i = 0; i < 44; i ++) {
t = i;
if(owner[t] == nam[pno]) {
if (t % 3 == 1) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ffcccc”;
if (t % 3 == 2) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccffcc”;
if (t % 3 == 0) document.getElementById(“B” + (t – 1)).style.backgroundColor = “#ccccff”;
owner[t] = “”;
}
}
document.getElementById(“tname”).value = nam[pno + 1];
if (pno + 1 > no2) document.getElementById(“tname”).value = nam[0];
nam[pno] = “”;
document.getElementById(“t” + pno).remove();
}
}