58 lines
1.3 KiB
Dart
58 lines
1.3 KiB
Dart
|
import 'package:werwolf/models/role.dart';
|
||
|
|
||
|
import 'player.dart';
|
||
|
|
||
|
class Game {
|
||
|
List<Player> players = [];
|
||
|
List playernames = [];
|
||
|
int numWolves = 1;
|
||
|
Map specialRoles = <Role, bool>{};
|
||
|
|
||
|
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<Player> getAllPlayers() {
|
||
|
players.clear();
|
||
|
List<Role> 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;
|
||
|
}
|
||
|
}
|