comments
This commit is contained in:
parent
844bd0b2cd
commit
e2c012695d
16
src/code.js
16
src/code.js
@ -1,10 +1,18 @@
|
|||||||
|
// called to handle player movements
|
||||||
|
|
||||||
|
// provided with the id of the area of the board clicked: eg 21
|
||||||
|
|
||||||
function move(id)
|
function move(id)
|
||||||
{
|
{
|
||||||
|
// exit function if their is already something at the position clicked
|
||||||
|
|
||||||
if (board[ids[id][0]][ids[id][1]][0] != 0)
|
if (board[ids[id][0]][ids[id][1]][0] != 0)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// what character will be placed their
|
||||||
|
|
||||||
var charater = (ptm == 1) ? "X" : "O";
|
var charater = (ptm == 1) ? "X" : "O";
|
||||||
var optm = ptm;
|
var optm = ptm;
|
||||||
|
|
||||||
@ -13,6 +21,8 @@ function move(id)
|
|||||||
board[ids[id][0]][ids[id][1]][1].innerHTML = charater;
|
board[ids[id][0]][ids[id][1]][1].innerHTML = charater;
|
||||||
board[ids[id][0]][ids[id][1]][0] = optm;
|
board[ids[id][0]][ids[id][1]][0] = optm;
|
||||||
|
|
||||||
|
// check if someone has won, or if the game is over
|
||||||
|
|
||||||
var winner = win();
|
var winner = win();
|
||||||
|
|
||||||
if (winner != 0)
|
if (winner != 0)
|
||||||
@ -56,6 +66,8 @@ function move(id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if someone has won, or if the game is over
|
||||||
|
|
||||||
function win()
|
function win()
|
||||||
{
|
{
|
||||||
console.log(board);
|
console.log(board);
|
||||||
@ -134,8 +146,12 @@ function win()
|
|||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reset the board ready for another game
|
||||||
|
|
||||||
function reset()
|
function reset()
|
||||||
{
|
{
|
||||||
|
// loop through all positions on board and reset them
|
||||||
|
|
||||||
for (var x = 0; x <= 2; x++)
|
for (var x = 0; x <= 2; x++)
|
||||||
{
|
{
|
||||||
for (var y = 0; y <= 2; y++)
|
for (var y = 0; y <= 2; y++)
|
||||||
|
Loading…
Reference in New Issue
Block a user