Example #1
0
        /// <summary >
        /// Updates the game settings with user defined parameters.
        /// Iterates through the settings array and sets each one in order,
        /// by comparing it to the arguments array.
        /// Uses an exception to catch badly formatted parameters and
        /// The validation class to validate parameters.
        /// </ summary >
        /// <param name =" args " >String arguments that initialise the Game of Life settings</ param >
        public void set(string[] args)
        {
            int    pos = -1;
            int    parameterInt;
            double parameterDouble;

            foreach (string op in Options) //Sets each setting in the pre-defined order.
            {
                pos = Array.IndexOf(args, op);
                if (pos > -1)
                {
                    try
                    {
                        switch (op)
                        {
                        case "--dimensions":    //sets the dimensions of the universe...
                            parameterInt = int.Parse(args[pos + 2]);
                            if (validate.dimensions(parameterInt))
                            {
                                columns = parameterInt;
                            }
                            parameterInt = int.Parse(args[pos + 1]);
                            if (validate.dimensions(parameterInt))
                            {
                                rows = parameterInt;
                            }
                            break;

                        case "--periodic":     //turn on periodic mode
                            periodicBehavior = true;
                            break;

                        case "--random":    //sets the likelyhood that a cell is born initially...
                            parameterDouble = double.Parse(args[pos + 1]);
                            if (validate.randomFactor(parameterDouble))
                            {
                                randomFactor = parameterDouble;
                            }
                            break;

                        case "--seed":    //sets the path to .seed file
                            if (validate.seed(args[pos + 1]))
                            {
                                seed = args[pos + 1];
                            }
                            break;

                        case "--generations":    //sets the maximum number of generations...
                            parameterInt = int.Parse(args[pos + 1]);
                            if (validate.generations(parameterInt))
                            {
                                generations = parameterInt;
                            }
                            break;

                        case "--max-update":    //sets the maximum rate of generations per second...
                            parameterDouble = double.Parse(args[pos + 1]);
                            if (validate.updateRate(parameterDouble))
                            {
                                updateRate = parameterDouble;
                            }
                            break;

                        case "--step":    //turn on step mode
                            stepMode = true;
                            break;

                        case "--neighbour":     //sets neighbourhood type, order and centre cell switch
                            readNeighbour(pos, args);
                            break;

                        case "--survival":     //sets number of cells for survival
                            readSB(pos, args, survival);
                            break;

                        case "--birth":     //sets the number of cells for birth
                            readSB(pos, args, birth);
                            break;

                        case "--memory":    //Sets memory size
                            parameterInt = int.Parse(args[pos + 1]);
                            if (validate.memory(parameterInt))
                            {
                                memory = parameterInt;
                            }
                            break;

                        case "--output":    //sets the path to output .seed file
                            if (validate.seed(args[pos + 1]))
                            {
                                output = args[pos + 1];
                            }
                            break;

                        case "--ghost":    //sets the path to output .seed file
                            ghostMode = true;
                            break;
                        }
                    }
                    catch (Exception) //catches badly formatted parameters
                    {
                        validate.invalid(args[pos] + " has an invalid parameter");
                    }
                }
            }
            if (validate.success) //when all arguments are read correctly
            {
                Console.ForegroundColor = ConsoleColor.Green;
                centerText("Successfully read arguments");
            }
        }