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

            return new NimGame(numberOfLines)
            {
                game = game
            };
        }
Example #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;
        }
Example #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;
        }