@@ -16,6 +16,7 @@ class _GameScreenState extends State<GameScreen> {
16
16
int _timeLeft = 20 ; // Time left in seconds
17
17
late Timer _timer;
18
18
bool _gameLoaded = false ; // Tracks if the game is loaded
19
+ bool _gameOver = false ; // Tracks if the game is over
19
20
20
21
@override
21
22
void initState () {
@@ -29,9 +30,12 @@ class _GameScreenState extends State<GameScreen> {
29
30
(Timer timer) {
30
31
if (_progress <= 0 || _timeLeft <= 0 ) {
31
32
timer.cancel ();
33
+ setState (() {
34
+ _gameOver = true ;
35
+ });
32
36
} else {
33
37
setState (() {
34
- _progress -= 0.05 ;
38
+ _progress -= 1 / 20 ; // Decrease progress based on total time
35
39
_timeLeft -= 1 ;
36
40
});
37
41
}
@@ -64,53 +68,90 @@ class _GameScreenState extends State<GameScreen> {
64
68
appBar: AppBar (
65
69
title: const Header (title: 'Quiz Game' ),
66
70
),
67
- body: Column (
71
+ body: Stack (
68
72
children: < Widget > [
69
- Padding (
70
- padding: const EdgeInsets .all (16.0 ),
71
- child: Row (
72
- mainAxisAlignment: MainAxisAlignment .spaceBetween,
73
- children: < Widget > [
74
- Expanded (
75
- child: SizedBox (
76
- height: 20 , // Make the progress bar thicker
77
- child: TweenAnimationBuilder (
78
- tween: Tween <double >(begin: 1.0 , end: _progress),
79
- duration: const Duration (milliseconds: 500 ),
80
- builder: (context, value, child) {
81
- return LinearProgressIndicator (
82
- value: value,
83
- backgroundColor: Colors .grey[300 ],
84
- color: Colors .blue,
85
- );
86
- },
87
- ),
88
- ),
89
- ),
90
- const SizedBox (width: 20 ),
91
- Column (
92
- crossAxisAlignment: CrossAxisAlignment .end,
73
+ Column (
74
+ children: < Widget > [
75
+ Padding (
76
+ padding: const EdgeInsets .all (16.0 ),
77
+ child: Row (
78
+ mainAxisAlignment: MainAxisAlignment .spaceBetween,
93
79
children: < Widget > [
94
- Text (
95
- 'Score: $_score ' ,
96
- style: const TextStyle (
97
- fontSize: 24 , fontWeight: FontWeight .bold),
80
+ Expanded (
81
+ child: Container (
82
+ decoration: BoxDecoration (
83
+ color: Colors .blue.shade700, // Dark blue background
84
+ borderRadius: BorderRadius .circular (20.0 ),
85
+ boxShadow: < BoxShadow > [
86
+ BoxShadow (
87
+ color: Colors .black.withOpacity (0.2 ),
88
+ spreadRadius: 2 ,
89
+ blurRadius: 4 ,
90
+ offset: const Offset (0 , 2 ), // Shadow position
91
+ ),
92
+ ],
93
+ ),
94
+ height: 30 , // Make the progress bar thicker
95
+ child: ClipRRect (
96
+ borderRadius: BorderRadius .circular (20.0 ),
97
+ child: TweenAnimationBuilder (
98
+ tween: Tween <double >(begin: 1.0 , end: _progress),
99
+ duration: const Duration (milliseconds: 500 ),
100
+ builder: (BuildContext context, double value,
101
+ Widget ? child) {
102
+ return LinearProgressIndicator (
103
+ value: value,
104
+ backgroundColor: Colors .grey[300 ],
105
+ color: Colors .blue,
106
+ );
107
+ },
108
+ ),
109
+ ),
110
+ ),
98
111
),
99
- Text (
100
- 'Time Left: $_timeLeft s' ,
101
- style: const TextStyle (fontSize: 16 ),
112
+ const SizedBox (width: 20 ),
113
+ Column (
114
+ crossAxisAlignment: CrossAxisAlignment .end,
115
+ children: < Widget > [
116
+ Text (
117
+ 'Score: $_score ' ,
118
+ style: const TextStyle (
119
+ fontSize: 24 , fontWeight: FontWeight .bold),
120
+ ),
121
+ const SizedBox (height: 5 ),
122
+ Text (
123
+ 'Time Left: $_timeLeft s' ,
124
+ style: const TextStyle (fontSize: 16 ),
125
+ ),
126
+ ],
102
127
),
103
128
],
104
129
),
105
- ],
106
- ),
130
+ ),
131
+ Expanded (
132
+ child: GameWrapper (
133
+ onLoaded: onGameLoaded,
134
+ onScoreUpdate: updateScore,
135
+ ),
136
+ ),
137
+ ],
107
138
),
108
- Expanded (
109
- child: GameWrapper (
110
- onLoaded: onGameLoaded,
111
- onScoreUpdate: updateScore,
139
+ if (_gameOver)
140
+ Positioned .fill (
141
+ child: Container (
142
+ color: Colors .grey.withOpacity (0.7 ),
143
+ child: const Center (
144
+ child: Text (
145
+ 'Game Over!' ,
146
+ style: TextStyle (
147
+ fontSize: 40 ,
148
+ fontWeight: FontWeight .bold,
149
+ color: Colors .white,
150
+ ),
151
+ ),
152
+ ),
153
+ ),
112
154
),
113
- ),
114
155
],
115
156
),
116
157
);
@@ -127,7 +168,7 @@ class GameWrapper extends StatelessWidget {
127
168
@override
128
169
Widget build (BuildContext context) {
129
170
// Simulate a delay for loading the game
130
- Future .delayed (const Duration (seconds: 2 ), onLoaded);
171
+ Future .delayed (const Duration (seconds: 4 ), onLoaded);
131
172
132
173
return const Center (
133
174
child: SelectTheAreaGame (),
0 commit comments