Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Game 3 #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
9 changes: 6 additions & 3 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react';
import ColorGame from './components/color_game/color_game';
import OrderClick from './components/OrderClick/OrderClick';
import ColorGame from './components/color_game/color_game'
import ColorMatch from './components/ColorMatch/ColorMatch'
import OrderClick from './components/OrderClick/OrderClick'

function App() {
return (
<div className="App">
{/* Todo: Add routes here */}
{/* {<ColorGame></ColorGame>} */}
<OrderClick> </OrderClick>
{/* <OrderClick> </OrderClick> */}
<ColorMatch />
</div>
);
}
Expand Down
25 changes: 25 additions & 0 deletions src/components/ColorMatch/ColorMatch.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.box {
width: 5rem;
height: 3rem;
font-size: 2rem;
}

.font-yellow {
color: yellow;
}

.font-green {
color: green;
}

.font-blue {
color: blue;
}

.font-pink {
color: pink;
}

.font-orange {
color: orange;
}
29 changes: 29 additions & 0 deletions src/components/ColorMatch/ColorMatch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useEffect, useState } from 'react'
import { COLORS } from '../utils/utils'
import './ColorMatch.css'

const ColorMatch = () => {

const [name, setName] = useState(COLORS[Math.floor(Math.random() * (COLORS.length-1))])
const [color, setColor] = useState(COLORS[Math.floor(Math.random() * (COLORS.length-1))])

useEffect(() => {
const timer = setInterval(
() => {
setName(COLORS[Math.floor(Math.random() * (COLORS.length-1))])
setColor(COLORS[Math.floor(Math.random() * (COLORS.length-1))])
},
1000)
return () => clearInterval(timer)
},[])

const check = () => {
console.log(name, color)
}

return <div onClick={()=>{check()}} className={`box font-${color}`}>
{name}
</div>
}

export default ColorMatch
6 changes: 2 additions & 4 deletions src/components/color_game/color_game.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, { Component } from 'react';
import { COLORS } from '../utils/utils'
import './color_game.css';

const colors = ["yellow", "green", "blue", "pink", "orange"];


class ColorGame extends Component {
constructor(props) {
super(props);
Expand All @@ -23,7 +21,7 @@ class ColorGame extends Component {

setTimeout(() => {
this.setState({
classes: colors[this.state.index],
classes: COLORS[this.state.index],
start_time: new Date()
});
this.setState(prevstate => ({ index: prevstate.index + 1}));
Expand Down
7 changes: 7 additions & 0 deletions src/components/utils/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const shuffle = arr => arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1]);


export const COLORS = ["yellow", "green", "blue", "pink", "orange"];