Beispiel #1
0
        /// <summary>
        /// This method creates the specified number of videogames, using random data from the videogame list also provided
        /// </summary>
        /// <param name="numberOfVideogames">Number of videogames to be created</param>
        /// <returns>An array of Videogame instances, fully instantiated from the videogame data</returns>
        public static Videogame[] CreateRandomVideoGames(int numberOfVideogames = 100)
        {
            Videogame[] listing = new Videogame[numberOfVideogames];
            Random      random  = new Random();

            string[,] data = null;
            Platform platform = Platform.PS3;

            for (int i = 0; i < numberOfVideogames; i++)
            {
                int platformNumber = random.Next(0, 3);
                if (platformNumber == 0)
                {
                    data     = RandomVideogameGeneratorData.Ps3Games;
                    platform = Platform.PS3;
                }

                if (platformNumber == 1)
                {
                    data     = RandomVideogameGeneratorData.XBox360Games;
                    platform = Platform.Xbox360;
                }

                if (platformNumber == 2)
                {
                    data     = RandomVideogameGeneratorData.WiiGames;
                    platform = Platform.Wii;
                }

                int gameNumber = random.Next(0, data.GetLength(0));

                int year = 2020;
                try
                {
                    year = int.Parse(data[gameNumber, 2]);
                }
                catch (Exception)
                {
                    //A non-valid year means that year = 2020
                }
                listing[i] = new Videogame
                {
                    Title               = data[gameNumber, 0],
                    Platform            = platform,
                    Year                = year,
                    Genre               = data[gameNumber, 3],
                    Editor              = data[gameNumber, 4],
                    AmericaSales        = double.Parse(data[gameNumber, 5].Replace(".", ",")),
                    EuropeSales         = double.Parse(data[gameNumber, 6].Replace(".", ",")),
                    JapanSales          = double.Parse(data[gameNumber, 7].Replace(".", ",")),
                    RestOfTheWorldSales = double.Parse(data[gameNumber, 8].Replace(".", ",")),
                    AvailableUnits      = random.Next(10, 100),
                };
            }
            return(listing);
        }
Beispiel #2
0
        public override bool Equals(object obj)
        {
            Videogame videogame = obj as Videogame;

            if (videogame == null)
            {
                return(false);
            }
            return(this.Title.Equals(videogame.Title));
        }