Пример #1
0
        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();
        }
Пример #2
0
        public static NimGame Create(Game game)
        {
            //TODO: Random again
            int numberOfLines = new Random().Next(10, 20);

            return new NimGame(numberOfLines)
            {
                game = game
            };
        }
Пример #3
0
        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;
        }
Пример #4
0
        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;
        }