import 'package:werwolf/models/role.dart'; import 'player.dart'; class Game { List players = []; List playernames = []; int numWolves = 1; Map specialRoles = {}; Game({required this.playernames}) { for (Role role in Role.values) { if (role != Role.dorfbewohner && role != Role.werwolf) { specialRoles[role] = false; } } } void incrementWolves() { if (numWolves < playernames.length - 1 && (playernames.length) >= ((numWolves + 1) * 3)) { numWolves++; } } void decrementWolves() { if (numWolves > 1) { numWolves--; } } int getWolves() { return numWolves; } List getAllPlayers() { players.clear(); List randomRoles = []; for (var i = 0; i < numWolves; i++) { randomRoles.add(Role.werwolf); } for (var specialRole in specialRoles.keys) { if (specialRoles[specialRole]) { randomRoles.add(specialRole); } } for (var i = randomRoles.length; i < playernames.length; i++) { randomRoles.add(Role.dorfbewohner); } randomRoles.shuffle(); for (var playerName in playernames) { players.add(Player(name: playerName, role: randomRoles.last)); randomRoles.removeLast(); } return players; } }