cpd_David_und_Yusuf/lib/screens/settings.dart

128 lines
4.3 KiB
Dart
Raw Permalink Normal View History

import 'package:flutter/material.dart';
import 'package:werwolf/screens/flippingcards.dart';
2024-05-10 23:21:21 +02:00
import '../models/game.dart';
import '../models/role.dart';
2024-06-18 01:46:57 +02:00
// Main widget for game settings
class GameSettings extends StatefulWidget {
final List<String> playernames;
const GameSettings({required this.playernames, super.key});
@override
State<GameSettings> createState() => _GameSettingsState();
}
class _GameSettingsState extends State<GameSettings> {
late Game game;
@override
void initState() {
2024-06-18 01:46:57 +02:00
game = Game(playernames: widget.playernames); // Initialize the game with player names
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(
"Werwolf",
2024-06-18 01:46:57 +02:00
style: Theme.of(context).textTheme.titleLarge, // Use large title style from theme
),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.fromLTRB(30.0, 40.0, 30.0, 8.0),
child: Column(
children: [
Text(
2024-06-18 01:46:57 +02:00
"Anzahl der Spieler ${widget.playernames.length}", // Display number of players
style: Theme.of(context).textTheme.titleLarge, // Use large title style from theme
),
const Divider(
height: 60,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(
2024-06-18 01:46:57 +02:00
"Anzahl der Werwölfe ${game.getWolves()}", // Display number of werewolves
style: Theme.of(context).textTheme.bodyLarge, // Use large body style from theme
),
IconButton(
onPressed: () {
setState(() {
2024-06-18 01:46:57 +02:00
game.decrementWolves(); // Decrease the number of werewolves
});
},
icon: const Icon(Icons.remove, color: Colors.white),
),
IconButton(
onPressed: () {
setState(() {
2024-06-18 01:46:57 +02:00
game.incrementWolves(); // Increase the number of werewolves
});
},
icon: const Icon(Icons.add, color: Colors.white),
),
],
),
const Divider(
height: 60,
),
Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 20),
child: Text(
2024-06-18 01:46:57 +02:00
"Spezielle Rollen", // Display special roles section
style: Theme.of(context).textTheme.titleLarge, // Use large title style from theme
),
),
Expanded(
child: ListView.builder(
itemCount: Role.values.length,
itemBuilder: (context, index) {
if (Role.values[index] != Role.dorfbewohner &&
Role.values[index] != Role.werwolf) {
Role role = Role.values[index];
return ListTile(
title: Text(
2024-06-18 01:46:57 +02:00
role.stringValue, // Display role name
style: Theme.of(context).textTheme.bodyLarge, // Use large body style from theme
),
trailing: Switch(
value: game.specialRoles[role],
onChanged: (bool value) {
setState(() {
2024-06-18 01:46:57 +02:00
game.specialRoles[role] = value; // Toggle special role
});
},
),
);
}
2024-06-18 01:46:57 +02:00
return Container(); // Return empty container if not a special role
},
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
2024-06-18 01:46:57 +02:00
builder: (context) => FlipingCard(players: game.getAllPlayers()), // Start game
),
);
},
2024-06-07 20:08:07 +02:00
child: const Text(
2024-06-18 01:46:57 +02:00
'Spiel starten!', // Start game button text
),
),
const Padding(padding: EdgeInsets.all(30)),
],
),
),
);
}
}