Tic-tac-toe React
How do I make an tic-tac-toe react?
What is a tic-tac-toe react? How do you make a tic-tac-toe react? This script and codes were developed by Yas on 05 January 2023, Thursday.
Tic-tac-toe React - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>tic-tac-toe React</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div id="board"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/react/15.4.2/react-dom.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Tic-tac-toe React - Script Codes CSS Codes
#board { display: flex; flex-basis: 406px; height: 390px; flex-direction: row; flex-wrap: wrap; justify-content: flex-start; margin: 60px auto;
}
.square { display: flex; flex-basis: 130px; font-size: 100px; font-family: arial; justify-content: center; align-items: center;
}
.square:hover { background-color: #c4f8fa; cursor: pointer;
}
#s1 { border-right: 4px solid; border-bottom: 4px solid; border-color: #477076;
}
#s2 { border-left: 4px solid; border-right: 4px solid; border-bottom: 4px solid; border-color: #477076;
}
#s3 { border-left: 4px solid; border-bottom: 4px solid; border-color: #477076;
}
#s4 { border-right: 4px solid; border-top: 4px solid; border-bottom: 4px solid; border-color: #477076;
}
#s5 { border: 4px solid; border-color: #477076;
}
#s6 { border-left: 4px solid; border-top: 4px solid; border-bottom: 4px solid; border-color: #477076;
}
#s7 { border-right: 4px solid; border-top: 4px solid; border-color: #477076;
}
#s8 { border-left: 4px solid; border-right: 4px solid; border-top: 4px solid; border-color: #477076;
}
#s9 { border-left: 4px solid; border-top: 4px solid; border-color: #477076;
}
.blue { color: #08507d;
}
.red { color: #ec574e;
}
Tic-tac-toe React - Script Codes JS Codes
"use strict";
var TicTacToe = React.createClass({ displayName: "TicTacToe", getInitialState: function getInitialState() { return { PLAYER_ONE_SYMBOL: "X", PLAYER_TWO_SYMBOL: "O", currentTurn: "X", writeMark: "X", X_CLASS: "square blue", O_CLASS: "square red", boardArr: ["", "", "", "", "", "", "", "", "", ""], colorArr: ["square", "square", "square", "square", "square", "square", "square", "square", "square"] }; }, switchTurn: function switchTurn() { var currentTurn = this.state.currentTurn == this.state.PLAYER_ONE_SYMBOL ? this.state.PLAYER_TWO_SYMBOL : this.state.PLAYER_ONE_SYMBOL; this.setState({ currentTurn: currentTurn }); }, clearBoard: function clearBoard() { console.log("reset"); this.state.boardArr = this.state.boardArr.map(function () { return " "; }); this.state.colorArr = this.state.colorArr.map(function () { return "square"; }); this.setState({ boardArr: this.state.boardArr, colorArr: this.state.colorArr }); }, resetGame: function resetGame() { console.log("reset"); this.state.boardArr = this.state.boardArr.map(function () { return " "; }); this.state.colorArr = this.state.colorArr.map(function () { return "square"; }); this.setState({ boardArr: this.state.boardArr }); }, checkWinner: function checkWinner() { var mark = this.state.boardArr; if (mark[0] != "" && mark[0] == mark[1] && mark[0] == mark[2]) { this.resetGame(); return mark[0]; } else if (mark[3] != "" && mark[3] == mark[4] && mark[3] == mark[5]) { this.resetGame(); return mark[4]; } else if (mark[6] != "" && mark[6] == mark[7] && mark[6] == mark[8]) { this.resetGame(); return mark[4]; } else if (mark[0] != "" && mark[0] == mark[3] && mark[0] == mark[6]) { this.resetGame(); return mark[4]; } else if (mark[1] != "" && mark[1] == mark[4] && mark[1] == mark[7]) { this.resetGame(); return mark[4]; } else if (mark[2] != "" && mark[2] == mark[5] && mark[2] == mark[8]) { this.resetGame(); return mark[4]; } else if (mark[0] != "" && mark[0] == mark[4] && mark[0] == mark[8]) { this.resetGame(); return mark[4]; } else if (mark[2] != "" && mark[2] == mark[4] && mark[2] == mark[6]) { this.resetGame(); return mark[4]; } }, clickHandler: function clickHandler(i) { if (this.state.boardArr[i] == "") { this.state.boardArr[i] = this.state.currentTurn; this.setState({ boardArr: this.state.boardArr }); this.state.colorArr[i] = this.state.boardArr[i] == this.state.PLAYER_ONE_SYMBOL ? this.state.X_CLASS : this.state.O_CLASS; this.setState({ colorArr: this.state.colorArr }); this.switchTurn(); this.checkWinner(); this.render(); } }, render: function render() { var _this = this; return React.createElement( "div", { id: "board" }, this.state.boardArr.map(function (square, index) { var i = index + 1; return React.createElement( "div", { onClick: _this.clickHandler.bind(_this, index), className: _this.state.colorArr[index], id: "s" + i }, square ); }) ); }
});
ReactDOM.render(React.createElement(TicTacToe, null), document.getElementById('board'));
Developer | Yas |
Username | Yas46 |
Uploaded | January 05, 2023 |
Rating | 3 |
Size | 3,512 Kb |
Views | 8,096 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Browser Calculator | 2,846 Kb |
TicTacToe | 1,674 Kb |
Quote Machine | 3,625 Kb |
Twitch Streamers | 2,772 Kb |
Tic-tac-toe | 3,730 Kb |
Weather | 3,186 Kb |
Pomodoro Clock | 3,328 Kb |
A Pen by Yas | 4,042 Kb |
Wikipedia Search | 2,746 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Scrolling Horizontal Isotope | Bramus | 2,017 Kb |
Starfield using KineticJS | Asp | 3,512 Kb |
Drag in vanilla js using dotval math instead of translate | Paulq | 2,662 Kb |
Pattern lab logo | TimPietrusky | 3,666 Kb |
CSS Org Chart | Appirio-ux | 3,882 Kb |
Subscription Newsletter - Before inlining | Bradstrong | 7,526 Kb |
Scroll to top button | DominicFrancois | 3,743 Kb |
Two joint circles - One element | Berdejitendra | 1,704 Kb |
Custom Checkbox and radio inputs SCSS | Rgfx | 3,367 Kb |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!