2024-05-07 18:00:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'game.dart';
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
runApp(MaterialApp(home: WerewolfGame()));
|
|
|
|
}
|
|
|
|
|
|
|
|
class WerewolfGame extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_WerewolfGameState createState() => _WerewolfGameState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _WerewolfGameState extends State<WerewolfGame> {
|
|
|
|
final Game game = Game(1); // Initial number of wolves
|
|
|
|
final TextEditingController _playerController = TextEditingController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(title: Text("Werwolf Spiel")),
|
|
|
|
body: Column(
|
|
|
|
children: [
|
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.all(8.0),
|
|
|
|
child: TextField(
|
|
|
|
controller: _playerController,
|
|
|
|
decoration: InputDecoration(labelText: 'Spielername'),
|
|
|
|
onSubmitted: (value) {
|
|
|
|
setState(() {
|
|
|
|
game.addPlayer(value);
|
|
|
|
_playerController.clear();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
|
|
children: [
|
|
|
|
FloatingActionButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
game.decrementWolves();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Icon(Icons.remove),
|
|
|
|
mini: true,
|
|
|
|
),
|
|
|
|
Text('Anzahl der Werwölfe: ${game.numWolves}', style: TextStyle(fontSize: 16)),
|
|
|
|
FloatingActionButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
game.incrementWolves();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Icon(Icons.add),
|
|
|
|
mini: true,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
ElevatedButton(
|
|
|
|
onPressed: () {
|
|
|
|
setState(() {
|
|
|
|
game.assignRoles();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
child: Text('Spiel starten'),
|
|
|
|
),
|
|
|
|
Expanded(
|
|
|
|
child: ListView.builder(
|
|
|
|
itemCount: game.players.length,
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return ListTile(
|
|
|
|
title: Text(game.players[index].name),
|
|
|
|
trailing: Icon(game.players[index].isRevealed ? Icons.visibility : Icons.visibility_off),
|
|
|
|
onTap: () {
|
|
|
|
setState(() {
|
|
|
|
game.toggleReveal(index);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
subtitle: game.players[index].isRevealed ? Text(game.players[index].role) : null,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|