cpd_David_und_Yusuf/lib/models/game.dart

58 lines
1.3 KiB
Dart
Raw Normal View History

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;
}
2024-05-10 23:21:21 +02:00
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;
}
}