fixed bug, added some minor things and added setstate, deleted game.dart

main
Oeyuu 2024-05-10 23:20:18 +02:00
parent c8c6c9bff3
commit 5a4e32992e
3 changed files with 43 additions and 75 deletions

View File

@ -1,48 +0,0 @@
import 'package:werwolf/models/role.dart';
import 'player.dart';
class Game {
List<Player> 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<Player> getPlayers() {
return players;
}
void assignRoles() {
List<int> 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;
// }
}

View File

@ -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<FlipingCard> {
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<FlipingCard> {
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<FlipingCard> {
),
),
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<FlipingCard> {
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<FlipingCard> {
),
),
onPressed: () {
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<FlipingCard> {
),
),
onPressed: () {
if (index >= 0 && index <= widget.players.length) {
setState(() {
if (index >= 0 && index < widget.players.length - 1) {
index++;
if (!_controller.state!.isFront) {
_controller.toggleCardWithoutAnimation();
}
}
});
},
child: const Text("Nächster Spieler"),
),

View File

@ -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<GameSettings> {
late Game game;
bool joker = false;
@override
void initState() {
game = Game(playernames: widget.playernames);
@ -101,6 +101,17 @@ class _GameSettingsState extends State<GameSettings> {
},
),
),
ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
FlipingCard(players: game.getAllPlayers()),
));
},
child: const Text('Spiel starten!'),
),
],
),
),