From 5a4e32992e24de6b6e17a79b64448f9a28279fef Mon Sep 17 00:00:00 2001 From: Oeyuu Date: Fri, 10 May 2024 23:20:18 +0200 Subject: [PATCH] fixed bug, added some minor things and added setstate, deleted game.dart --- lib/models/game.dart | 48 ---------------------------- lib/screens/flippingcards.dart | 57 ++++++++++++++++++---------------- lib/screens/settings.dart | 13 +++++++- 3 files changed, 43 insertions(+), 75 deletions(-) delete mode 100644 lib/models/game.dart diff --git a/lib/models/game.dart b/lib/models/game.dart deleted file mode 100644 index 31aa983..0000000 --- a/lib/models/game.dart +++ /dev/null @@ -1,48 +0,0 @@ -import 'package:werwolf/models/role.dart'; - -import 'player.dart'; - -class Game { - List players = []; - List playernames = []; - int numWolves = 1; - - Game({required this.playernames, required this.numWolves}) { - assignRoles(); - } - - void addPlayer(String name, Role role) { - players.add(Player(name: name, role: role)); - } - - List getPlayers() { - return players; - } - - void assignRoles() { - List indexes = List.generate(playernames.length, (index) => index) - ..shuffle(); - for (var player in playernames) { - //addPlayer(player, Role.dorfbewohner); - for (int i = 0; i < numWolves; i++) { - addPlayer(player[0], Role.dorfbewohner); - } - } - } - - void incrementWolves() { - if (numWolves < players.length) { - numWolves++; - } - } - - void decrementWolves() { - if (numWolves > 1) { - numWolves--; - } - } - - // void toggleReveal(int index) { - // players[index].isRevealed = !players[index].isRevealed; - // } -} diff --git a/lib/screens/flippingcards.dart b/lib/screens/flippingcards.dart index d7f88e3..c84ac75 100644 --- a/lib/screens/flippingcards.dart +++ b/lib/screens/flippingcards.dart @@ -1,7 +1,7 @@ +import 'package:flip_card/flip_card_controller.dart'; import 'package:flutter/material.dart'; import 'package:flip_card/flip_card.dart'; -import '../models/game.dart'; import '../models/player.dart'; import '../models/role.dart'; @@ -16,20 +16,12 @@ class FlipingCard extends StatefulWidget { class _FlipingCardState extends State { int index = 0; - String giveRole(Role role) { - String playerrole = "Dorfbewohner"; - switch (role) { - case Role.werwolf: - playerrole = "Werwolf"; - break; - case Role.joker: - playerrole = "Joker"; - break; - default: - playerrole = "Dorfbewohner"; - break; - } - return playerrole; + late FlipCardController _controller; + + @override + void initState() { + super.initState(); + _controller = FlipCardController(); } _renderContent(context) { @@ -39,9 +31,10 @@ class _FlipingCardState extends State { left: 15.0, right: 15.0, top: 10.0, bottom: 10.0), color: const Color(0x00000000), child: FlipCard( + controller: _controller, direction: FlipDirection.HORIZONTAL, side: CardSide.FRONT, - speed: 400, + speed: 300, onFlipDone: (status) {}, front: Container( decoration: const BoxDecoration( @@ -71,9 +64,11 @@ class _FlipingCardState extends State { ), ), back: Container( - decoration: const BoxDecoration( - color: Color(0xFF006666), - borderRadius: BorderRadius.all(Radius.circular(8.0)), + decoration: BoxDecoration( + color: widget.players[index].role != Role.werwolf + ? const Color(0xFF006666) + : Color.fromARGB(255, 100, 21, 15), + borderRadius: const BorderRadius.all(Radius.circular(8.0)), ), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, @@ -82,7 +77,7 @@ class _FlipingCardState extends State { Container( padding: const EdgeInsets.all(10), child: Text( - giveRole(widget.players[index].role), + widget.players[index].role.stringValue, textAlign: TextAlign.center, style: Theme.of(context) .textTheme @@ -123,9 +118,14 @@ class _FlipingCardState extends State { ), ), onPressed: () { - if (index > 0 && index <= widget.players.length) { - index--; - } + setState(() { + if (index > 0 && index <= widget.players.length) { + index--; + if (!_controller.state!.isFront) { + _controller.toggleCardWithoutAnimation(); + } + } + }); }, child: const Text("Zurück"), ), @@ -137,9 +137,14 @@ class _FlipingCardState extends State { ), ), onPressed: () { - if (index >= 0 && index <= widget.players.length) { - index++; - } + setState(() { + if (index >= 0 && index < widget.players.length - 1) { + index++; + if (!_controller.state!.isFront) { + _controller.toggleCardWithoutAnimation(); + } + } + }); }, child: const Text("Nächster Spieler"), ), diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index ad9f379..0543f1a 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:werwolf/screens/flippingcards.dart'; import '../models/games.dart'; import '../models/role.dart'; @@ -13,7 +14,6 @@ class GameSettings extends StatefulWidget { class _GameSettingsState extends State { late Game game; - bool joker = false; @override void initState() { game = Game(playernames: widget.playernames); @@ -101,6 +101,17 @@ class _GameSettingsState extends State { }, ), ), + ElevatedButton( + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + FlipingCard(players: game.getAllPlayers()), + )); + }, + child: const Text('Spiel starten!'), + ), ], ), ),