if (checkWin()) {
// alert the user that he/she won
if (symbol == "X" ) {
// increment the xCount by one
// display the xCount in the appropriate box
}
else {
// increment the oCount by one
// display the oCount in the appropriate box
}
replayGame(); //resets the game
return;
}
else if (numMoves == 9) {
// alert that the game is tied.
// increment the xTie by one
// display the xTie in the appropriate box
replayGame(); // resets the game
return
}
else {
// change the symbol from X to O or O to X for the next player
changeSymbol();
return;
}
Just realized I copy and pasted the wrong code. Is there an edit post feature that I'm not finding?
<html>
<head>
<title>jex8</title>
<style type="text/css">
input.btn {
background-color: maroon;
color: gold;
font-size: 1in;
font-family: "Courier New", "Courier";
font-weight: bold;
width: 2in;
height: 2in;
}
</style>
<script type="text/javascript">
var cell;
var symbol = "X";
function markbox(cell) {
if (cell.value == ""){
cell.value = symbol;
if (symbol == "X")
symbol = "O";
else
symbol = "X";
}
else {
alert("This square is occupied");
}
}
function changeSymbol() {
if (symbol== "X") {
// change the symbol to "O"
}
else {
// change the symbol to "X"
}
}
if (checkWin()) {
alert ("You win!")
}
else {
// change the symbol from X to O or O to X for the next player
changeSymbol();
return;
}
function checkWin() {
with (document.simpleForm) {
if ((b1.value == symbol) && (b2.value==symbol) && (b3.value == symbol))
return true
if ((b4.value == symbol) && (b5.value==symbol) && (b6.value == symbol))
return true
if ((b7.value == symbol) && (b8.value==symbol) && (b9.value == symbol))
return true
if ((b1.value == symbol) && (b4.value==symbol) && (b7.value == symbol))
return true
if ((b2.value == symbol) && (b5.value==symbol) && (b8.value == symbol))
return true
if ((b3.value == symbol) && (b6.value==symbol) && (b9.value == symbol))
return true
if ((b1.value == symbol) && (b5.value==symbol) && (b9.value == symbol))
return true
if ((b3.value == symbol) && (b5.value==symbol) && (b7.value == symbol))
return true
}
return false;
if (checkWin()) {
// alert the user that he/she won
if (symbol == "X" ) {
// increment the xCount by one
// display the xCount in the appropriate box
}
else {
// increment the oCount by one
// display the oCount in the appropriate box
}
replayGame(); //resets the game
return;
}
else if (numMoves == 9) {
// alert that the game is tied.
// increment the xTie by one
// display the xTie in the appropriate box
replayGame(); // resets the game
return
}
else {
// change the symbol from X to O or O to X for the next player
changeSymbol();
return;
}
}
function clearBtn() {
status = "X"
with (document.simpleForm) {
b1.value="";
b2.value="";
b3.value="";
b4.value="";
b5.value="";
b6.value="";
b7.value="";
b8.value="";
b9.value="";
}
}
</script>
</HEAD>
<body >
<FORM name=simpleForm>
<input class="btn" type="button" name="b1" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b2" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b3" value="" onclick="markbox(this)">
<br/>
<input class="btn" type="button" name="b4" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b5" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b6" value="" onclick="markbox(this)">
<br/>
<input class="btn" type="button" name="b7" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b8" value="" onclick="markbox(this)">
<input class="btn" type="button" name="b9" value="" onclick="markbox(this)">
<br/>
<br/>
<FORM name=secondForm>
Current Move: <input type="text" name="currentmove" value="" size=5> </br>
<INPUT type="reset" value="Play Again" onclick="clearBtn()">
</br>
</BR>
Score: X <input type="text" name="xscore" value="" size=3>
O <input type="text" name="oscore" value="" size=3>
TIE <input type="text" name="tiegame" value="" size=3></br>
<INPUT type="reset" value="RESET SCORE AND GAME" onclick="clearBtn()">
</br>
</BODY>
</html>

New Topic/Question
Reply


MultiQuote








|