Esempio n. 1
0
        public static IAzienda FactoryAzienda(int scelta)
        {
            IAzienda azienda = null;

            //creazione sulla base del param
            if (scelta <= 20)
            {
                azienda = new Piccola();
            }
            else if (scelta <= 100)
            {
                azienda = new Media();
            }
            else if (scelta <= 500)
            {
                azienda = new Grande();
            }
            else if (scelta >= 500)
            {
                azienda = new Multinazionale();
            }
            else
            {
                return(azienda);
            }

            return(azienda);
        }
Esempio n. 2
0
        /// <summary>
        /// Removing the car from database.
        /// </summary>
        /// <param name="a9">Asphalt9Entities</param>
        /// <param name="carToDelete">Car to delete.</param>
        /// <param name="transaction">Transaction.</param>
        /// <returns></returns>
        private async Task DeleteCarAsync(Asphalt9Entities a9, Grande carToDelete, DbContextTransaction transaction)
        {
            await Task.Run(() =>
            {
                // Removing the entity related to the requested car to delete.
                a9.Grandes.Remove(carToDelete);

                // saving changes.
                a9.SaveChanges();

                // committing the saved changes into the database.
                transaction.Commit();
            });
        }
Esempio n. 3
0
        public void Reset()
        {
            VictoryPoints         = 0;
            Money                 = 0;
            NumberOfRounds        = 0;
            ResidualMoney         = 0;
            RemainingBonusActions = 0;
            Round                 = 1;

            Hand = new Hand();

            VineDeck          = new Deck <VineCard>(Hand, _vineCards);
            OrderDeck         = new Deck <OrderCard>(Hand, _orderCards);
            AutomaDeck        = new Deck <AutomaCard>(Hand, _automaCards);
            SummerVisitorDeck = new Deck <VisitorCard>(Hand, _visitorCards.Where(p => p.Season == Season.Summer));
            WinterVisitorDeck = new Deck <VisitorCard>(Hand, _visitorCards.Where(p => p.Season == Season.Winter));

            Yoke         = new Yoke(_eventAggregator);
            Trellis      = new Trellis(_eventAggregator);
            Cottage      = new Cottage(_eventAggregator);
            Windmill     = new Windmill(_eventAggregator);
            Irigation    = new Irigation(_eventAggregator);
            LargeCellar  = new LargeCellar(_eventAggregator);
            TastingRoom  = new TastingRoom(_eventAggregator);
            MediumCellar = new MediumCellar(_eventAggregator);

            Field1 = new Field(_eventAggregator, 5);
            Field2 = new Field(_eventAggregator, 6);
            Field3 = new Field(_eventAggregator, 7);

            Grande        = new Grande(_eventAggregator);
            NeutralWorker = new Worker(_eventAggregator);

            _workers = new List <Worker>();
            for (var i = 0; i < 5; i++)
            {
                _workers.Add(new Worker(_eventAggregator));
            }

            InitializeGrapes(out _redGrapes, GrapeColor.Red);
            InitializeGrapes(out _whiteGrapes, GrapeColor.White);

            InitializeWines(out _redWines, WineType.Red, 9);
            InitializeWines(out _whiteWines, WineType.White, 9);
            InitializeWines(out _blushWines, WineType.Blush, 6);
            InitializeWines(out _sparklingWines, WineType.Sparkling, 3);
        }
