-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
92 lines (76 loc) · 2.62 KB
/
index.html
File metadata and controls
92 lines (76 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>React Memory Game</title>
<link rel="stylesheet" href="style.css" />
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script crossorigin src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
</head>
<body>
<div id="app-container"></div>
</body>
<script type="text/babel">
class MemoryTile extends React.Component {
render() {
console.log("props: ", this.props);
let actualImageSource = "images/blank.png";
if (this.props.isShowing === true) {
actualImageSource = this.props.imageSource;
}
return (
<div className="memory-tile" onClick={this.props.clickCallback}>
<img
src={actualImageSource}
alt="memory tile"
className="memory-tile-image"
/>
</div>
);
}
}
class GameContainer extends React.Component {
constructor() {
super();
this.state = {
memoryTiles: [
{ imageSource: "images/pig.png", isShowing: false },
{ imageSource: "images/pig.png", isShowing: false },
{ imageSource: "images/dog.png", isShowing: false },
{ imageSource: "images/dog.png", isShowing: false },
{ imageSource: "images/cow.png", isShowing: false },
{ imageSource: "images/cow.png", isShowing: false }
]
};
this.tileClicked = this.tileClicked.bind(this);
}
tileClicked(index) {
console.log("tile was clicked in parent!!!");
/* this.setState({
memoryTiles: []
}); */
}
render() {
var memoryTileElements = [];
for (let i = 0; i < this.state.memoryTiles.length; i++) {
let tile = this.state.memoryTiles[i];
memoryTileElements.push(
<MemoryTile
key={i}
imageSource={tile.imageSource}
isShowing={tile.isShowing}
clickCallback={this.tileClicked}
/>
);
}
console.log(memoryTileElements);
return <div id="game-container">{memoryTileElements}</div>;
}
}
ReactDOM.render(<GameContainer />, document.getElementById("app-container")
);
</script>
</html>