-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added score calculation and timer
- Loading branch information
1 parent
8a31d4c
commit b4464dd
Showing
34 changed files
with
229 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
import { Colors } from '../theme'; | ||
|
||
export const ElapsedTimeStyles = StyleSheet.create({ | ||
container: { | ||
alignItems: 'center', | ||
flex: 1, | ||
justifyContent: 'center' | ||
}, | ||
text: { | ||
color: Colors.black | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { differenceInSeconds, format, setMinutes, setSeconds } from 'date-fns'; | ||
import { useEffect, useState } from 'react'; | ||
import { Text, View } from 'react-native'; | ||
|
||
import { ElapsedTimeStyles as styles } from './elapsed-time.styles'; | ||
|
||
const getElapsedTime = (start: Date) => (end: Date) => { | ||
const currentTime = new Date(); | ||
|
||
const remainingSeconds = differenceInSeconds(end, start); | ||
const minutes = Math.floor(remainingSeconds / 60); | ||
const seconds = remainingSeconds % 60; | ||
|
||
return format(setMinutes(setSeconds(currentTime, seconds), minutes), 'mm:ss'); | ||
}; | ||
|
||
interface Props { | ||
startedAt: Date; | ||
} | ||
|
||
export const ElapsedTime = ({ startedAt }: Props) => { | ||
const [currentTime, setCurrentTime] = useState(new Date()); | ||
const elapsedFormatted = getElapsedTime(startedAt); | ||
|
||
useEffect(() => { | ||
const handle = setInterval(() => setCurrentTime(new Date()), 1000); | ||
|
||
return () => clearTimeout(handle); | ||
}, []); | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.text}>({elapsedFormatted(currentTime)})</Text> | ||
</View> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const FieldSizeConstant = 9; | ||
export const FieldCellCountConstant = FieldSizeConstant * FieldSizeConstant; | ||
export const FieldGroupSizeConstant = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export const ScoreCorrectValueConstant = 500; | ||
export const ScoreElapsedCoefficientConstant = 0.001; | ||
export const ScoreMistakesCoefficientConstant = 0.05; | ||
export const ScoreLastInRowCoefficientConstant = 2; | ||
export const ScoreLastInColCoefficientConstant = 3; | ||
export const ScoreLastInGroupCoefficientConstant = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { type CellInterface } from './cell.interface'; | ||
|
||
export type FieldInterface = CellInterface[][]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.