Esempio n. 4
0
        public static void Alta(Animal a)
        {
            Animal a2;

            if (a.Peso <= 10)
            {
                a2 = new Pequeño();
            }
            else if (a.Peso > 10 && a.Peso <= 250)
            {
                a2 = new Mediano();
            }
            else
            {
                a2 = new Grande();
            }

            a2.Especie = a.Especie;
            a2.Peso    = a.Peso;
            Lista.Add(a2);
        }
        /// <summary>
        /// Adding the new car asynchronously.
        /// </summary>
        /// <returns></returns>
        private async Task AddCarAsync()
        {
            using (var a9 = new Asphalt9Entities())
            {
                using (var transaction = a9.Database.BeginTransaction())
                {
                    try
                    {
                        // creating new entity with the given car information by the user.
                        var newCar = new Grande
                        {
                            Brand       = Car.CarBrand,
                            CarName     = Car.CarName,
                            CarClass    = Car.CarClass,
                            CarType     = Enum.Parse(typeof(CarType), Car.Type).ToString(),
                            Fuel        = Car.Fuel,
                            CarImage    = string.Concat(Car.CarClass.ToLower(), "_", ImageName),
                            Refill      = Car.Refill,
                            ReleaseDate = Car.ReleaseDate,
                            Stars       = Car.Stars,

                            // every single grande entity has the links with other entities via foreign key created in database.

                            Blueprint = new Entities.Blueprint()
                            {
                                FirstStarBP  = Car.Blueprints.FirstStar,
                                SecondStarBP = Car.Blueprints.SecondStar,
                                ThirdStarBP  = Car.Blueprints.ThirdStar,
                                FourthStarBP = Car.Blueprints.FourthStar,
                                FifthStarBP  = Car.Blueprints.FifthStar,
                                SixthStarBP  = Car.Blueprints.SixthStar,
                                TotalBP      = Car.Blueprints.Total
                            },

                            StockDetail = new StockDetail()
                            {
                                TopSpeed     = Car.Performance.StockTopSpeed,
                                Acceleration = Car.Performance.StockAcceleration,
                                Handling     = Car.Performance.StockHandling,
                                Nitro        = Car.Performance.StockNitro,
                            },

                            MaxDetail = new MaxDetail()
                            {
                                TopSpeed     = Car.Performance.MaxTopSpeed,
                                Acceleration = Car.Performance.MaxAcceleration,
                                Handling     = Car.Performance.MaxHandling,
                                Nitro        = Car.Performance.MaxNitro,
                            },

                            StarRank = new StarRank()
                            {
                                StockStarRank  = Car.Ranks.Stock,
                                FirstStarRank  = Car.Ranks.FirstStar,
                                SecondStarRank = Car.Ranks.SecondStar,
                                ThirdStarRank  = Car.Ranks.ThirdStar,
                                FourthStarRank = Car.Ranks.FourthStar,
                                FifthStarRank  = Car.Ranks.FifthStar,
                                SixthStarRank  = Car.Ranks.SixthStar,
                                Max            = Car.Ranks.Max
                            },

                            Upgrade = new Upgrade()
                            {
                                Stage1  = Car.Upgrades.Stage0,
                                Stage2  = Car.Upgrades.Stage1,
                                Stage3  = Car.Upgrades.Stage2,
                                Stage4  = Car.Upgrades.Stage3,
                                Stage5  = Car.Upgrades.Stage4,
                                Stage6  = Car.Upgrades.Stage5,
                                Stage7  = Car.Upgrades.Stage6,
                                Stage8  = Car.Upgrades.Stage7,
                                Stage9  = Car.Upgrades.Stage8,
                                Stage10 = Car.Upgrades.Stage9,
                                Stage11 = Car.Upgrades.Stage10,
                                Stage12 = Car.Upgrades.Stage11,
                                Stage13 = Car.Upgrades.Stage12,
                                Total   = Car.Upgrades.TotalStagesCost
                            },

                            UncommonPart = new UncommonPart()
                            {
                                Cost      = Car.AdditionalParts.UncommonCost,
                                Quantity  = Car.AdditionalParts.UncommonQuantity,
                                TotalCost = Car.AdditionalParts.UncommonTotalCost
                            },

                            RarePart = new RarePart()
                            {
                                Cost      = Car.AdditionalParts.RareCost,
                                Quantity  = Car.AdditionalParts.RareQuantity,
                                TotalCost = Car.AdditionalParts.RareTotalCost
                            },

                            EpicPart = new EpicPart()
                            {
                                Cost      = Car.AdditionalParts.EpicCost,
                                Quantity  = Car.AdditionalParts.EpicQuantity,
                                TotalCost = Car.AdditionalParts.EpicTotalCost
                            }
                        };

                        // here we check if the current car is new or already exist.
                        if (a9.Grandes
                            .Any(item => string.Concat(item.Brand, " ", item.CarName) ==
                                 string.Concat(newCar.Brand, " ", newCar.CarName)))
                        {
                            Status = "Another car with same name is already exists!";
                            return;
                        }

                        // Adding new Car
                        a9.Grandes.Add(newCar);

                        // saving the addition.
                        a9.SaveChanges();

                        // Committing the addition of the new car into the database.
                        transaction.Commit();

                        // Saving the image into app image directory.
                        await Task.Run(() =>
                        {
                            var encoder = new PngBitmapEncoder();

                            encoder.Frames.Add(item: BitmapFrame.Create(source: CarImage));

                            var imagePath = FileHelpers.ImagePath(imageName: newCar.CarImage);

                            using (var fileStream = new FileStream(path: imagePath, mode: FileMode.Create))
                            {
                                encoder.Save(stream: fileStream);
                            }
                        });

                        // Notifying the state of operation.
                        Status = $"{newCar.Brand} {newCar.CarName} has been added successfully.";
                    }
                    catch
                    {
                        // Rolling back adding the car in case an error occurred.
                        transaction.Rollback();
                        Status = @"Error occurred while adding the car!";
                    }
                }
            }
        }
