-
Notifications
You must be signed in to change notification settings - Fork 1
/
SudokuPage.tsx
121 lines (109 loc) · 3.66 KB
/
SudokuPage.tsx
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import React from "react";
import { StyleSheet, View } from "react-native";
import SudokuBoard from "../Components/Sudoku Board/SudokuBoard";
import { StatusBar } from "expo-status-bar";
import { SafeAreaProvider, SafeAreaView } from "react-native-safe-area-context";
import Header from "../Components/Header";
import Alert from "react-native-awesome-alerts";
import { useTheme } from "react-native-paper";
import EndGameModal from "../Components/Sudoku Board/EndGameModal";
import { rgba } from "polished";
import { sudokuStrategyArray } from "sudokuru";
// startGame - https://www.npmjs.com/package/sudokuru#:~:text=sudokuru.Puzzles%3B-,Puzzles.startGame(),-Description%3A%20Returns%20puzzle
let strategies: sudokuStrategyArray = [
"AMEND_NOTES",
"SIMPLIFY_NOTES",
"NAKED_SINGLE",
"NAKED_PAIR",
"NAKED_TRIPLET",
"NAKED_QUADRUPLET",
"HIDDEN_SINGLE",
"HIDDEN_PAIR",
"HIDDEN_TRIPLET",
"HIDDEN_QUADRUPLET",
"POINTING_PAIR",
"POINTING_TRIPLET",
];
const SudokuPage = ({ route, navigation }: any) => {
const { gameType } = route.params;
const { difficulty } = route.params;
const theme = useTheme();
const [gameResultsVisible, setGameResultsVisible] = React.useState(false);
const [gameResultScore, setGameResultScore] = React.useState(0);
const [gameResultTime, setGameResultTime] = React.useState(0);
const [gameResultNumHintsUsed, setGameResultNumHintsUsed] = React.useState(0);
const [gameResultNumWrongCellsPlayed, setGameResultNumWrongCellsPlayed] =
React.useState(0);
const [gameResultPuzzleDifficulty, setGameResultPuzzleDifficulty] =
React.useState(0);
const showGameResults = (
score: number,
time: number,
numHintsUsed: number,
numWrongCellsPlayed: number,
puzzleDifficulty: number
) => {
setGameResultScore(score);
setGameResultTime(time);
setGameResultNumHintsUsed(numHintsUsed);
setGameResultNumWrongCellsPlayed(numWrongCellsPlayed);
setGameResultPuzzleDifficulty(puzzleDifficulty);
};
// we show the game results if time does not equal zero and on score change
React.useEffect(() => {
if (gameResultTime != 0) {
setGameResultsVisible(true);
}
}, [gameResultTime]);
return (
<SafeAreaProvider>
<SafeAreaView>
<View style={homeScreenStyles.home}>
<View style={styles.statisticsTitle}>
{/* The game now required the info about it to be rendered, which is given in generateGame() */}
<SudokuBoard
gameType={gameType}
difficulty={difficulty}
strategies={strategies}
navigation={navigation}
showGameResults={showGameResults}
/>
<StatusBar style="auto" />
</View>
</View>
<Alert
show={gameResultsVisible}
closeOnTouchOutside={false}
closeOnHardwareBackPress={false}
customView={
<EndGameModal
score={gameResultScore}
time={gameResultTime}
numHintsUsed={gameResultNumHintsUsed}
numWrongCellsPlayed={gameResultNumWrongCellsPlayed}
difficulty={gameResultPuzzleDifficulty}
></EndGameModal>
}
alertContainerStyle={{
backgroundColor: rgba(theme.colors.background, 0.3),
}}
overlayStyle={{ backgroundColor: "transparent" }}
/>
</SafeAreaView>
</SafeAreaProvider>
);
};
const styles = StyleSheet.create({
statisticsTitle: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
});
const homeScreenStyles = StyleSheet.create({
home: {
display: "flex",
flexDirection: "row",
},
});
export default SudokuPage;