Tic-Tac-Toe (P5 version)


Re-create the classic game using P5.js. Apply your own design, and come up with a clever algorithm to figure out the win condition.
To see a working example click here


Directions
  1. Set up your HTML page, insert the P5.js source tag into the <head>section of your project page:

    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>

    Your code now speaks P5!

  2. Create a 3x3 grid on the canvas. Use rect() or line().

  3. Create a 3x3 array that will hold the value of each square. Use a nested for-loop for a 2-D array.

  4. Make it so that when you click on the upper-left square, it gets an X, and the value in the array for that square changes. One way to do it is with
    
         function mouseClicked()  
     
    
  5. To make it handy for you to debug, add a label element to your HTML page, above the canvas. Then display the Row and Column Clicked and the Value, in the label.

  6. Write a function that figures out which square is being clicked based on mouse position, and make changes that to square in the grid and on the canvas.

  7. Keep track of whose turn it is, Player 1 or Player 2, and change the square to an X or a O, depending on the player.

  8. Check if any player has 3 in a row and announce a winner if so. As you are adding up the rows and columns, display the results in the label so you can check yourself.

  9. Test and finish the project till it looks perfect to you.





(c) 2018 by Code Craft Academy