public void requestGame(PlayerDTO playerDTO) { IdlePlayers.Add(new IdlePlayer() { PlayerId = playerDTO.PlayerId, Name = playerDTO.Name, Connection = new Nim.Models.Connection(Context.ConnectionId) }); if (IdlePlayers.Count > 1) { Game game = new Game(); game.AddPlayer(PlayerFactory.Create(IdlePlayers[0])); game.AddPlayer(PlayerFactory.Create(IdlePlayers[1])); Games.Add(game); //Start a game... game.StartNew(); IdlePlayers.RemoveRange(0, 2); } PlayerCountChanged(); }
public static NimGame Create(Game game) { //TODO: Random again int numberOfLines = new Random().Next(10, 20); return new NimGame(numberOfLines) { game = game }; }
public static GameDTO CreateDTO(Game game) { GameDTO gameDTO = new GameDTO() { GameId = game.GameId, ActiveGame = game.ActiveGame, GameResults = game.GameResults, CurrentTurn = game.CurrentTurn, Players = game.Players }; return gameDTO; }
public NimGameFinish(Game game) { var scores = new List<PlayerScore>(); foreach (ActivePlayer player in game.Players) { scores.Add(new PlayerScore() { Player = player, Wins = game.GameResults.Count(x => x.Winner == player), Loses = game.GameResults.Count(x => x.Winner != player) }); } this.Scores = scores; this.Winner = game.GameResults.Last().Winner; }