Skip to content

Commit fc7853b

Browse files
committed
feat: add timer to measure gameplay time
1 parent 535f63d commit fc7853b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"Number-Guessing/internal/helper"
55
"fmt"
66
"strconv"
7+
"time"
78
)
89

910
func main() {
@@ -31,6 +32,7 @@ func main() {
3132
randomNumber := helper.RandomNumberGenerator()
3233
attempts := 0
3334
chances := helper.GetChancesForLevel(selectedLevel)
35+
startTime := time.Now()
3436
for {
3537
fmt.Println()
3638
fmt.Printf("Enter your guess: ")
@@ -54,6 +56,7 @@ func main() {
5456
}
5557
if guessedNumber == randomNumber {
5658
fmt.Printf("Congratulations! You guessed the correct number in %d attempts\n", attempts)
59+
fmt.Printf("You took %v time\n", time.Since(startTime).Truncate(time.Second))
5760
break
5861
}
5962
if chances > 0 {
@@ -65,6 +68,7 @@ func main() {
6568
continue
6669
} else {
6770
fmt.Println("Game Over! You have used all the attempts")
71+
fmt.Printf("You took %v time\n", time.Since(startTime).Truncate(time.Second))
6872
}
6973
break
7074
}

0 commit comments

Comments
 (0)