altonelli / tic-tac-toe

browser tic-tac-toe with HTML, CSS, JS, jQuery, Bootstrap
0 stars 0 forks source link

Tic Tac Toe - Weekend Lab

Objective: Build a tic-tac-toe game in HTML, CSS, and JavaScript.

This week, we've been learning about working with conditionals and loops, as well as writing functions. We've also learned about the structure of the DOM and how we can interact with it using CSS and JavaScript. We've looked at Bootstrap's CSS library and at jQuery, a JavaScript library for front end web development.

For your first weekend lab, we'll be making a tic-tac-toe game using your knowledge and skills from this week.

Baseline Requirements

Further Challenge Ideas

How to Get Started

Play Tic-Tac-Toe

Remind yourself how tic-tac-toe works by playing a few games with a classmate.

Set up repository, files, and basic structure.

  1. Fork this repository to create a copy on your GitHub account.

  2. Clone the tic-tac-toe repository from your GitHub account into your wdi folder to create a local copy on your computer.

  3. Use index.html as your starting point on this project. There is already some starter code in index.html, css/style.css, and js/app.js.

  4. Make sure that jQuery and Bootstrap's CSS are linked in your index.html. Also link your custom CSS and JavaScript files to your index.html.

  5. Test that your CSS and JavaScript files are linked to your index.html. Add an alert to app.js, and change the color of the body in style.css. Then open index.html in the browser. You should see part of an empty tic-tac-toe game board with your background color, and you should also see your alert message pop up.

  6. There's part of a board in index.html already. Use Bootstrap's grid system to create the rest of the empty tic-tac-toe game board. The empty board should look like this:

    empty tic tac toe board
  7. Add a reset button below the board.

Target DOM elements for gameplay

  1. Use the $() jQuery function with CSS selectors to locate each of the DOM elements your user will click. Try this in your console to make sure your selection works. Set up variables for them in your app.js.

  2. After you find the element(s), use .on to set up a simple click event listener for each of those elements. Start by having your event handler just log a message that the element was clicked.

  3. Most of your game logic will happen when a user clicks inside the board, on one of the boxes.

Hints and Tips:

Track Turns

You need to keep track of whose turn it is. This will be important when deciding whether to draw an `X` or an `O`. Try storing the turn as a variable.

Claim a Box

You'll need a way for your code to check whether a box is empty. When a box is claimed, use jQuery to change the box's DOM element somehow. Then you can check that feature of the box later! Test your ideas in the console.

Reset Everything

Your reset button should change the board back to its initial configuration. Make sure you empty all the boxes and reset all other variables to their starting values. Don't forget the starting turn variable!

Style `X`s and `O`s

Use jQuery to add a CSS class to the box when a player makes a move. (Not sure how? Google "jQuery add class", choose the jQuery API Documentation result, and find some examples!)

Detect a Draw

The game can end when someone wins or when the board fills up. How can you check whether the board is full or still has space for the players to move?

Win!
Hint: what is winning?

Start by listing all the ways to win at tic-tac-toe. There are 8 winning combinations of boxes!

Big Hint: when to check for winner?Check for your winning combinations every time someone could win -- after every move!

Hint: showing a messageTry an `alert`. For an extra challenge, put a message directly onto the page using jQuery!

Submission