Code Monkey home page Code Monkey logo

react-changing-state-lab-web-0217's Introduction

React Changing State Lab

Overview

In this lab, you'll implement a Tic Tac Toe game where you will respond to state changes in React amd rendering React components.

Tic-tac-toe

One upon a time, long before Virtual Reality, Pokemon Go and World of Warcraft, people used to play games on "physical" paper with "real" pencils. One of those games was Tic-tac-toe.

TicTacToe

Tic-tac-toe is a really simple paper-and-pencil game for two players. Each turn, one of the players (X or O) marks a space in a 3x3 grid. The first player to place three marks in a vertical, horizontal, or diagonal row wins.

In this lab we're going to implement such a game. Our app should allow us to place Xs and Os on the playing field. Once a player succeeds by placing three of their marks in a row, an alert should appear and the playing field should be reset.

This is how our final application is going to look like:

Final

There are four different components:

Game.js

The game component represents the application as a whole. It is the only stateful component. The initial state of the Game component should encode the following information:

  • board, e.g. [null, 'x', null, null, null, null, null, null, null]

    The board state represents the current state of the Tic Tac Toe game. Each item in the array stands for one field. null means a player can mark the field, X means the X player marked the field etc.

  • turn, e.g. X or O.

    If turn is X, then it's currently X's turn. If turn is O, then it's currently O's turn.

Board.js

The board component is a pure component. It consists of exactly nine Fields and accepts the board prop. It renders the actual Tic Tac Toe board.

Status.js

The status component can be seen in the above screenshot as the gray box. It notifies the user about the current state of the game (Tie / X won / O won).

Resources

Credits

  • Tic Tac Toe image by Symode09 โ€” Own work, Public Domain

react-changing-state-lab-web-0217's People

Contributors

alexandergugel avatar thomastuts avatar annjohn avatar aturkewi avatar pletcher avatar

Watchers

James Cloos avatar Katie Burke avatar

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.