js/tictactoe.js
/* Reaction is called whenever the player clicks on a box, or enters recursion if Autoplay is active for the current player */
Reaction is called whenever the player clicks on a box, or enters recursion if Autoplay is active for the current player
Reaction is called whenever the player clicks on a box or enters recursion if Autoplay is active for the current player
function Reaction(space)
{
    var board = GatherBoard();
    console.log(space.id);
    var turn = parseInt(document.getElementById("Counter").textContent);
    console.log(turn);
    if((space.classList.contains("X") || space.classList.contains("O")) && turn < 10) 
    {
        console.log("Invalid move!");
        document.getElementById("Message").textContent = "Invalid move!";  
    }
    else if(turn < 10) 
    {
        if(turn % 2 == 1) 
        {
            space.classList.add("X");
            document.getElementById("Message").textContent = "O's turn";
        }
        else 
        {
            space.classList.add("O");
            document.getElementById("Message").textContent = "X's turn";     
        }  
        turn++;
    } 
    var check = WinCheck(board); 
    if(!check) 
    { 
        console.log(turn + " game is still going"); 
    }
    else if(turn % 2 == 0 && turn < 11)
    {
        document.getElementById("Message").textContent = "X won!";
        turn = 11;
        FadeLose(board, "X");
    }
    else if(turn < 11)
    {
        document.getElementById("Message").textContent = "O won!";
        turn = 11;
        FadeLose(board, "O");
    }
    if(turn == 10)
    {
        document.getElementById("Message").textContent = "Draw! Play again?";   
    }
    turn = turn.toString();
    document.getElementById("Counter").textContent = turn;
    var list = document.getElementsByTagName('button');
    if(list[1].classList.contains("Auto") && turn % 2 == 1 && turn < 10)
   {
        console.log("Autoplay for X's turn");
        Reaction(getValidMove());
   }
    if(list[2].classList.contains("Auto") && turn % 2 == 0 && turn < 10)
   {
        console.log("Autoplay for O's turn");
        Reaction(getValidMove());
   }
} 
function Reaction ( space ) { var board = GatherBoard ( ) ; console . log ( space . id ) ; var turn = parseInt ( document . getElementById ( "Counter" ) . textContent ) ; console . log ( turn ) ; if ( ( space . classList . contains ( "X" ) || space . classList . contains ( "O" ) ) && turn < 10 ) { console . log ( "Invalid move!" ) ; document . getElementById ( "Message" ) . textContent = "Invalid move!" ; } else if ( turn < 10 ) { if ( turn % 2 == 1 ) { space . classList . add ( "X" ) ; document . getElementById ( "Message" ) . textContent = "O's turn" ; } else { space . classList . add ( "O" ) ; document . getElementById ( "Message" ) . textContent = "X's turn" ; } turn ++ ; } var check = WinCheck ( board ) ; if ( ! check ) { console . log ( turn + " game is still going" ) ; } else if ( turn % 2 == 0 && turn < 11 ) { document . getElementById ( "Message" ) . textContent = "X won!" ; turn = 11 ; FadeLose ( board , "X" ) ; } else if ( turn < 11 ) { document . getElementById ( "Message" ) . textContent = "O won!" ; turn = 11 ; FadeLose ( board , "O" ) ; } if ( turn == 10 ) { document . getElementById ( "Message" ) . textContent = "Draw! Play again?" ; } turn = turn . toString ( ) ; document . getElementById ( "Counter" ) . textContent = turn ; var list = document . getElementsByTagName ( 'button' ) ; if ( list [ 1 ] . classList . contains ( "Auto" ) && turn % 2 == 1 && turn < 10 ) { console . log ( "Autoplay for X's turn" ) ; Reaction ( getValidMove ( ) ) ; } if ( list [ 2 ] . classList . contains ( "Auto" ) && turn % 2 == 0 && turn < 10 ) { console . log ( "Autoplay for O's turn" ) ; Reaction ( getValidMove ( ) ) ; } }
Reaction is called whenever the player clicks on a box, or enters recursion if Autoplay is active for the current player
Reaction is called whenever the player clicks on a box or enters recursion if Autoplay is active for the current player
// Compile 2D array of board, X right, Y down
 // Determine who's turn it is, stored in 'Counter' id
 // Invalid move
 // Valid move
 // Odd value, X turn
 // Even value, o turn
 // End of valid move 'Else' statement
 // Check is boolean value
 // Nobody has won
 // This should only trigger if there is a tie
 // Change inner HTML to reflect current turn
 // See if autoplay is on for X or O
 // End of function Reaction
