public void DeclareReady(Game game) { var player = game.GetCurrentPlayer(Hub.Context.ConnectionId); if (!player.IsReady) { player.IsReady = true; if (new Random().Next(0, 10) > 5) { game.NextPlayer(); } } Hub.Clients.Group(game.GameId).updateBoard(game); }
private void ResumeGame(Game game) { game.ReconnectTimer.Stop(); var player = game.GetCurrentPlayer(Hub.Context.ConnectionId); if (player != null) player.IsReady = true; Hub.Clients.Group(game.GameId).updateBoard(game); Hub.Clients.Group(game.GameId).playerConnected(); }
private void GameEnded(Game game) { // TODO: if called by ai player error wont be handled by interceptor GameResult result = null; DbRepository.Transacted(() => { result = new GameResult(game); DbRepository.Current.Add(result.DbEntity); game.FirstPlayer.UpdateStanding(result.GetFor(game.FirstPlayer)); game.SecondPlayer.UpdateStanding(result.GetFor(game.SecondPlayer)); }); Games.RemoveGame(game); BroadcastGameList(); Hub.Clients.Group(game.GameId).updateBoard(game); Hub.Clients.Caller.receiveResult(result.GetFor(game.GetCurrentPlayer(Hub.Context.ConnectionId))); }
private void HoldGame(Game game, int reconnectTimeInSec) { var player = game.GetCurrentPlayer(Hub.Context.ConnectionId); if (player != null) player.IsReady = false; game.ReconnectTimer.Interval = reconnectTimeInSec * 1000; game.ReconnectTimer.Start(); Hub.Clients.Group(game.GameId).updateBoard(game); Hub.Clients.Group(game.GameId).playerDisconnected(); }
public void PlaceCard(string id, int position, Game game) { if (game.CurrentPlayer != game.GetCurrentPlayer(Hub.Context.ConnectionId)) { Hub.Clients.Caller.receiveError("Wait for your turn"); Hub.Clients.Caller.updateBoard(game); return; } game.CurrentPlayer.Play(game, new CardCommand(id, position)); Hub.Clients.Group(game.GameId).updateBoard(game); }