Added Game Over Screen
parent
9d7cf30061
commit
94955ad7c3
|
@ -15,12 +15,11 @@ class MyApp extends StatelessWidget {
|
||||||
|
|
||||||
final int gridSize = 8;
|
final int gridSize = 8;
|
||||||
|
|
||||||
// This widget is the root of your application.
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return MaterialApp(
|
return MaterialApp(
|
||||||
title: 'Bubble-Twist',
|
title: 'Bubble-Twist',
|
||||||
debugShowCheckedModeBanner: false, // This removes the debug banner
|
debugShowCheckedModeBanner: false,
|
||||||
theme: ThemeData(
|
theme: ThemeData(
|
||||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
|
@ -33,15 +32,6 @@ class MyApp extends StatelessWidget {
|
||||||
class MyHomePage extends StatefulWidget {
|
class MyHomePage extends StatefulWidget {
|
||||||
const MyHomePage({super.key, required this.title, required this.gridSize});
|
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 String title;
|
||||||
final int gridSize;
|
final int gridSize;
|
||||||
|
|
||||||
|
@ -55,6 +45,7 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
int _score = 0;
|
int _score = 0;
|
||||||
int _time = 0;
|
int _time = 0;
|
||||||
StoneLocation? sl1;
|
StoneLocation? sl1;
|
||||||
|
bool _isGameOver = false;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
|
@ -77,7 +68,11 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Center(
|
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() {
|
Widget _buildGameGrid() {
|
||||||
return Column(
|
return Column(
|
||||||
children: [
|
children: [
|
||||||
|
@ -171,7 +191,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
}
|
}
|
||||||
|
|
||||||
Color _getColorForStone(Stone? stone) {
|
Color _getColorForStone(Stone? stone) {
|
||||||
// Beispielhafte Farben basierend auf dem Stein.
|
|
||||||
switch (stone?.getStoneColor()) {
|
switch (stone?.getStoneColor()) {
|
||||||
case StoneColors.red:
|
case StoneColors.red:
|
||||||
return Colors.red;
|
return Colors.red;
|
||||||
|
@ -190,7 +209,9 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void gameStopped() {
|
void gameStopped() {
|
||||||
// TODO: implement gameStopped
|
setState(() {
|
||||||
|
_isGameOver = true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -201,7 +222,6 @@ class _MyHomePageState extends State<MyHomePage> implements IGameConsumer {
|
||||||
@override
|
@override
|
||||||
void updateStones() {
|
void updateStones() {
|
||||||
setState(() {
|
setState(() {
|
||||||
// _grid aktualisieren
|
|
||||||
for (int row = 0; row < widget.gridSize; row++) {
|
for (int row = 0; row < widget.gridSize; row++) {
|
||||||
for (int col = 0; col < widget.gridSize; col++) {
|
for (int col = 0; col < widget.gridSize; col++) {
|
||||||
_grid[row][col] = game.getStone(StoneLocation(row: row, column: col));
|
_grid[row][col] = game.getStone(StoneLocation(row: row, column: col));
|
||||||
|
|
Loading…
Reference in New Issue