コード例 #1
0
    /// <summary>
    /// Reads car data from a given file and stores it in a given list
    /// </summary>
    /// <param name="filePath">file to read from</param>
    /// <param name="list">list to store car data</param>
    public static void ReadCarData(string filePath, CarList list)
    {
        using (StreamReader reader = new StreamReader(filePath)) {
            string line = null;

            while ((line = reader.ReadLine()) != null)
            {
                string[] data = line.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries);

                CarData carData = new CarData(
                    data[0], data[1], data[2], int.Parse(data[3]), int.Parse(data[4]));

                list.AddCar(carData);
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// Loops through a list and stores all cars that are aged between
    /// minAge and maxAge in a new list
    /// </summary>
    /// <param name="cars">list of cars to pick from</param>
    /// <param name="minAge">minimum age of the car</param>
    /// <param name="maxAge">maximum age of the car</param>
    /// <returns>new list of cars aged between minAge and maxAge</returns>
    private CarList GetCarsAgedBetween(CarList cars, int minAge, int maxAge)
    {
        CarList newCars = new CarList();

        while (cars.MoveToNextElement())
        {
            int carAge = cars.GetCurrentElement().GetAge();

            if (carAge >= minAge && carAge <= maxAge)
            {
                newCars.AddCar(cars.GetCurrentElement());
            }
        }

        newCars.SortList();
        return(newCars);
    }
コード例 #3
0
 public void AddCar(GameObject gamePlayer)
 {
     _cars.AddCar(gamePlayer.GetComponent <CarController>());
 }