Beispiel #1
0
        public Models.Salvo salvear(SalvoView salvoView, long gamePlayerId)
        {
            GamePlayer gameplayer = _repository.FindById(gamePlayerId);
            int        ultimoTurno;

            if (gameplayer.salvos == null)
            {
                ultimoTurno = 0;
            }
            else
            {
                ultimoTurno = gameplayer.salvos.Count;
            }


            var salvo = new Models.Salvo();

            salvo.Locations = new List <SalvoLocation>();
            salvo.Turn      = ultimoTurno + 1;
            foreach (SalvoLocationView salvoVloc in salvoView.locations)
            {
                SalvoLocation SalvoLoco = new SalvoLocation();
                SalvoLoco.Location = salvoVloc.location;
                salvo.Locations.Add(SalvoLoco);
            }
            return(salvo);
        }
Beispiel #2
0
        public IActionResult DispararSalvos(long gamePlayerId, [FromBody] SalvoView salvo)
        {
            GamePlayer gameplayer = _repository.FindById(gamePlayerId);    // repito logica con todas las validaciones

            if (gameplayer == null)
            {
                return(StatusCode(403, "no existe el plasher"));
            }
            Player playerSession = playerRepo.FindByEmail(User.FindFirst("Player").Value);

            if (gameplayer.Playerid != playerSession.Id)
            {
                return(StatusCode(403, "El usuario no se encuentra en el juego!"));
            }
            if (gameplayer.Game.GamePlayer.Count == 2)
            {
                GamePlayer contrincante = gameplayer.Rival();
                if (gameplayer.salvos == null)
                {
                    gameplayer.salvos = new List <Models.Salvo>();
                }
                if (contrincante.salvos == null)
                {
                    contrincante.salvos = new List <Models.Salvo>();
                }
                if (gameplayer.JoinDate < contrincante.JoinDate && gameplayer.salvos.Count == contrincante.salvos.Count) //aca tomo al que es mano, desp debo comparar los turnos y bla
                {                                                                                                        //si el mano tiene los mismos turnos, juega él
                    gameplayer.salvos.Add(salvear(salvo, gamePlayerId));
                    _repository.Save(gameplayer);
                    return(StatusCode(201, gameplayer.Id));
                }
                else if (gameplayer.JoinDate > contrincante.JoinDate && gameplayer.salvos.Count < contrincante.salvos.Count)
                {  //si el pie tiene la misma cantidad de turnos, debe permitir a él jugar
                    gameplayer.salvos.Add(salvear(salvo, gamePlayerId));
                    _repository.Save(gameplayer);
                    return(StatusCode(201, gameplayer.Id));
                }
                return(StatusCode(401, "espera tu turno"));
            }
            else
            {
                return(StatusCode(403, "Debes esperar al contrincante pa jugar ñery"));
            }
        }