Esempio n. 6
0
        public void SetFromClone(GameState clone)
        {
            VictoryPoints         = clone.VictoryPoints;
            Money                 = clone.Money;
            NumberOfRounds        = clone.NumberOfRounds;
            ResidualMoney         = clone.ResidualMoney;
            RemainingBonusActions = clone.RemainingBonusActions;
            Round                 = clone.Round;

            Hand.SetFromClone(clone.Hand, Entities);

            VineDeck.SetFromClone(clone.VineDeck, Entities);
            OrderDeck.SetFromClone(clone.OrderDeck, Entities);
            AutomaDeck.SetFromClone(clone.AutomaDeck, Entities);
            SummerVisitorDeck.SetFromClone(clone.SummerVisitorDeck, Entities);
            WinterVisitorDeck.SetFromClone(clone.WinterVisitorDeck, Entities);

            Yoke.SetFromClone(clone.Yoke, Entities);
            Trellis.SetFromClone(clone.Trellis, Entities);
            Cottage.SetFromClone(clone.Cottage, Entities);
            Windmill.SetFromClone(clone.Windmill, Entities);
            Irigation.SetFromClone(clone.Irigation, Entities);
            LargeCellar.SetFromClone(clone.LargeCellar, Entities);
            TastingRoom.SetFromClone(clone.TastingRoom, Entities);
            MediumCellar.SetFromClone(clone.MediumCellar, Entities);

            Field1.SetFromClone(clone.Field1, Entities);
            Field2.SetFromClone(clone.Field2, Entities);
            Field3.SetFromClone(clone.Field3, Entities);

            Grande.SetFromClone(clone.Grande, Entities);
            NeutralWorker.SetFromClone(clone.NeutralWorker, Entities);

            for (var i = 0; i < 5; i++)
            {
                _workers[i].SetFromClone(clone.Workers.ElementAt(i), Entities);
            }

            for (int i = 0; i < 9; i++)
            {
                _redGrapes[i].SetFromClone(clone._redGrapes[i], Entities);
            }

            for (int i = 0; i < 9; i++)
            {
                _whiteGrapes[i].SetFromClone(clone._whiteGrapes[i], Entities);
            }

            for (int i = 0; i < 9; i++)
            {
                _redWines[i].SetFromClone(clone._redWines[i], Entities);
            }

            for (int i = 0; i < 9; i++)
            {
                _whiteWines[i].SetFromClone(clone._whiteWines[i], Entities);
            }
            for (int i = 0; i < 6; i++)
            {
                _blushWines[i].SetFromClone(clone._blushWines[i], Entities);
            }
            for (int i = 0; i < 3; i++)
            {
                _sparklingWines[i].SetFromClone(clone._sparklingWines[i], Entities);
            }
        }
Esempio n. 7
0
        public GameState Clone()
        {
            var gameState = new GameState();

            gameState.VictoryPoints         = VictoryPoints;
            gameState.Money                 = Money;
            gameState.NumberOfRounds        = NumberOfRounds;
            gameState.ResidualMoney         = ResidualMoney;
            gameState.RemainingBonusActions = RemainingBonusActions;
            gameState.Round                 = Round;

            gameState.Hand = Hand.Clone() as Hand;

            gameState.VineDeck          = VineDeck.Clone();
            gameState.OrderDeck         = OrderDeck.Clone();
            gameState.AutomaDeck        = AutomaDeck.Clone();
            gameState.SummerVisitorDeck = SummerVisitorDeck.Clone();
            gameState.WinterVisitorDeck = WinterVisitorDeck.Clone();

            gameState.Yoke         = Yoke.Clone() as Yoke;
            gameState.Trellis      = Trellis.Clone() as Trellis;
            gameState.Cottage      = Cottage.Clone() as Cottage;
            gameState.Windmill     = Windmill.Clone() as Windmill;
            gameState.Irigation    = Irigation.Clone() as Irigation;
            gameState.LargeCellar  = LargeCellar.Clone() as LargeCellar;
            gameState.TastingRoom  = TastingRoom.Clone() as TastingRoom;
            gameState.MediumCellar = MediumCellar.Clone() as MediumCellar;

            gameState.Field1 = Field1.Clone() as Field;
            gameState.Field2 = Field2.Clone() as Field;
            gameState.Field3 = Field3.Clone() as Field;

            gameState.Grande        = Grande.Clone() as Grande;
            gameState.NeutralWorker = NeutralWorker.Clone() as Worker;

            gameState._workers = new List <Worker>();
            for (var i = 0; i < 5; i++)
            {
                gameState._workers.Add(_workers[i].Clone() as Worker);
            }

            gameState._redGrapes = new List <Grape>();
            foreach (var redGrape in _redGrapes)
            {
                gameState._redGrapes.Add(redGrape.Clone() as Grape);
            }

            gameState._whiteGrapes = new List <Grape>();
            foreach (var whiteGrape in _whiteGrapes)
            {
                gameState._whiteGrapes.Add(whiteGrape.Clone() as Grape);
            }

            gameState._redWines = new List <Wine>();
            foreach (var redWine in _redWines)
            {
                gameState._redWines.Add(redWine.Clone() as Wine);
            }

            gameState._whiteWines = new List <Wine>();
            foreach (var whiteWine in _whiteWines)
            {
                gameState._whiteWines.Add(whiteWine.Clone() as Wine);
            }

            gameState._blushWines = new List <Wine>();
            foreach (var blushWine in _blushWines)
            {
                gameState._blushWines.Add(blushWine.Clone() as Wine);
            }

            gameState._sparklingWines = new List <Wine>();
            foreach (var sparklingWine in _sparklingWines)
            {
                gameState._sparklingWines.Add(sparklingWine.Clone() as Wine);
            }

            return(gameState);
        }