MCPcopy Create free account
hub / github.com/codemistic/Web-Development / selectGameField

Function selectGameField

Tic-tac-toe using JS/scripts/game.js:43–68  ·  view source on GitHub ↗
(event)

Source from the content-addressed store, hash-verified

41
42
43function selectGameField(event){
44 const selectedField=event.target;
45 const selectedColumn=selectedField.dataset.col-1;
46 const selectedRow=selectedField.dataset.row-1;
47
48 if(gameData[selectedRow][selectedColumn]>0){
49 alert('please select an empty box');
50 return;
51 }
52
53 event.target.textContent=player[activePlayer].symbol;
54 event.target.classList.add('disabled');
55
56
57
58 gameData[selectedRow][selectedColumn]=activePlayer+1;
59
60 const winnerId=checkForGameOver();
61
62 if(winnerId!==0){
63 endGame(winnerId);
64 }
65
66 currentRound++;
67 switchPlayer();
68}
69
70function checkForGameOver(){
71for(let i=0;i<3;i++){

Callers

nothing calls this directly

Calls 3

checkForGameOverFunction · 0.85
switchPlayerFunction · 0.85
endGameFunction · 0.70

Tested by

no test coverage detected