Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 07week/ticTacToe/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.23.1/babel.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/react/15.5.0/react-dom.js"></script>
<script type="text/babel" src="./script.js"></script>
<script type="text/babel" src="./script2.js"></script>
</body>
</html>
98 changes: 88 additions & 10 deletions 07week/ticTacToe/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,107 @@
class TicTacToe extends React.Component {
constructor(props) {
super(props);
this.state = {
values: [
'', '', '', '', '', '', '', '', ''
],
}
this.winState = [
//Horizontal Win
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
//Verticle Win
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
//Diagonal Win
[0, 4, 8],
[2, 4, 6]
]
this.player = ""
}

render() {

return (
<div>
<div id='status'>Time to start, X goes first</div>
<div className="row">
<div data-cell="0"></div>
<div data-cell="1"></div>
<div data-cell="2"></div>
<div id='square0' className='sqaure' onClick={() => this.createPlayer(0)} data-cell='0'>{this.state.values[0]}</div>
<div id='square1' className='sqaure' onClick={() => this.createPlayer(1)} data-cell='1'>{this.state.values[1]}</div>
<div id='square2' className='sqaure' onClick={() => this.createPlayer(2)} data-cell='2'>{this.state.values[2]}</div>
</div>
<div className="row">
<div data-cell="3"></div>
<div data-cell="4"></div>
<div data-cell="5"></div>
<div id='square3' className='sqaure' onClick={() => this.createPlayer(3)} data-cell='3'>{this.state.values[3]}</div>
<div id='square4' className='sqaure' onClick={() => this.createPlayer(4)} data-cell='4'>{this.state.values[4]}</div>
<div id='square5' className='sqaure' onClick={() => this.createPlayer(5)} data-cell='5'>{this.state.values[5]}</div>
</div>
<div className="row">
<div data-cell="6"></div>
<div data-cell="7"></div>
<div data-cell="8"></div>
<div id='square6' className='sqaure' onClick={() => this.createPlayer(6)} data-cell='6'>{this.state.values[6]}</div>
<div id='square7' className='sqaure' onClick={() => this.createPlayer(7)} data-cell='7'>{this.state.values[7]}</div>
<div id='square8' className='sqaure' onClick={() => this.createPlayer(8)} data-cell='8'>{this.state.values[8]}</div>
</div>
</div>
);
}

status() {
let statusBar = document.getElementById('status')
if(this.player === ''){
statusBar.innerText = "It is O's turn"
}else{
statusBar.innerText = "It is " + this.player + "'s turn"
}
}

playerTurn() {
if (this.player === 'X') {
this.player = 'O'
} else {
this.player = 'X'
}
return this.player
}
createPlayer(num) {
let squareValue = document.getElementById('square' + num)
if (squareValue.innerHTML === '') {
this.status()
this.playerTurn()
squareValue.innerText = this.player
this.checkWinner()
}
}
checkWinner() {
for (let i = 0; i < this.winState.length; i++) {

let xWin = 0
let oWin = 0

for (let x = 0; x < this.winState[i].length; x++){

let position = this.winState[i][x];
let square = document.getElementById('square' + position).innerHTML

if(square === "X"){
xWin = xWin +1
if(xWin === 3){
console.log("X WINS")
document.getElementById('status').innerText = "X Wins"
}

}else if(square === "O"){
oWin = oWin + 1
if(oWin === 3){
console.log("O WINS")
document.getElementById('status').innerText = "O Wins"
}
}
}
}
}

}

ReactDOM.render(<TicTacToe />, document.getElementById('tic-tac-toe'));

ReactDOM.render(<TicTacToe />, document.getElementById('tic-tac-toe'));
135 changes: 135 additions & 0 deletions 07week/ticTacToe/script2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
'use strict';

