public void updateRelJugadorMapa(RelJugadorMapa r)
        {
            try
            {
                var rel = ctx.RelJugadorMapa
                          .Where(w => w.id == r.id)
                          .SingleOrDefault();

                if (rel != null)
                {
                    rel.nivel1 = r.nivel1;
                    rel.nivel2 = r.nivel2;
                    rel.nivel3 = r.nivel3;
                    rel.nivel4 = r.nivel4;
                    rel.nivel5 = r.nivel5;
                    rel.j      = new Entities.Jugador(r.jugador.nombre, r.jugador.apellido, r.jugador.foto, r.jugador.nickname,
                                                      r.jugador.nivel, r.jugador.experiencia);

                    ctx.SaveChangesAsync().Wait();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        public RelJugadorMapa Get(int id)
        {
            RelJugadorMapa colonia = blHandler.getRelJugadorMapa(id);

            if (colonia == null)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            return(colonia);
        }
        private int GetDistanceBetweenColony(int requester, int receiver)
        {
            int             distance = 0;
            RelJugadorMapa  from     = api.getRelJugadorMapaHandler().getRelJugadorMapa(requester);
            RelJugadorMapa  to       = api.getRelJugadorMapaHandler().getRelJugadorMapa(receiver);
            List <MapaNode> mapas    = api.getMapaNodeHandler().getAllMapas();

            if (from.nivel1 != -1 && to.nivel1 != -1 && from.nivel1 != to.nivel1)
            {
                MapaNode sect = mapas.Where(c => c.nivel == 1).FirstOrDefault();
                if (sect != null && sect.cantidad > 1)
                {
                    distance += sect.distance * 2;
                }
            }
            if (from.nivel2 != -1 && to.nivel2 != -1 && from.nivel2 != to.nivel2)
            {
                MapaNode sect = mapas.Where(c => c.nivel == 2).FirstOrDefault();
                if (sect != null && sect.cantidad > 1)
                {
                    distance += sect.distance * 2;
                }
            }
            if (from.nivel3 != -1 && to.nivel3 != -1 && from.nivel3 != to.nivel3)
            {
                MapaNode sect = mapas.Where(c => c.nivel == 3).FirstOrDefault();
                if (sect != null && sect.cantidad > 1)
                {
                    distance += sect.distance * 2;
                }
            }
            if (from.nivel4 != -1 && to.nivel4 != -1 && from.nivel4 != to.nivel4)
            {
                MapaNode sect = mapas.Where(c => c.nivel == 4).FirstOrDefault();
                if (sect != null && sect.cantidad > 1)
                {
                    distance += sect.distance * 2;
                }
            }
            if (from.nivel5 != -1 && to.nivel5 != -1 && from.nivel5 != to.nivel5)
            {
                MapaNode sect = mapas.Where(c => c.nivel == 5).FirstOrDefault();
                if (sect != null && sect.cantidad > 1)
                {
                    distance += sect.distance * 2;
                }
            }
            return(distance);
        }
        public void createRelJugadorMapa(RelJugadorMapa r)
        {
            var j   = ctx.Jugador.Where(w => w.Id == r.jugador.id).SingleOrDefault();
            var rel = new Entities.RelJugadorMapa(r.nivel1, r.nivel2, r.nivel3, r.nivel4, r.nivel5, r.coord, j);

            try
            {
                ctx.RelJugadorMapa.Add(rel);
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public RelJugadorMapa getRelJugadorMapa(int id)
        {
            try
            {
                var rel = (from c in ctx.RelJugadorMapa
                           where c.id == id
                           select c).SingleOrDefault();

                var j = new Jugador(rel.j.Id, rel.j.nombre, rel.j.apellido, rel.j.Email, rel.j.UserName, rel.j.PasswordHash, rel.j.foto,
                                    rel.j.nickname, rel.j.nivel, rel.j.experiencia);
                var rjm = new RelJugadorMapa(rel.id, rel.nivel1, rel.nivel2, rel.nivel3, rel.nivel4, rel.nivel5, rel.coord, j);
                return(rjm);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 6
0
        //ESTADO INICIAL JUGADOR

        public void inicializarJugador(Jugador j)
        {
            var    mapas = builder.getMapaNodeHandler().getAllMapas();
            Random rnd   = new Random();

            int[]   nivel   = { -1, -1, -1, -1, -1 };
            int     i       = 0;
            string  coord   = "";
            string  c       = "/";
            Boolean hayMapa = true;

            do
            {
                i     = 0;
                coord = "";
                c     = "/";
                foreach (var m in mapas)
                {
                    nivel[i] = rnd.Next(1, m.cantidad + 1);
                    coord   += c;
                    c        = nivel[i] + "/";
                    i++;
                }
                hayMapa = builder.getRelJugadorMapaHandler().existeColonia(nivel[0], nivel[1], nivel[2], nivel[3], nivel[4]);
            } while (hayMapa == true);

            var reljm = new RelJugadorMapa(1, nivel[0], nivel[1], nivel[2], nivel[3], nivel[4], coord, j);

            builder.getRelJugadorMapaHandler().createRelJugadorMapa(reljm);

            List <RelJugadorMapa> colonias = builder.getRelJugadorMapaHandler().getMapasByJugador(j.id);
            var colonia = colonias.First();

            var ahora = DateTime.Now;

            List <Recurso> recursos = builder.getRecursoHandler().getAllRecursos();

            foreach (var rec in recursos)
            {
                var rel = new RelJugadorRecurso(1, rec, colonia, rec.capacidadInicial, rec.cantInicial, rec.produccionXTiempo, ahora);
                builder.getRelJugadorRecursoHandler().createRelJugadorRecurso(rel);
            }

            List <Edificio> edificios = builder.getUnidadHandler().getAllEdificios();

            foreach (var ed in edificios)
            {
                var rel = new RelJugadorEdificio(1, colonia, ed, 0, ahora);
                builder.getRelJugadorEdificioHandler().createRelJugadorEdificio(rel);
            }

            List <Destacamento> destacamentos = builder.getUnidadHandler().getAllDestacamentos();

            foreach (var des in destacamentos)
            {
                var rel = new RelJugadorDestacamento(1, colonia, des, 0, ahora);
                builder.getRelJugadorDestacamentoHandler().createRelJugadorDestacamento(rel);
            }

            List <Investigacion> investigaciones = builder.getInvestigacionHandler().getAllInvestigaciones();

            foreach (var inv in investigaciones)
            {
                var rel = new RelJugadorInvestigacion(1, colonia, inv, 0, ahora);
                builder.getRelJugadorInvestigacionHandler().createRelJugadorInvestigacion(rel);
            }
        }
Exemplo n.º 7
0
 public void updateRelJugadorMapa(RelJugadorMapa reljugadormapa)
 {
     builder.getRelJugadorMapaHandler().updateRelJugadorMapa(reljugadormapa);
 }