private GameManager() { _packs = new List <Pack>(); // Load the settings Settings = GameSettings.FromFile(SettingsFilePath); // Load all the decks foreach (var deckPath in Directory.EnumerateFiles(PacksDirectory, "*.json", SearchOption.AllDirectories)) { try { var pack = JsonConvert.DeserializeObject <Pack>(File.ReadAllText(deckPath)); _packs.Add(pack); } catch (Exception ex) { Console.WriteLine($"Failed to load deck '{deckPath}': {ex}"); } } Game = new CardGame(_packs, Settings); Console.WriteLine("\n=========== GAME INFO ===========\n"); Console.WriteLine($"Player limit: [{Settings.MinPlayers}, {Settings.MaxPlayers}]"); Console.WriteLine($"Hand size: {Settings.HandSize}"); Console.WriteLine($"Perma-Czar: {Settings.PermanentCzar}"); Console.WriteLine($"Bot Czars: {Settings.AllowBotCzars}"); Console.WriteLine($"Winner Is Czar: {Settings.WinnerCzar}"); Console.WriteLine($"Points to win: {Settings.MaxPoints}"); Console.WriteLine($"Max Rounds: {Settings.MaxRounds}"); Console.WriteLine($"Upgrades enabled: {Settings.UpgradesEnabled}"); Console.WriteLine($"Allow duplicate players: {Settings.AllowDuplicatePlayers}"); Console.WriteLine($"Player Preserves: {Settings.PlayerPreserveEnabled}"); if (Settings.PlayerPreserveEnabled) { Console.WriteLine($"Player Preserve Time: {Settings.PlayerPreserveTimeSeconds}s"); } Console.WriteLine($"Cards: {Game.BlackCardCount + Game.WhiteCardCount} ({Game.WhiteCardCount}x white, {Game.BlackCardCount}x black)"); Console.WriteLine(); Console.WriteLine($"Packs:\n{Game.GetPacks().Select(d => $" [{d}]").Aggregate((c, n) => $"{c}\n{n}")}"); Console.WriteLine("\n=================================\n"); Game.GameStateChanged += OnGameStateChanged; Game.RoundStarted += OnGameRoundStarted; Game.StageChanged += OnGameStageChanged; Game.RoundEnded += OnGameRoundEnded; Game.GameEnded += OnGameEnded; Game.BlackCardSkipped += OnBlackCardSkipped; UpdateTitle(); }
public CardGameServer(CardGame game) { Game = game ?? throw new ArgumentNullException(nameof(game)); Game.RoundEnded += OnGameRoundEnded; Game.GameEnded += OnGameEnded; _rng = new Random(unchecked (Environment.TickCount * 7919)); _rant = new RantEngine(); _spectators = new HashList <SpectatorConnection>(); _connections = new HashList <ClientConnectionBase>(); _addressTally = new Tally <string, ClientConnectionBase>(); _botTaunts = game.GetPacks().Select(p => p.GetTaunts()).SelectMany(t => t).ToArray(); _ws = new WebSocketServer(game.Settings.WebSocketUrl); _ws.AddWebSocketService(ServerPlayDir, () => new PlayerConnection(this, Game)); _ws.AddWebSocketService(ServerSpectateDir, () => new SpectatorConnection(this, Game)); }