class TicTacToe extends React.Component {
constructor(props) {
super(props);

this.state = {
playValue : ['', '', '', '', '', '', '', '', ''],
player: 'X',
winner: ''
}

this.winState = [
//Horizontal Win
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
//Verticle Win
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
//Diagonal Win
[0, 4, 8],
[2, 4, 6]
]
}

createBoard(i){
return(
<div
id={'square'+i}
className='sqaure'
onClick={() => this.playChecker(i)}
data-cell='0'>
{this.state.playValue[i]}
</div>
)
}

status() {
let statusBar = document.getElementById('status')
if(this.state.player === ''){
statusBar.innerText = "It is O's turn"
}else{
statusBar.innerText = "It is " + this.state.player + "'s turn"
}
}

playerTurn() {
if (this.state.player === 'X') {
this.setState({player: 'O'})
} else {
this.setState({player: 'X'})
}
return this.state.player
}

checkWinner() {
for (let i = 0; i < this.winState.length; i++) {

let xWin = 0
let oWin = 0

for (let x = 0; x < this.winState[i].length; x++){

let position = this.winState[i][x];
// let square = document.getElementById('square' + position).innerHTML
let square = this.state.playValue[position]
if(square === "X"){
xWin = xWin + 1

if(xWin === 3){
this.setState({winner: 'X'})
document.getElementById('status').innerText = "X is the Winner"
}

}else if(square === "O"){
oWin = oWin + 1
if(oWin === 3){
this.setState({winner: 'O'})
document.getElementById('status').innerText = "O is the Winner"
}
}
}
}
}

playChecker(num) {
let squareValue = this.state.playValue[num]
if (squareValue === '') {
this.playerTurn()
this.status()

let newPlayValue = this.state.playValue.slice()
newPlayValue[num] = this.state.player
this.setState({playValue: newPlayValue},()=> this.checkWinner(this.state.playValue))
//this.setState(()=>{return{playValue: newPlayValue}})
//this.checkWinner()
}
}

clearBoard(){
console.log(this.state.playValue)
let newPlayValue = ['', '', '', '', '', '', '', '', '']
this.setState({playValue: newPlayValue})
this.setState({player: 'X'})
document.getElementById('status').innerText = "Time to start, X goes first"
}

render() {
return (
<div>
<div id='status' className='header/footer'>Time to start, X goes first</div>
<div className='row'>
{this.createBoard(0)}
{this.createBoard(1)}
{this.createBoard(2)}
</div>
<div className='row'>
{this.createBoard(3)}
{this.createBoard(4)}
{this.createBoard(5)}
</div>
<div className='row'>
{this.createBoard(6)}
{this.createBoard(7)}
{this.createBoard(8)}
</div>
<div id="clear" className='headerfooter' onClick={()=> this.clearBoard()}>Clear Board</div>
</div>
);
}
}

ReactDOM.render(<TicTacToe />, document.getElementById('tic-tac-toe'));
19 changes: 19 additions & 0 deletions 07week/ticTacToe/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,22 @@ div[data-cell] {
clear: both;
font-size: 50px;
}

#status{
font-size: 25pt;
font-weight: bolder
}

#clear{
display: block;
font-weight: bolder;
max-width: 150px;
min-height: 30px;
margin-left: 75px;
margin-top: 110px;
padding-top: 5px;
cursor: pointer;
text-align: center;
background-color: darkslategrey;
color: #f2f2f2
}
23 changes: 23 additions & 0 deletions 08week/checkers-react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
68 changes: 68 additions & 0 deletions 08week/checkers-react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).

## Available Scripts

In the project directory, you can run:

### `npm start`

Runs the app in the development mode.<br>
Open [http://localhost:3000](http://localhost:3000) to view it in the browser.

The page will reload if you make edits.<br>
You will also see any lint errors in the console.

### `npm test`

Launches the test runner in the interactive watch mode.<br>
See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information.

### `npm run build`

Builds the app for production to the `build` folder.<br>
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.<br>
Your app is ready to be deployed!

See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information.

### `npm run eject`

**Note: this is a one-way operation. Once you `eject`, you can’t go back!**

If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

## Learn More

You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started).

To learn React, check out the [React documentation](https://reactjs.org/).

### Code Splitting

This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting

### Analyzing the Bundle Size

This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size

### Making a Progressive Web App

This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app

### Advanced Configuration

This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration

### Deployment

This section has moved here: https://facebook.github.io/create-react-app/docs/deployment

### `npm run build` fails to minify

This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify
Loading