private void btnGravar_Click(object sender, EventArgs e) { try { var grupo = (GrupoVegetal)cbxGrupo.SelectedItem; var vegetal = new Vegetal { Codigo = ObterCodigo(), Nome = txtNome.Text, Tamanho = txtTam.Text, GrupoVegetal = grupo, GrupoVegetal_Codigo = grupo?.Codigo ?? 0 }; var logica = new VegetalLogica(); logica.Salvar(vegetal); MessageBox.Show("Salvo com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information); LimparCampos(); txtNome.Focus(); } catch (ArgumentNullException) { MessageBox.Show("Os campos em negrito são obrigatórios!", "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void Editar(Vegetal vegetal) { try { var query = "update Vegetais set Nome = @Nome, Tamanho = @Tamanho, CodigoGrupo = @CodigoGrupo where Codigo = @Codigo"; var cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@Codigo", vegetal.Codigo); cmd.Parameters.AddWithValue("@Nome", vegetal.Nome); cmd.Parameters.AddWithValue("@Tamanho", vegetal.Tamanho); cmd.Parameters.AddWithValue("@Codigo", vegetal.GrupoVegetal_Codigo); conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } }
private void Editar(Vegetal vegetal) { try { dados.Editar(vegetal); } catch (Exception) { throw; } }
private void Inserir(Vegetal vegetal) { try { dados.Inserir(vegetal); } catch (Exception) { throw; } }
public List <Vegetal> Listar() { try { var query = "select veg.*, grp.Nome as NomeGrupo from Vegetais as veg join GruposVegetais as grp on veg.CodigoGrupo = grp.Codigo"; var cmd = new SqlCommand(query, conn); var vegetais = new List <Vegetal>(); conn.Open(); var datareader = cmd.ExecuteReader(); if (datareader.HasRows) { while (datareader.Read()) { var vegetal = new Vegetal(); vegetal.Codigo = Convert.ToInt32(datareader["Codigo"].ToString()); vegetal.Nome = datareader["Nome"].ToString(); vegetal.Tamanho = datareader["Tamanho"].ToString(); vegetal.GrupoVegetal_Codigo = Convert.ToInt32(datareader["CodigoGrupo"].ToString()); vegetal.GrupoVegetal = new GrupoVegetal { Codigo = Convert.ToInt32(datareader["CodigoGrupo"].ToString()), Nome = datareader["NomeGrupo"].ToString() }; vegetais.Add(vegetal); } } return(vegetais); } catch (Exception) { throw; } finally { conn.Close(); } }
private static VegetalSerializable getVegetalSerializable(Vegetal veg) { VegetalSerializable resultado = new VegetalSerializable(); resultado.idSer = veg.idSer; resultado.numVegetales = veg.numVegetales; resultado.posX = veg.posX; resultado.posY = veg.posY; resultado.modelo = getModeloSerializable(veg.especie); resultado.especie = getEspecieVegSerializable(veg.especie); resultado.indiceHabitat = veg.indiceHabitat; resultado.turnosEvolucion = veg.turnosEvolucion; resultado.habitabilidad = new List <float>(); for (int i = 0; i < veg.habitabilidad.Count; i++) { resultado.habitabilidad.Add(veg.habitabilidad[i]); } return(resultado); }
public Vegetal Encontrar(int codigo) { try { var query = "select veg.*, grp.Nome as NomeGrupo from Vegetais as veg join GruposVegetais as grp on veg.CodigoGrupo = grp.Codigo where veg.Codigo = @Codigo "; var cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@Codigo", codigo); conn.Open(); var datareader = cmd.ExecuteReader(); var vegetal = new Vegetal(); if (datareader.HasRows) { datareader.Read(); vegetal.Codigo = Convert.ToInt32(datareader["Codigo"].ToString()); vegetal.Nome = datareader["Nome"].ToString(); vegetal.Tamanho = datareader["Tamanho"].ToString(); vegetal.GrupoVegetal_Codigo = Convert.ToInt32(datareader["CodigoGrupo"].ToString()); vegetal.GrupoVegetal = new GrupoVegetal { Codigo = Convert.ToInt32(datareader["CodigoGrupo"].ToString()), Nome = datareader["NomeGrupo"].ToString() }; } return(vegetal); } catch (Exception) { throw; } finally { conn.Close(); } }
public void Salvar(Vegetal vegetal) { try { if (string.IsNullOrEmpty(vegetal.Nome) || string.IsNullOrEmpty(vegetal.Tamanho) || vegetal.GrupoVegetal_Codigo == 0) { throw new ArgumentNullException(); } if (vegetal.Codigo == 0) { Inserir(vegetal); } else { Editar(vegetal); } } catch (Exception) { throw; } }
public void Inserir(Vegetal vegetal) { try { var query = "insert into Vegetais (Nome, Tamanho, CodigoGrupo) values (@Nome, @Tamanho, @CodigoGrupo)"; var cmd = new SqlCommand(query, conn); cmd.Parameters.AddWithValue("@Nome", vegetal.Nome); cmd.Parameters.AddWithValue("@Tamanho", vegetal.Tamanho); cmd.Parameters.AddWithValue("@CodigoGrupo", vegetal.GrupoVegetal_Codigo); conn.Open(); cmd.ExecuteNonQuery(); } catch (Exception) { throw; } finally { conn.Close(); } }
private void insertarFertilizante() { if (accion == taccion.lanzarFertilizante) { int posX = 0; int posY = 0; RaycastHit hit; if (principal.raycastRoca (Input.mousePosition, ref posX, ref posY, out hit)) { vegetalFertilizante = principal.vida.tablero[posY, posX].vegetal; animalFertilizante = principal.vida.tablero[posY, posX].animal; if (Input.GetMouseButton (0)) { if (vegetalFertilizante != null || animalFertilizante != null) { List<int> costes = mejoras.costeHab5; if (principal.recursosSuficientes(costes[0], costes[1], costes[2], costes[3])) { principal.consumeRecursos(costes[0], costes[1], costes[2], costes[3]); principal.vida.fertilizanteBioQuimico(vegetalFertilizante, animalFertilizante, factorFertilizantePos); turnoFertilizante = principal.numPasos; fertilizanteActivo = true; } } else { Audio_SoundFX efectos = sonidoFX.GetComponent<Audio_SoundFX> (); efectos.playNumber (Random.Range (1, 3)); } accion = taccion.ninguna; } } } }
private static VegetalSerializable getVegetalSerializable(Vegetal veg) { VegetalSerializable resultado = new VegetalSerializable(); resultado.idSer = veg.idSer; resultado.numVegetales = veg.numVegetales; resultado.posX = veg.posX; resultado.posY = veg.posY; resultado.modelo = getModeloSerializable(veg.especie); resultado.especie = getEspecieVegSerializable(veg.especie); resultado.indiceHabitat = veg.indiceHabitat; resultado.turnosEvolucion = veg.turnosEvolucion; resultado.habitabilidad = new List<float>(); for (int i = 0; i < veg.habitabilidad.Count; i++) { resultado.habitabilidad.Add(veg.habitabilidad[i]); } return resultado; }
/*public bool anadeSer(Ser ser) { if(ser is Vegetal) { Vegetal vegetal = (Vegetal)ser; if(!compruebaAnadeVegetal(vegetal.especie,vegetal.habitabilidad,vegetal.posX,vegetal.posY)) return false; int turno = (turnoActual + vegetal.especie.siguienteTurno)%numMaxTurnos; listadoSeresTurnos[turno].Add(vegetal); idActualVegetal++; vegetales.Add(vegetal); tablero[vegetal.posX,vegetal.posY].vegetal = vegetal; pintaPlantasTex(vegetal.posX,vegetal.posY); } else if(ser is Animal) { Animal animal = (Animal)ser; if(!compruebaAnadeAnimal(animal.especie,animal.posX,animal.posY)) return false; int turno = (turnoActual + animal.especie.siguienteTurno)%numMaxTurnos; listadoSeresTurnos[turno].Add(animal); idActualAnimal++; animales.Add(animal); tablero[animal.posX,animal.posY].animal = animal; } else if(ser is Edificio) { Edificio edificio = (Edificio)ser; if(!compruebaAnadeEdificio(edificio.tipo,edificio.posX,edificio.posY)) return false; int turno = (turnoActual + edificio.tipo.siguienteTurno)%numMaxTurnos; listadoSeresTurnos[turno].Add(edificio); idActualEdificio++; edificios.Add(edificio); tablero[edificio.posX,edificio.posY].edificio = edificio; } seres.Add(ser); return true; }*/ //Elimina un vegetal, si no existe devuelve false public bool eliminaVegetal(Vegetal vegetal) { if(!vegetales.Contains(vegetal)) return false; for(int i = 0; i < vegetal.modelos.Count; i++) UnityEngine.Object.Destroy(vegetal.modelos[i]); //listadoSeresTurnos[turnoActual].Remove(vegetal); tablero[vegetal.posX,vegetal.posY].vegetal = null; seres.Remove(vegetal); vegetales.Remove(vegetal); vegetal.especie.numSeresEspecie--; return true; }
//Devuelve false si el vegetal ya existe (no se añade) y true si se añade correctamente public bool anadeVegetal(EspecieVegetal especie,List<float> habitabilidad,float habitabilidadMinima,int posX,int posY,Vector3 pos) { if(tieneEdificio(posX,posY) || tieneVegetal(posX,posY) || habitabilidad[(int)tablero[posX,posY].habitat] == habitabilidadMinima) return false; GameObject modelo = especie.modelos[UnityEngine.Random.Range(0,especie.modelos.Count)]; Vector3 coordsVert = pos; //Vector3 coordsVert = tablero[posX,posY].coordsVert; Vegetal vegetal = new Vegetal(idActualVegetal,especie,posX,posY,habitabilidad,tablero[posX,posY].habitat,FuncTablero.creaMesh(coordsVert, modelo)); //vegetal.modelos[0].transform.position = objetoRoca.TransformPoint(vegetal.modelos[0].transform.position); seres.Add(vegetal); //int turno = (turnoActual + especie.siguienteTurno)%numMaxTurnos; //listadoSeresTurnos[turno].Add(vegetal); idActualVegetal++; vegetales.Add(vegetal); tablero[posX,posY].vegetal = vegetal; especie.numSeresEspecie++; // pintaPlantasTex(posX,posY); return true; }
public void fertilizanteBioQuimico(Vegetal v,Animal a, float factor) { EspecieVegetal especieVegetal; if(v == null) especieVegetal = null; else especieVegetal = v.especie; EspecieAnimal especieAnimal; if(a == null) especieAnimal = null; else especieAnimal = a.especie; Vegetal vegetal; Animal animal; if(especieVegetal != null) for(int i = 0; i < vegetales.Count; i++) { vegetal = vegetales[i]; if(vegetal.especie == especieVegetal) vegetal.habitabilidad[vegetal.indiceHabitat] *= factor; } if(especieAnimal != null) { for(int i = 0; i < animales.Count; i++) { animal = animales[i]; if(animal.especie == especieAnimal) animal.turnosParaReproduccion = (int)((float)animal.turnosParaReproduccion/factor); } especiesAnimales[especiesAnimales.IndexOf(especieAnimal)].reproductibilidad = (int)((float)especiesAnimales[especiesAnimales.IndexOf(especieAnimal)].reproductibilidad / factor); } }
public CadastroVegetais(Menu menu, Vegetal vegetal) : this(menu) { _vegetal = vegetal; }
public Casilla(T_habitats hab, T_elementos elems, Vector2 coord, Vector3 vert) { habitat = hab; elementos = elems; coordsTex = coord; vegetal = null; animal = null; edificio = null; coordsVert = vert; }
private bool seleccionarObjetoTablero() { int x = 0; int y = 0; RaycastHit hit; if (principal.raycastRoca (Input.mousePosition, ref x, ref y, out hit)) { Edificio edificio = principal.vida.tablero[y, x].edificio; Vegetal vegetal = principal.vida.tablero[y, x].vegetal; Animal animal = principal.vida.tablero[y, x].animal; infoSeleccion.Clear (); animalSeleccionado = null; vegetalSeleccionado = null; edificioSeleccionado = null; if (animal != null || vegetal != null || edificio != null) { if (animal != null) { infoSeleccion.Add (animal.especie.nombre); //Cadena infoSeleccion[0] TiposSeres tiposSeres = GameObject.FindGameObjectWithTag ("TiposSeres").GetComponent<TiposSeres> (); tipoSeleccion = tiposSeres.getNumeroSer(animal.especie); infoSeleccion.Add (tiposSeres.getDescripcion (tipoSeleccion)); //Cadena infoSeleccion[1] habitabilidadSeleccion[0] = (animal.especie.habitats.Contains (T_habitats.montana)) ? 1 : -1; habitabilidadSeleccion[1] = animal.especie.habitats.Contains (T_habitats.llanura) ? 1 : -1; habitabilidadSeleccion[2] = animal.especie.habitats.Contains (T_habitats.colina) ? 1 : -1; habitabilidadSeleccion[3] = animal.especie.habitats.Contains (T_habitats.desierto) ? 1 : -1; habitabilidadSeleccion[4] = animal.especie.habitats.Contains (T_habitats.volcanico) ? 1 : -1; habitabilidadSeleccion[6] = animal.especie.habitats.Contains (T_habitats.costa) ? 1 : -1; habitabilidadSeleccion[7] = animal.especie.habitats.Contains (T_habitats.tundra) ? 1 : -1; animalSeleccionado = animal; return true; } else if (vegetal != null) { infoSeleccion.Add (vegetal.especie.nombre); //Cadena infoSeleccion[0] TiposSeres temp = GameObject.FindGameObjectWithTag ("TiposSeres").GetComponent<TiposSeres> (); tipoSeleccion = temp.getNumeroSer(vegetal.especie); infoSeleccion.Add (temp.getDescripcion (tipoSeleccion)); //Cadena infoSeleccion[1] habitabilidadSeleccion[0] = vegetal.habitabilidad[0]; habitabilidadSeleccion[1] = vegetal.habitabilidad[1]; habitabilidadSeleccion[2] = vegetal.habitabilidad[2]; habitabilidadSeleccion[3] = vegetal.habitabilidad[3]; habitabilidadSeleccion[4] = vegetal.habitabilidad[4]; habitabilidadSeleccion[6] = vegetal.habitabilidad[6]; habitabilidadSeleccion[7] = vegetal.habitabilidad[7]; vegetalSeleccionado = vegetal; return true; } else if (edificio != null) { infoSeleccion.Add (edificio.tipo.nombre); //Cadena infoSeleccion[0] TiposSeres temp = GameObject.FindGameObjectWithTag ("TiposSeres").GetComponent<TiposSeres> (); tipoSeleccion = temp.getNumeroSer(edificio.tipo); infoSeleccion.Add (temp.getDescripcion (tipoSeleccion)); //Cadena infoSeleccion[1] habitabilidadSeleccion[0] = edificio.tipo.habitats.Contains (T_habitats.montana) ? 1 : -1; habitabilidadSeleccion[1] = edificio.tipo.habitats.Contains (T_habitats.llanura) ? 1 : -1; habitabilidadSeleccion[2] = edificio.tipo.habitats.Contains (T_habitats.colina) ? 1 : -1; habitabilidadSeleccion[3] = edificio.tipo.habitats.Contains (T_habitats.desierto) ? 1 : -1; habitabilidadSeleccion[4] = edificio.tipo.habitats.Contains (T_habitats.volcanico) ? 1 : -1; habitabilidadSeleccion[6] = edificio.tipo.habitats.Contains (T_habitats.costa) ? 1 : -1; habitabilidadSeleccion[7] = edificio.tipo.habitats.Contains (T_habitats.tundra) ? 1 : -1; //TODO Poner aqui la info escrita que necesitemos para los edificios edificioSeleccionado = edificio; return true; } } //Si la casilla esta vacia... tipoSeleccion = -1; return false; } //Si el raycast falla... tipoSeleccion = -1; return false; }
public void actualizaModelosVegetal(Vegetal vegetal) { float cantidad = (float)(vegetal.numVegetales)/(float)(vegetal.especie.numMaxVegetales); int numModelos = (int)(vegetal.especie.numMaxModelos * cantidad); if(numModelos > vegetal.modelos.Count) { GameObject modelo = vegetal.especie.modelos[UnityEngine.Random.Range(0,vegetal.especie.modelos.Count)]; Vector3 coordsVert = posicionAleatoriaVegetal(vegetal.posX,vegetal.posY); modelo = FuncTablero.creaMesh(coordsVert, modelo); modelo.transform.position = objetoRoca.TransformPoint(modelo.transform.position); vegetal.modelos.Add(modelo); } else if (numModelos < vegetal.modelos.Count && vegetal.modelos.Count > 1) { UnityEngine.Object.Destroy(vegetal.modelos[vegetal.modelos.Count-1]); vegetal.modelos.RemoveAt(vegetal.modelos.Count-1); } }