Skip to content

Commit 879839a

Browse files
committed
Pontuacao e Verificacao de click
1 parent 5ec26bf commit 879839a

File tree

12 files changed

+149
-2245
lines changed

12 files changed

+149
-2245
lines changed

.vscode/settings.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"spellright.language": "pt",
3+
"spellright.documentTypes": [
4+
"latex",
5+
"plaintext"
6+
]
7+
}

README.md

+5-2,225
Large diffs are not rendered by default.

src/App.js

+77-13
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,114 @@
11
import React, { Component } from "react";
22
import "./assets/style.css";
3+
34
import startImg from "./assets/img/start.svg";
45
import strictImg from "./assets/img/strict.svg";
56

67
import { Point } from "./components/Point";
78
import { Simon } from "./components/Simon";
9+
import { setTime, SOUNDS, playAudio } from "./components/utils";
810

911
class App extends Component {
1012
constructor(props) {
1113
super(props);
1214
this.state = {
1315
ligado: false,
14-
strict: false
16+
strict: false,
17+
listColors: [],
18+
positionColor: 0,
19+
turnColor: "",
20+
point: 0
1521
};
1622
}
1723

18-
ligaDesligaSimon = () => {
19-
this.setState({ ligado: !this.state.ligado });
24+
startGame = () => {
25+
console.log("Start game");
26+
let listColors = Array.from({ length: 20 }, () =>
27+
Math.floor(Math.random() * 4)
28+
);
29+
console.log(listColors);
30+
this.setState(
31+
{
32+
listColors: listColors,
33+
point: 0,
34+
positionColor: 0
35+
},
36+
() => this.turnOn()
37+
);
2038
};
2139

22-
ligaDesligaStrict = () => {
23-
let { ligado, strict } = this.state;
24-
if (ligado) {
25-
this.setState({ strict: !strict });
40+
turnOn = numColor => {
41+
let { positionColor, listColors } = this.state;
42+
let turnColor = listColors[positionColor];
43+
44+
console.log(`position: ${positionColor}`)
45+
console.log(`turnColor: ${turnColor}`)
46+
console.log(`numColor: ${numColor}`)
47+
48+
playAudio(numColor || turnColor);
49+
this.setState(
50+
{
51+
turnColor: numColor || turnColor
52+
},
53+
setTime(() => this.setState({ turnColor: "" }))
54+
);
55+
};
56+
57+
onClickColor = numColor => {
58+
this.turnOn(numColor);
59+
setTime(() => this.verificaColor(numColor))
60+
};
61+
62+
verificaColor = numColor => {
63+
let { positionColor, listColors, strict, point } = this.state;
64+
if (listColors[positionColor] === numColor) {
65+
console.log("It's right");
66+
this.setState(
67+
{
68+
point: point + 1,
69+
positionColor: positionColor + 1
70+
},
71+
this.turnOn(listColors[positionColor + 1])
72+
);
73+
} else {
74+
alert("It's wrong!!");
75+
if (strict) {
76+
this.startGame();
77+
} else {
78+
this.turnOn(listColors[positionColor]);
79+
}
2680
}
2781
};
2882

2983
render() {
30-
let { ligado, strict } = this.state;
84+
let { ligado, strict, turnColor, point } = this.state;
3185

3286
return (
3387
<div className="game">
3488
<div className={`board ${ligado ? "on" : "off"}`}>
35-
<Simon />
89+
<Simon colorTurnOn={turnColor} onClickColor={this.onClickColor} />
90+
91+
<audio id={`audio0`} src={SOUNDS.sound0} />
92+
<audio id={`audio1`} src={SOUNDS.sound1} />
93+
<audio id={`audio2`} src={SOUNDS.sound2} />
94+
<audio id={`audio3`} src={SOUNDS.sound3} />
3695

3796
<div className="menu">
38-
<Point />
97+
<Point value={point} />
3998

4099
<div className="buttons">
41-
<div className="btn-start">
100+
<div
101+
className="btn-start"
102+
onClick={ligado ? this.startGame : () => {}}
103+
>
42104
<img src={startImg} alt="Start" />
43105
<span>START</span>
44106
</div>
45107
<div
46108
className="btn-strict"
47-
onClick={() => this.ligaDesligaStrict()}
109+
onClick={
110+
ligado ? () => this.setState({ strict: !strict }) : () => {}
111+
}
48112
>
49113
<img src={strictImg} alt="Strict" />
50114
STRICT
@@ -54,7 +118,7 @@ class App extends Component {
54118

55119
<div
56120
className={`on-off ${ligado ? "on" : "off"}`}
57-
onClick={() => this.ligaDesligaSimon()}
121+
onClick={() => this.setState({ ligado: !this.state.ligado, strict: false, point: 0})}
58122
/>
59123
</div>
60124
</div>

src/assets/sound/sound1.mp3

1.63 KB
Binary file not shown.

src/assets/sound/sound2.mp3

1.23 KB
Binary file not shown.

src/assets/sound/sound3.mp3

1.28 KB
Binary file not shown.

src/assets/sound/sound4.mp3

1.02 KB
Binary file not shown.

src/assets/style.css

+8
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,29 @@ body {
2121
background-color: #219653;
2222
border-top-left-radius: 100%;
2323
margin-right: -10px; }
24+
.simon .green.on {
25+
background-color: #1d5636; }
2426

2527
.simon .red {
2628
background-color: #EB5757;
2729
border-top-right-radius: 100%; }
30+
.simon .red.on {
31+
background-color: #4f1a1a; }
2832

2933
.simon .yellow {
3034
background-color: #F2C94C;
3135
border-bottom-left-radius: 100%;
3236
margin-right: -10px;
3337
margin-top: -10px; }
38+
.simon .yellow.on {
39+
background-color: #493d17; }
3440

3541
.simon .blue {
3642
background-color: #2D9CDB;
3743
border-bottom-right-radius: 100%;
3844
margin-top: -10px; }
45+
.simon .blue.on {
46+
background-color: #163547; }
3947

4048
.menu {
4149
width: 200px;

src/assets/style.scss

+21
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ $red: #EB5757;
33
$yellow: #F2C94C;
44
$blue: #2D9CDB;
55

6+
$onGreen: #1d5636;
7+
$onRed: #4f1a1a;
8+
$onYellow: #493d17;
9+
$onBlue: #163547;
10+
611
$onImg: url('./img/on.svg');
712
$offImg: url('./img/off.svg');
813

@@ -36,21 +41,37 @@ body {
3641
background-color: $green;
3742
border-top-left-radius: 100%;
3843
margin-right: -10px;
44+
45+
&.on {
46+
background-color: $onGreen;
47+
}
3948
}
4049
.red {
4150
background-color: $red;
4251
border-top-right-radius: 100%;
52+
53+
&.on {
54+
background-color: $onRed;
55+
}
4356
}
4457
.yellow {
4558
background-color: $yellow;
4659
border-bottom-left-radius: 100%;
4760
margin-right: -10px;
4861
margin-top: -10px;
62+
63+
&.on {
64+
background-color: $onYellow;
65+
}
4966
}
5067
.blue {
5168
background-color: $blue;
5269
border-bottom-right-radius: 100%;
5370
margin-top: -10px;
71+
72+
&.on {
73+
background-color: $onBlue;
74+
}
5475
}
5576
}
5677

src/components/Point.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from "react";
22

3-
export const Point = () => (
3+
export const Point = ({value}) => (
44
<div className="point">
5-
<input disabled value="25" type="text" />
5+
<input disabled value={value} type="text" />
66
POINT
77
</div>
88
);

src/components/Simon.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React from "react";
22

3-
export const Simon = () => (
3+
export const Simon = ({colorTurnOn, onClickColor}) => (
44
<div className="simon">
5-
<div className="green" />
6-
<div className="red" />
7-
<div className="yellow" />
8-
<div className="blue" />
5+
<div onClick={() => onClickColor(0)} className={`green ${colorTurnOn === 0 && "on" }`} />
6+
<div onClick={() => onClickColor(1)} className={`red ${colorTurnOn === 1 && "on" }`} />
7+
<div onClick={() => onClickColor(2)} className={`yellow ${colorTurnOn === 2 && "on" }`} />
8+
<div onClick={() => onClickColor(3)} className={`blue ${colorTurnOn === 3 && "on" }`} />
99
</div>
1010
);

src/components/utils.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import sound1 from "../assets/sound/sound1.mp3";
2+
import sound2 from "../assets/sound/sound2.mp3";
3+
import sound3 from "../assets/sound/sound3.mp3";
4+
import sound4 from "../assets/sound/sound4.mp3";
5+
6+
export const SOUNDS = {
7+
sound0: sound1,
8+
sound1: sound2,
9+
sound2: sound3,
10+
sound3: sound4
11+
};
12+
13+
export const setTime = (func, time=2000) => {
14+
setTimeout(() => {
15+
func();
16+
}, time);
17+
}
18+
19+
/* Play sound */
20+
export const playAudio = (num) => {
21+
let audio = document.getElementById(`audio${num}`);
22+
audio.play();
23+
setTime(() => audio.load())
24+
}

0 commit comments

Comments
 (0)