private static void DibujarPlaneta(PaintEventArgs e, Planeta planeta) { Rectangle area = new Rectangle(planeta.Location.X, planeta.Location.Y, planeta.Width, planeta.Height); if (planeta.Imagen != null) { e.Graphics.DrawImage(planeta.Imagen, area); } StringFormat formatoTexto = new StringFormat(); formatoTexto.LineAlignment = StringAlignment.Far; e.Graphics.DrawString(planeta.Name, planeta.Font, new SolidBrush(Color.Red), area, formatoTexto); Pen lapiz; if (planeta.Dueño == null) { lapiz = new Pen(Color.White, 1f); } else { lapiz = new Pen(planeta.Dueño.Color, 2f); } e.Graphics.DrawRectangle(lapiz, area.X, area.Y, area.Width - 1, area.Height - 1); }
public void ChequearQueElSateliteNoEsteEnLaLista() { Planeta p = new Planeta(1, 1, "Tierra", 1, Tipo.Rocoso); Satelite s = new Satelite(1, 1, "Luna"); Assert.IsFalse(p == s); }
/// <summary> /// Envia una flota entre dos planetas /// </summary> public void EnviarFlota(Planeta origen, Planeta destino, int naves, int rondaActual) { if (naves != 0) { if (origen.Naves < naves) { naves = origen.Naves; } origen.Naves -= naves; Flota flota = new Flota(); flota.Destino = destino; flota.TecnologiaMilitar = origen.TecnologiaMilitar; flota.Origen = origen; flota.Naves = naves; flota.Distancia = Cliente.CalcularDistancia(origen, destino); flota.RondaSalida = rondaActual; flota.RondaLlegada = (rondaActual + (int)Math.Round(flota.Distancia)); origen.Dueño.Flotas.Add(flota); origen.Dueño.ClienteTcp.EnviarComando(205, string.Format("He enviado '{0}' naves desde '{1}' hasta '{2}'. La distancia es de '{3}' y la tecnologia militar es '{4}'", naves, origen.Name, destino.Name, flota.Distancia, flota.TecnologiaMilitar)); } }
public void PlanetasDiferenteNombre() { Planeta p1 = new Planeta(1, 1, "Tierra", 1, Tipo.Rocoso); Planeta p2 = new Planeta(1, 1, "Marte", 1, Tipo.Rocoso); Assert.IsFalse(p1 == p2); }
public SimularBatalla(Planeta planeta, Planeta planeta2, Cliente jugador) { InitializeComponent(); this.Icon = Icon.ExtractAssociatedIcon(Application.ExecutablePath); if (jugador != null) { label1.Text = "Simulacion de batalla para el jugador " + jugador.Nombre + " desde el planeta " + planeta.Name; } else { label1.Text = "Simulador de batallas"; } numericUpDownEx1.Value = planeta.Naves; numericUpDownEx4.Value = planeta.TecnologiaMilitar; if (planeta2.Dueño != null) { numericUpDownEx2.Value = planeta2.Naves; numericUpDownEx3.Value = planeta2.TecnologiaMilitar; } numericUpDownEx1.ValueChanged += ResimularBatalla; numericUpDownEx2.ValueChanged += ResimularBatalla; numericUpDownEx3.ValueChanged += ResimularBatalla; numericUpDownEx4.ValueChanged += ResimularBatalla; ResimularBatalla(null, null); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Nome,Email")] Planeta planeta) { if (id != planeta.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(planeta); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PlanetaExists(planeta.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(planeta)); }
public void PlanetasNoAlineadosEntreSi() { var list = new List <Planeta>(); var planeta = new Planeta { PlanetaId = 1, Posicion = 45, Distancia = 100 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 2, Posicion = 150, Distancia = 300 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 3, Posicion = 90, Distancia = 450 }; list.Add(planeta); var service = new PronosticoService(null, null); var alineados = service.EstanAlineados(list, out double?pendiente); Assert.IsFalse(alineados); }
public static Planeta PostPlaneta(Planeta sistema) { sistema.teletransportador = null; sistema.deposito = null; var httpWebRequest = (HttpWebRequest)WebRequest.Create(ApiCalls.url + "/api/planetas"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonUtility.ToJson(sistema); //json = json.Replace("\"id\":0,", ""); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); sistema = JsonUtility.FromJson <Planeta>(result); } return(sistema); }
static void Main(string[] args) { SistemaSolar sistema = new SistemaSolar(); SistemaSolar sistema2 = new SistemaSolar(); Planeta planet = new Planeta(22, 10, "Tierra", 7, ETipo.Gaseoso); Planeta p2 = new Planeta(100, 10, "Saturno", 8, ETipo.Rocoso); Satelite s1 = new Satelite(4, 1, "Anillos"); Satelite s2 = new Satelite(6, 2, "Tito"); Satelite satelit = new Satelite(1, 2, "Luna"); Satelite sat = new Satelite(2, 1, "Sol"); sistema.Planetas.Add(planet); sistema2.Planetas.Add(p2); if (planet + satelit && planet + sat && p2 + s1 && p2 + s2) { Console.WriteLine(sistema.MostrarInformacionAstros()); Console.WriteLine(sistema2.MostrarInformacionAstros()); //Console.WriteLine(planet.ToString()); } Console.ReadKey(); }
public void PlanetasMismoNombre() { Planeta p1 = new Planeta(1, 1, "Tierra", 1, Tipo.Rocoso); Planeta p2 = new Planeta(3, 2, "Tierra", 4, Tipo.Gaseoso); Assert.IsTrue(p1 == p2); }
public void PlanetasNoContienenAlSol() { var list = new List <Planeta>(); var planeta = new Planeta { PlanetaId = 1, Posicion = 60, Distancia = 100 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 2, Posicion = 90, Distancia = 300 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 3, Posicion = 150, Distancia = 450 }; list.Add(planeta); var service = new PronosticoService(null, null); var contieneAlSol = service.PlanetasContienenAlSol(list, new Tuple <double, double>(0, 0)); Assert.IsFalse(contieneAlSol); }
public IHttpActionResult DeletePlaneta(int id) { List <AristaNodo> aristas = db.AristaNodoes.Where(xx => xx.origenFK == id || xx.destinoFK == id).ToList(); db.AristaNodoes.RemoveRange(aristas); Planeta planeta = db.Planetas.Find(id); Teletransportador teletransportador = db.Teletransportadores.Find(id); Deposito deposito = db.Depositos.Find(id); if (planeta == null) { return(NotFound()); } if (teletransportador != null) { db.Teletransportadores.Remove(teletransportador); } if (deposito != null) { db.Depositos.Remove(deposito); } db.Planetas.Remove(planeta); db.SaveChanges(); return(Ok(planeta)); }
private void BtnAgregarPlaneta_Click(object sender, EventArgs e) { int tiempoOrb = 0; if (txtNombrePlaneta.Text != "" && txtOrbitaPlaneta.Text != "" && int.TryParse(txtOrbitaPlaneta.Text, out tiempoOrb)) { if (tiempoOrb > 0 && (int)numRotacion.Value > 0 && (int)numSatelite.Value >= 0) { Planeta planeta = new Planeta(tiempoOrb, (int)numRotacion.Value, txtNombrePlaneta.Text, (int)numSatelite.Value, (Tipo)cmbTipo.SelectedItem); planetas.Add(planeta); cmbPlanetas.Items.Add((string)planeta); MessageBox.Show("Planeta agregado corréctamente"); } else { MessageBox.Show("Ingrese valores mayores a 0"); } } else { MessageBox.Show("Ingrese datos corréctamente"); } txtNombrePlaneta.Text = ""; txtNombreSatelite.Text = ""; txtOrbitaPlaneta.Text = ""; numRotacion.Value = 0; numRotacionSatelite.Value = 0; numOrbitaSatelite.Value = 0; numSatelite.Value = 0; }
/// <summary> /// Agrega al planeta a la lista /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAgregarPlaneta_Click(object sender, EventArgs e) { if (txtNombrePlaneta.Text != "" && txtOrbitaPlaneta.Text != "" && numRotacion.Value > 0 && numSatelite.Value >= 0 && cmbTipo.Text != "") { Planeta planetaUno = new Planeta(int.Parse(txtOrbitaPlaneta.Text), (int)numRotacion.Value, txtNombrePlaneta.Text, (int)numSatelite.Value, (Tipo)cmbTipo.SelectedItem); bool flag = true; foreach (Planeta planeta in planetas) { if (planetaUno == planeta) { MessageBox.Show("El planeta ya se encuentra en la lista", "Atencion", MessageBoxButtons.OK, MessageBoxIcon.Information); flag = false; break; } flag = true; } if (flag) { planetas.Add(planetaUno); MessageBox.Show("Se agrego el planeta con exito", "Agregado!", MessageBoxButtons.OK, MessageBoxIcon.Information); cmbPlanetas.Items.Add(txtNombrePlaneta.Text); } txtNombrePlaneta.Text = ""; txtOrbitaPlaneta.Text = ""; numRotacion.Value = 0; numSatelite.Value = 0; cmbTipo.Text = ""; } else { MessageBox.Show("Complete todos los campos para agregar", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public IHttpActionResult PutPlaneta(int id, Planeta planeta) { planeta.deposito = null; planeta.teletransportador = null; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != planeta.id) { return(BadRequest()); } db.Entry(planeta).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { } return(StatusCode(HttpStatusCode.NoContent)); }
private void btnAgregarPlaneta_Click(object sender, EventArgs e) { if (txtNombrePlaneta.Text != String.Empty && txtTiempoOrbitaPlaneta.Text != String.Empty && numCantLunasPlaneta.Value >= 0 && numRotacionPlaneta.Value >= 0) { Astro p; if (cmbPlaneta.SelectedText == "Rocoso") { p = new Planeta(Convert.ToInt16(txtTiempoOrbitaPlaneta.Text), (int)numRotacionPlaneta.Value, txtNombrePlaneta.Text, (int)numCantLunasPlaneta.Value, Tipo.Rocoso); } else { p = new Planeta(Convert.ToInt16(txtTiempoOrbitaPlaneta.Text), (int)numRotacionPlaneta.Value, txtNombrePlaneta.Text, (int)numCantLunasPlaneta.Value, Tipo.Gaseoso); } planetas.Add(p); if (planetas.Contains(p)) { MessageBox.Show("Planeta Agregado", "Atencion", MessageBoxButtons.OK); cmbPlaneta.Items.Clear(); foreach (Astro item in planetas) { if (item is Planeta) { cmbPlaneta.Items.Add((string)item); } } } else { MessageBox.Show("Error al agregar un planeta", "Atencion", MessageBoxButtons.OK); } } }
public ActionResult Post(PlanetaIncluir planetaIncluir) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } Planeta planeta = new Planeta(); planeta.nome = planetaIncluir.nome; planeta.clima = planetaIncluir.clima; planeta.terreno = planetaIncluir.terreno; List <ResultsPlanetas> planetasWebApi = BuscarDadosWeb(); ResultsPlanetas planetaWebApi = new ResultsPlanetas(); planetaWebApi = planetasWebApi.FindLast(p => p.name == planeta.nome); if (planetaWebApi != null) { planeta.qtdApareceuEmFilme = planetaWebApi.films.Count(); } else { planeta.qtdApareceuEmFilme = 0; } _context.planetas.Add(planeta); _context.SaveChanges(); return(Ok(planeta)); }
public DetallePlaneta(Planeta planeta) { InitializeComponent(); nombrePlaneta.Text = planeta.Name; diametroPlaneta.Text = planeta.Diameter; }
private void btnAgregarP_Click(object sender, EventArgs e) { bool agregado = true; if (txtNombrePlaneta.Text != "" && txtTiempoOrbita.Text != "" && numRotacionP.Value > 0 && numCantLunas.Value >= 0) { Planeta planetaNuevo = new Planeta(int.Parse(txtTiempoOrbita.Text), (int)numRotacionP.Value, txtNombrePlaneta.Text, (int)numCantLunas.Value, (Tipo)cmbTipoPlanetas.SelectedItem); foreach (Planeta aux in planeta) { if (aux == planetaNuevo) { MessageBox.Show("El planeta ya se encuentra en la lista"); agregado = false; break; } agregado = true; } if (agregado) { planeta.Add(planetaNuevo); MessageBox.Show("El planeta se agrego con exito!!"); cmbPlaneta.Items.Add(txtNombrePlaneta.Text); } txtNombrePlaneta.Text = ""; txtTiempoOrbita.Text = ""; numRotacionP.Value = 0; numCantLunas.Value = 0; } else { MessageBox.Show("Debe completar los datos completos"); } }
public void PronosticarClimaOptimo() { var list = new List <Planeta>(); var planeta = new Planeta { PlanetaId = 1, Posicion = 45, Distancia = 100 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 2, Posicion = 315, Distancia = 100 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 3, Posicion = 45, Distancia = 100 }; list.Add(planeta); var service = new PronosticoService(null, null); var clima = service.PronosticarClimaDePlanetas(list); Assert.AreEqual(clima, ClimaConstants.Optimo); }
public static void PutPlaneta(Planeta sistema) { var httpWebRequest = (HttpWebRequest)WebRequest.Create(ApiCalls.url + "/api/planetas/" + sistema.id); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "PUT"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { string json = JsonUtility.ToJson(sistema); streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); sistema = JsonUtility.FromJson <Planeta>(result); } }
/// <summary> /// Agrega un planeta a la lista /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonAgregarPlaneta_Click(object sender, EventArgs e) { if (estrellas == null) { buttonAgregarPlaneta.Enabled = false; } else { if (txtPlanetaNombre.Text != String.Empty && txtOrbitaPlaneta.Text != String.Empty && numericUpDownRotacionPlaneta.Value > 0 && numericUpDownLunas.Value >= 0 && comboBoxTipoPlaneta.Text != String.Empty) { Planeta p = new Planeta(int.Parse(txtOrbitaPlaneta.Text), (int)numericUpDownRotacionPlaneta.Value, txtPlanetaNombre.Text, (int)numericUpDownLunas.Value, (Tipo)comboBoxTipoPlaneta.SelectedItem); //planetas.Add(p); estrellas.Planetas.Add(p); comboBoxPlaneta.Items.Add(txtPlanetaNombre.Text); MessageBox.Show("Planeta cargado correctamente.", "OK", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show("No se pudo cargar el planeta. Asegurese de completar todos los campos.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } txtPlanetaNombre.Text = String.Empty; txtOrbitaPlaneta.Text = String.Empty; numericUpDownRotacionPlaneta.Value = 0; numericUpDownLunas.Value = 0; comboBoxTipoPlaneta.Text = String.Empty; }
public void PronosticarClimaIndeterminado() { var list = new List <Planeta>(); var planeta = new Planeta { PlanetaId = 1, Posicion = 60, Distancia = 100 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 2, Posicion = 90, Distancia = 300 }; list.Add(planeta); planeta = new Planeta { PlanetaId = 3, Posicion = 150, Distancia = 450 }; list.Add(planeta); var service = new PronosticoService(null, null); var clima = service.PronosticarClimaDePlanetas(list); Assert.AreEqual(clima, ClimaConstants.Indeterminado); }
private void BtnAgregarPlaneta_Click(object sender, EventArgs e) { if (numCantSatelites.Value>0 && numRotacion.Value>0 && txtNombrePlaneta.Text!="" && txtOrbitaPlaneta.Text!="") { int resultado; resultado = Convert.ToInt32(txtOrbitaPlaneta.Text); ETipo tipo; if (cmbTipo.Text == "Gaseoso") { tipo = ETipo.Gaseoso; Planeta nuevo = new Planeta(resultado, (int)numRotacion.Value, txtNombrePlaneta.Text, (int)numCantSatelites.Value, tipo); planetas.Add(nuevo); cmbPlanetas.Items.Add(nuevo); } else if (cmbTipo.Text == "Rocoso") { tipo = ETipo.Rocoso; Planeta nuevo = new Planeta(resultado, (int)numRotacion.Value, txtNombrePlaneta.Text, (int)numCantSatelites.Value, tipo); planetas.Add(nuevo); cmbPlanetas.Items.Add(nuevo); } } }
public void GuardarArchivo() { Xml <Planeta> xml = new Xml <Planeta>(); Planeta hola = new Planeta(); xml.Guardar("", hola); }
//Inicializo el controlador y cargo la data de planetas //Inicializo el servicio cargandole la data de los 3 planetas //NOTA: //Se coloca con signo negativo a los que tiene avance de signo positivo //debido a que los grados aumentan en sentido antihorario //usando el sistema sexagesimal que es el mas parecido a la rotacion de un planeta respecto al eje public PronosticoController() { Planeta ferengi = new Planeta("Ferengi", 500, 1, -1); Planeta betasoide = new Planeta("Betasoide", 2000, 3, -1); Planeta vulcano = new Planeta("Vulcano", 1000, 5, 1); Service.Init(ferengi, betasoide, vulcano); }
public void CargarMalDirectorio() { Planeta planeta = new Planeta(); Xml <Planeta> xml = new Xml <Planeta>(); xml.Guardar(null, planeta); }
public void GuardarPlaneta() { //Arrange Planeta <Satelite> jupiter = new Planeta <Satelite>(100, 30, "Jupiter", 2, Tipo.Rocoso); //Act & Assert Assert.IsTrue(AstroExtension.GuardarPlanTxt(jupiter)); }
public void AnguloMayor360SeNormaliza() { var angulo = new Random().Next(360, 9999); var planeta = new Planeta(1, 1, true, "foo", angulo); Assert.True(planeta.Angulo > 0); Assert.True(planeta.Angulo < 360); }
public void TestArchivo() { Xml <Planeta> xml = new Xml <Planeta>(); Planeta p = new Planeta(); string path = ""; xml.Guardar(path, p); }