Ejemplo n.º 1
0
        public PlayerInBattle GetNewGame(Player firstPlayer, int gameType, List<Player> opponents)
        {
            // 1-Create The game
            var game = typeMapping.GetGame(gameType);
            Grid currentState = game.GetNewGame();

            // 2-Preparing listOfPlayers
            var listPlayers = opponents.Select(p=>p.PlayerId).ToList();
            listPlayers.Insert(0, firstPlayer.PlayerId);

            // 2-Link the players Id with player numbers
            PlayerInBattle toReturn = new PlayerInBattle()
            {
                Battle = new Battle
                {
                    CreationTime = DateTime.Now,
                    BattleId = Math.Abs((int)DateTime.Now.Ticks),//String.Format("{0}_{1}_{2}_{3}", game.GetGameType(), firstPlayer.PlayerId, GetElapsedSecondsSinceLastNewYear(), ran.Next(99)),
                    GameType = gameType,
                    GameTypeString = game.ToString(),
                    LastUpdate = DateTime.Now,
                    Players = listPlayers,
                    CurrentState = currentState
                },
                Player = firstPlayer,
                PlayerNumber = 1
            };

            repoPlayerInBattle.Persist(toReturn);
            return toReturn;
        }
Ejemplo n.º 2
0
 public Player Get(string login)
 {
     var p = new Player()
     {
         Login = login,
         Password = login,
         PlayerId = GetPlayerId(login)
     };
     if (!allPlayers.ContainsKey(p.PlayerId))
     {
         allPlayers.Add(p.PlayerId, p);
     }
     return p;
 }
Ejemplo n.º 3
0
 public Player CreatePlayer(string login, string password)
 {
     if (_context.Players.Any(g => g.Login == login))
     {
         throw new Exception(Error.LOGIN_ALREADY_EXISTS);
     }
     Player newPlayer = new Player
     {
         Login = login,
         Password = password,
     };
     _context.Players.Add(newPlayer);
     _context.SaveChanges();
     return newPlayer;
 }
Ejemplo n.º 4
0
 public PlayerInBattle GetParticipation(Player player, int gameId)
 {
     return repoPlayerInBattle.Get(gameId, player.PlayerId);
 }
Ejemplo n.º 5
0
 public List<PlayerInBattle> GetAllBattles(Player player)
 {
     return repoPlayerInBattle.Get(player.PlayerId);
 }