Example #1
0
        public static void GuardarPartida()
        {
            string farmName     = PartidaList[0].FarmName;
            string adjustedName = farmName + DateTime.Now.ToString();

            Partida.Almacenar_Partida(PartidaList, adjustedName);


            Alimento.Almacenar_Alimentos(PartidaList[0].PlayerAnimalFood, adjustedName);
            Alimento.Almacenar_Alimentos(PartidaList[0].PlayerFertilizerList, adjustedName);
            Alimento.Almacenar_Alimentos(PartidaList[0].PlayerAnimalWater, adjustedName);
            Alimento.Almacenar_Alimentos(PartidaList[0].PlayerPlantWater, adjustedName);
            Cattle.Almacenar_Ganado(PartidaList[0].PlayerBoughtCattle, adjustedName);
            Map.Almacenar_Mapa(PartidaList[0].Map, adjustedName);
            Plantation.Almacenar_Plantacion(PartidaList[0].PlayerPlantation, adjustedName);
            Remedio.Almacenar_Remedios(PartidaList[0].PlayerVaccines, adjustedName);
            Remedio.Almacenar_Remedios(PartidaList[0].PlayerFungicides, adjustedName);
            Remedio.Almacenar_Remedios(PartidaList[0].PlayerPesticides, adjustedName);
            Remedio.Almacenar_Remedios(PartidaList[0].PlayerHerbicides, adjustedName);
        }
Example #2
0
        private void FinishedProductButton_Click(object sender, EventArgs e)
        {
            /*Si alguna plantación o ganado ha llegado a su madurez
             * final, el jugador debe poder obtener su producto terminado. Para esto, pueden ocurrir
             * dos casos, si el jugador no tiene un bodega en su terreno o todas las bodegas están
             * a su capacidad máxima, entonces esta acción debe sacar la plantación/ganado del
             * terreno y venderla a precio mercado, sumando instantáneamente la venta al dinero del
             * jugador (recordar que la ganancia final de la venta es el precio de mercado
             * x calidad del producto terminado). Por otra parte, si el jugador posee espacio
             * en alguna bodega, entonces esta acción debe sacar la plantación/ganado del terreno
             * y guardar el producto en la bodega, de esta manera el jugador puede decidir cuándo
             * venderla. Es importante mencionar, que al momento de ejecutar esta acción se debe
             * calcular la calidad del producto terminado, la cual varía dependiendo del origen:
             * ⋄ Plantación: Salud x Calidad del terreno x Proporción de tierra del terreno
             * ⋄ Ganado: Salud x Unidades Actuales/ Unidades originales (Las unidades originales
             * del ganado dependen de la cantidad de tierra del terreno, esta se
             * calcula como: Unidades por defecto del animal x Proporción de tierra
             * del terreno.
             */

            List <Plantation> plantationList       = Juego.PartidaList[0].PlayerPlantation;
            List <Plantation> maturePlantationList = new List <Plantation>();
            List <Animal>     animalList           = Juego.PartidaList[0].PlayerAnimals;
            List <Animal>     matureAnimalList     = new List <Animal>();

            //Calidad plantación: Salud x Calidad del terreno x Proporción de tierra del terreno.
            foreach (Plantation p in plantationList)
            {
                double quality  = p.Health;
                int    maturity = p.Maturity;
                if (maturity >= 100)
                {
                    maturePlantationList.Add(p);
                    Juego.PartidaList[0].PlayerPlantation.Remove(p);
                }
            }

            /* ⋄ Ganado: Salud x Unidades Actuales/ Unidades originales (Las unidades originales
             * del ganado dependen de la cantidad de tierra del terreno, esta se
             * calcula como: Unidades por defecto del animal x Proporción de tierra
             * del terreno.
             */
            int storageAmount = Juego.PartidaList[0].playerBoughtStorage.Count;

            foreach (Animal a in animalList)
            {
                int maturity = a.Maturity;
                if (maturity >= 100)
                {
                    matureAnimalList.Add(a);
                    Juego.PartidaList[0].PlayerAnimals.Remove(a);
                }
            }

            // Acá se encarga de agarrar las plantas y ganados maduros y dejarlos en
            // los StorageBuilding disponibles.
            for (int i = 0; i < storageAmount; i++)
            {
                if (Juego.PartidaList[0].playerBoughtStorage[i].IsFull == false)
                {
                    while (matureAnimalList.Count != 0 ||
                           Juego.PartidaList[0].playerBoughtStorage[i].Guardado.Count <=
                           Juego.PartidaList[0].playerBoughtStorage[i].Maxcapacity)
                    {
                        Animal a = matureAnimalList[0];
                        Juego.PartidaList[0].playerBoughtStorage[i].Guardado.Add(a);
                        matureAnimalList.RemoveAt(0);
                    }

                    while (maturePlantationList.Count != 0 ||
                           Juego.PartidaList[0].playerBoughtStorage[i].Guardado.Count <=
                           Juego.PartidaList[0].playerBoughtStorage[i].Maxcapacity)
                    {
                        Plantation p = maturePlantationList[0];
                        Juego.PartidaList[0].playerBoughtStorage[i].Guardado.Add(p);
                        //Hay que encontrar una manera de poder guardar las plantas maduras en StorageBuilding.
                        maturePlantationList.RemoveAt(0);
                    }
                }
            }

            foreach (StorageBuilding sb in Juego.PartidaList[0].playerBoughtStorage)
            {
                int maxcapacity = sb.Maxcapacity;

                if (sb.Guardado.Count >= maxcapacity)
                {
                    sb.IsFull = true;
                }
            }

            // Falta multiplicar el precio de venta por la calidad del producto.
            int totalSellingPrice = 0;

            if (matureAnimalList.Count != 0)
            {
                foreach (Animal a in matureAnimalList)
                {
                    int sellingPrice = a.BaseSellingPrice;
                    totalSellingPrice += sellingPrice;
                }
            }

            if (maturePlantationList.Count != 0)
            {
                foreach (Plantation p in maturePlantationList)
                {
                    int sellingPrice = p.SalesPrice;
                    totalSellingPrice += sellingPrice;
                }
            }

            Juego.PartidaList[0].PlayerCash += totalSellingPrice;
        }