Exemplo n.º 1
0
 public static Game ToModelGame(this Article article)
 {
     Game game = new Game();
     game.Id = article.Id;
     game.Status = article.Get<string>("status");
     game.Players = new List<Player>();
     game.LastActivityTime = DateTime.UtcNow;
     return game;
 }
Exemplo n.º 2
0
        private void SaveGameStatus(string gameId, Game game, Player opponant, Player player, UserSession session)
        {
            game.Status = GameStatus.Finished.ToString();
            _gameProvider.SaveGameStatus(gameId, GameStatus.Finished);
            var tilesDiff = opponant.Tiles.Count;
            player.Points = player.Points + tilesDiff;
            opponant.Points = opponant.Points - tilesDiff;

            var winner = player.Points >= opponant.Points ? player : opponant;
            _gameProvider.SetGameWinner(gameId, winner.Id);

            int totalPoints = 0, level = 0;
            _gameProvider.UpdatePlayerProfile(winner.Id, winner.Points, out level, out totalPoints);
            if (string.Equals(session.Account.Id, winner.Id))
            {
                session.Account.Points = totalPoints;
                session.Account.Level = level;
            }
        }
Exemplo n.º 3
0
 private void GiveNextTilesToPlayer(Game game, ref Player player, Move userMove)
 {
     List<string> gameTiles = _gameProvider.GetGameTiles(game.Id);
     var parts = userMove.MoveCode.Split('|');
     foreach (var part in parts)
     {
         var mvs = part.Split(',');
         player.Tiles.Remove(mvs[2]);
     }
     player.TilesRemaining = player.TilesRemaining - parts.Length;
     if (player.TilesRemaining > 6)
         player.Tiles.AddRange(_movesDataProvider.GetRandomTiles(parts.Length, ref gameTiles));
     else
         player.Tiles.AddRange(_movesDataProvider.GetRandomTiles(player.TilesRemaining - player.Tiles.Count, ref gameTiles));
     _gameProvider.SetGameTiles(game.Id, gameTiles);
 }