private void StartServer() { Func <Task <string> > generateWordMethod = kalaburyService.GetWord; Func <Game, string> generateCurrentPlayerMethod = kalaburyService.SelectCurrentPlayer; Console.WriteLine("Server started."); while (true) { Console.WriteLine($"Game count: {gameHelper.gameTasks.Count}"); Console.WriteLine($"Running game count: {gameHelper.gameTasks.Where(g => g.IsStarted).ToList().Count}"); foreach (var gameTask in gameHelper.gameTasks) { if (!gameTask.IsStarted) { continue; } gameTask.CheckRound(); gameTask.CheckStatus(); if (gameTask.IsFinshed) { if (!gameTask.WasGuessed) { gameTask.UpdatePoints(null); } gameMiddleware.SendPoints(gameTask.Game.Room.Id.ToString(), gameTask.Game.PlayersPointsPerGame); gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), $"Koniec rundy, hasło: {gameTask.GameStatus.Word}"); gameTask.GenerateNewRound(generateWordMethod, generateCurrentPlayerMethod); continue; } if (gameTask.IsEnded) { kalaburyService.UpdateUsersPoints(gameTask.Game.PlayersPointsPerGame); gameTask.GameStatus.IsFinished = true; gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), "Koniec gry"); continue; } gameMiddleware.SendGameStatus(gameTask.Game.Room.Id.ToString(), gameTask.GameStatus); } gameHelper.gameTasks.RemoveAll(game => game.IsEnded); Thread.Sleep(1000); } Console.WriteLine("Server ended."); }
private void StartServer() { Func <Game, string> generateCurrentPlayerMethod = chineseService.SelectCurrentPlayer; Console.WriteLine("Server started."); while (true) { Console.WriteLine($"Game count: {gameHelper.gameTasks.Count}"); Console.WriteLine($"Running game count: {gameHelper.gameTasks.Where(g => g.IsStarted).ToList().Count}"); foreach (var gameTask in gameHelper.gameTasks) { if (!gameTask.IsStarted) { continue; } gameTask.CheckRound(); gameTask.CheckStatus(); if (gameTask.IsFinshed) { gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), $"Czas minał. Koniec rundy dla gracza ${gameTask.Game.Room.Players.First(p => p.Id == gameTask.Game.CurrentPlayerId).Name}"); gameTask.GenerateNewRound(generateCurrentPlayerMethod); gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), $"Nowa runda dla gracza ${gameTask.Game.Room.Players.First(p => p.Id == gameTask.Game.CurrentPlayerId).Name}"); continue; } if (gameTask.IsEnded) { gameTask.UpdatePoints(); chineseService.UpdateUsersPoints(gameTask.Game.PlayersPointsPerGame); gameMiddleware.SendPoints(gameTask.Game.Room.Id.ToString(), gameTask.Game.PlayersPointsPerGame); gameTask.GameStatus.IsFinished = true; gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), "Koniec gry"); continue; } gameMiddleware.SendGameStatus(gameTask.Game.Room.Id.ToString(), gameTask.GameStatus); } gameHelper.gameTasks.RemoveAll(game => game.IsEnded); Thread.Sleep(1000); } Console.WriteLine("Server ended."); }
private async void StartServer() { Console.WriteLine("Server started."); Func <ShipsGameStatus, Game, string> generateCurrentPlayerMethod = shipsService.SelectCurrentPlayer; while (true) { Console.WriteLine($"Game count: {gameHelper.gameTasks.Count}"); Console.WriteLine($"Running game count: {gameHelper.gameTasks.Where(g => g.IsStarted).ToList().Count}"); foreach (var gameTask in gameHelper.gameTasks) { if (!gameTask.IsStarted) { continue; } gameTask.CheckRound(); gameTask.CheckStatus(); if (gameTask.IsFinshed) { await gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), this.CreateMessage(gameTask)); gameTask.GenerateNewRound(generateCurrentPlayerMethod); continue; } if (gameTask.IsEnded) { shipsService.UpdateUsersPoints(gameTask.Game.PlayersPointsPerGame); gameTask.GameStatus.IsFinished = true; await gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), "Koniec gry"); continue; } await gameMiddleware.SendGameStatus(gameTask.Game.Room.Id.ToString(), gameTask.GameStatus); } gameHelper.gameTasks.RemoveAll(game => game.IsEnded); Thread.Sleep(1000); } }
private void StartServer() { Console.WriteLine("Server started."); while (true) { Console.WriteLine($"Game count: {gameHelper.gameTasks.Count}"); Console.WriteLine($"Running game count: {gameHelper.gameTasks.Where(g => g.IsStarted).ToList().Count}"); foreach (var gameTask in gameHelper.gameTasks) { if (!gameTask.IsStarted) { continue; } gameTask.UpdateClocks(); gameTask.UpdateGameStatus(); if (gameTask.GameStatus.IsFinished) { if (gameTask.Resigned) { gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), $"Rezygnacja gracza {gameTask.Game.Room.Players.First(p => p.Id == gameTask.GameStatus.CurrentPlayerId).Name}"); } if (gameTask.GameStatus.DrawAccepted) { gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), "Remis"); } gameMiddleware.SendMesage(gameTask.Game.Room.Id.ToString(), "Koniec gry"); gameTask.UpdatePoints(); chessService.UpdateUsersPoints(gameTask.Game.PlayersPointsPerGame); gameMiddleware.SendPoints(gameTask.Game.Room.Id.ToString(), gameTask.Game.PlayersPointsPerGame); continue; } gameMiddleware.SendGameStatus(gameTask.Game.Room.Id.ToString(), gameTask.GameStatus); } gameHelper.gameTasks.RemoveAll(game => game.GameStatus.IsFinished); Thread.Sleep(1000); } Console.WriteLine("Server ended."); }