Code Monkey home page Code Monkey logo

tictactoe's Introduction

Tic-Tac-Toe Project

Overview:

In this unit, coders will create the classic game of tic tac toe in their browser! The user will input moves as player X or O on a tic tac toe board. When a player wins, the game will end and a message will display the winner.

Day 1

Planning

  • Complete the project planning document.

Set-Up

  • Go to the repository
  • [ x] Fork this repository to your github account and import into a new Glitch project
  • Make your site live on gh-pages
  • Submit your website using the link on the Agenda

JavaScript

  • [ x] Declare a variable that keeps track of the current player and set it equal to either a string of "X" or "O"
  • Declare a variable that keeps track of the total number of turns taken and set it equal to 0
  • Declare a variable of a boolean type that will signal whether or not the game has ended and set it equal to false
  • [x ] Declare a function with two parameters that removes the button of the corresponding ID, and changes the text of the div that is the tileId to the player variable.
  • [x ] Declare a function with 0 parameters that will change the current player to either "X" or "O" depending on the current player. Decide where to call this function.

Wrap

  • Save and submit your website using the link on the session agenda.

Day 2

JavaScript

  • [ x] Declare a function with 3 parameters of the tileIds, and return if the value of the each of the tileIds are equal to the current player. This function will check if the player has won.
  • [x ] Declare a function that will call the function above on all of the vertical combinations of tiles.
  • [ x] Declare a function that will call the function above on all of the horizontal combinations of tiles
  • [ x] Declare a function checkDiagonalWins that will call the function above on all of the diagonal combinations

Day 3

JavaScript

  • [ x] Implement behavior that will change the title to "It's a draw!" and end the game by changing the boolean variable to true after 9 pieces are placed. Do this by writing a function that will add 1 to the current turns, and check if that counter has reached 9.
  • [ x] In each of the win functions, if the win condition is satisfied, set the end game variable to true, and change the title to "[Player] Wins!"
  • [ x] Update your functions to check if the game has ended first before placing a piece.
  • [ x] Determine the appropriate location to place the Win functions

Wrap

  • Push your changes!

Project Extensions:

  • Add in your own css to personalize your project
  • Create a button that will reset the game back to the original (this requires clearing the Xs and Os, and putting the "move" buttons back)
  • Keep track of the score between the two players: X wins, O wins, and draws
  • Change the 9 button functions to instead be one generic function on the button selector
  • Change the board to be 4x4 and end the game when there is a 4 in a row

References/Tools

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.