This commit is contained in:
AUnicornWithNoLife 2021-04-12 11:28:49 +01:00
parent 29767a5497
commit b366c2cdcb
4 changed files with 87 additions and 44 deletions

View File

@ -1,44 +1,3 @@
var board;
function load()
{
board =
[
[
[0, document.getElementById("id00")],
[0, document.getElementById("id01")],
[0, document.getElementById("id02")]
],
[
[0, document.getElementById("id10")],
[0, document.getElementById("id11")],
[0, document.getElementById("id12")]
],
[
[0, document.getElementById("id20")],
[0, document.getElementById("id21")],
[0, document.getElementById("id22")]
]
];
}
var ids =
{
'00': [0, 0],
'01': [0, 1],
'02': [0, 2],
'10': [1, 0],
'11': [1, 1],
'12': [1, 2],
'20': [2, 0],
'21': [2, 1],
'22': [2, 2]
};
var ptm = 1;
function move(id)
{
if (board[ids[id][0]][ids[id][1]][0] != 0)
@ -68,10 +27,27 @@ function move(id)
if (winner != 0)
{
alert(winner);
score[winner - 1]++;
info['score'].innerHTML = score[0] + " | " + score[1];
info['go'] = "X's Go";
ptm = 1;
reset();
return;
}
if (ptm == 1)
{
charater = "X";
}
else
{
charater = "O";
}
info['go'].innerHTML = charater + "'s Go";
}
function win()

View File

@ -6,6 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src='./code.js'></script>
<script src='./var.js'></script>
<link rel="stylesheet" href="style.css">
@ -52,11 +53,15 @@
</table>
</th>
<th id='info'>
<h2>Score: </h2>
<h2 id='score'>0 | 0</h2>
<br>
<h3>X Go</h3>
<h3 id='go'>X's Go</h3>
<br>
<button onmousedown="reset();" id='reset'>Reset</button>
</th>
</tr>
</table>

View File

@ -23,6 +23,12 @@ button
margin-right: auto;
}
#reset
{
height: 50px;
width: 150px;
}
*
{
background-color: black;

56
src/var.js Normal file
View File

@ -0,0 +1,56 @@
var board;
var info;
var score;
var ids;
var ptm;
function load()
{
board =
[
[
[0, document.getElementById("id00")],
[0, document.getElementById("id01")],
[0, document.getElementById("id02")]
],
[
[0, document.getElementById("id10")],
[0, document.getElementById("id11")],
[0, document.getElementById("id12")]
],
[
[0, document.getElementById("id20")],
[0, document.getElementById("id21")],
[0, document.getElementById("id22")]
]
];
info =
{
"score": document.getElementById("score"),
"go": document.getElementById("go")
};
score =
[
0,
0
];
ids =
{
'00': [0, 0],
'01': [0, 1],
'02': [0, 2],
'10': [1, 0],
'11': [1, 1],
'12': [1, 2],
'20': [2, 0],
'21': [2, 1],
'22': [2, 2]
};
ptm = 1;
}