-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
44 lines (40 loc) · 1.17 KB
/
App.js
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
import React from "react";
import { SafeAreaView, StyleSheet } from "react-native";
import { Board } from "./src/components/Board";
import { Controller } from "./src/components/Controller";
import { use2048 } from "./src/hooks/use2048";
import { Direction } from "./src/types/Direction";
import { Header } from "./src/components/Header";
import { GameOverModal } from "./src/components/GameOverModal";
const App = () => {
const {
cells,
newMove,
isGameOverModalVisible,
hideGameOverModal,
score,
} = use2048();
const getClickHandler = (direction) => () => newMove(direction);
return (
<SafeAreaView style={styles.container}>
<Header score={score} />
<Board cells={cells} />
<Controller
onClickDown={getClickHandler(Direction.Down)}
onClickUp={getClickHandler(Direction.Up)}
onClickLeft={getClickHandler(Direction.Left)}
onClickRight={getClickHandler(Direction.Right)}
/>
<GameOverModal
visible={isGameOverModalVisible}
onCloseButtonPressed={hideGameOverModal}
/>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
},
});
export default App;