Added Game Over Screen
parent
9d7cf30061
commit
94955ad7c3
|
@ -15,12 +15,11 @@ class MyApp extends StatelessWidget {
|
|||
|
||||
final int gridSize = 8;
|
||||
|
||||
// This widget is the root of your application.
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'Bubble-Twist',
|
||||
debugShowCheckedModeBanner: false, // This removes the debug banner
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||
useMaterial3: true,
|
||||
|
@ -33,15 +32,6 @@ class MyApp extends StatelessWidget {
|
|||
class MyHomePage extends StatefulWidget {
|
||||
const MyHomePage({super.key, required this.title, required this.gridSize});
|
||||
|
||||
// This widget is the home page of your application. It is stateful, meaning
|
||||
// that it has a State object (defined below) that contains fields that affect
|
||||
// how it looks.
|
||||
|
||||
// This class is the configuration for the state. It holds the values (in this
|
||||
// case the title) provided by the parent (in this case the App widget) and
|
||||
// used by the build method of the State. Fields in a Widget subclass are
|
||||
// always marked "final".
|
||||
|
||||
final String title;
|
||||
final int gridSize;
|
||||
|
||||
|
@ -55,6 +45,7 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
int _score = 0;
|
||||
int _time = 0;
|
||||
StoneLocation? sl1;
|
||||
bool _isGameOver = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
|
@ -77,7 +68,11 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
],
|
||||
),
|
||||
body: Center(
|
||||
child: game.running ? _buildGameGrid() : _buildStartButton(),
|
||||
child: _isGameOver
|
||||
? _buildGameOverMessage()
|
||||
: game.running
|
||||
? _buildGameGrid()
|
||||
: _buildStartButton(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
@ -93,6 +88,31 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
);
|
||||
}
|
||||
|
||||
Widget _buildGameOverMessage() {
|
||||
return Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text(
|
||||
'Game Over',
|
||||
style: TextStyle(fontSize: 32, fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(
|
||||
'Final Score: $_score',
|
||||
style: const TextStyle(fontSize: 24),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
_isGameOver = false;
|
||||
game.start();
|
||||
},
|
||||
child: const Text('Restart'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildGameGrid() {
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -171,7 +191,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
}
|
||||
|
||||
Color _getColorForStone(Stone? stone) {
|
||||
// Beispielhafte Farben basierend auf dem Stein.
|
||||
switch (stone?.getStoneColor()) {
|
||||
case StoneColors.red:
|
||||
return Colors.red;
|
||||
|
@ -190,7 +209,9 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
|
||||
@override
|
||||
void gameStopped() {
|
||||
// TODO: implement gameStopped
|
||||
setState(() {
|
||||
_isGameOver = true;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -201,7 +222,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
|||
@override
|
||||
void updateStones() {
|
||||
setState(() {
|
||||
// _grid aktualisieren
|
||||
for (int row = 0; row < widget.gridSize; row++) {
|
||||
for (int col = 0; col < widget.gridSize; col++) {
|
||||
_grid[row][col] = game.getStone(StoneLocation(row: row, column: col));
|
||||
|
|
Loading…
Reference in New Issue