Пример #1
0
 //kevin Model constructor
 public KevinModel(SharedVariables variables)
 {
     _variables = variables;
 }
Пример #2
0
        //modelwrapper constructor
        public ModelWrapper(int numCols, int numRows)
        {
            int farmPosX = numCols / 2;
            int farmPosY = numRows / 2;

            // Set SharedVariables as a variable with parameters passing through
            _variables = new SharedVariables(numCols, numRows);
            // Set each names variables to each of the people's models
            _model1 = new KevinModel(_variables);
            _model2 = new CindyModel(_variables);
            _model3 = new MaxModel(_variables);

            //Loop through all the columns of the grid
            for (int cols = 0; cols < _variables.Land.GetLength(0); cols++)
            {
                //Loop through all the rows of the grid
                for (int rows = 0; rows < _variables.Land.GetLength(1); rows++)
                {
                    // if the the column is in the current farm position x and rows is in the current position of y
                    if (cols == farmPosX && rows == farmPosY)
                    {
                        // Then the colony is a farm
                        _variables.Colony[cols, rows] = new Farm();
                        // and the land is an emptyland
                        _variables.Land[cols, rows] = new EmptyLand();
                    }

                    // if the columns position is left of the current position and rows is still the same position
                    else if (cols == farmPosX - 1 && rows == farmPosY)
                    {
                        // Then the colony is a farm
                        _variables.Colony[cols, rows] = new Farm();
                        // and the land is an emptyland
                        _variables.Land[cols, rows] = new EmptyLand();
                    }

                    // If the column is in current position and rows is below of position
                    else if (cols == farmPosX && rows == farmPosY - 1)
                    {
                        // Then the colony is a residence
                        _variables.Colony[cols, rows] = new Residence();
                        // and the land is an emptyland
                        _variables.Land[cols, rows] = new EmptyLand();
                    }

                    //If columns is left and rows is below of the current position
                    else if (cols == farmPosX - 1 && rows == farmPosY - 1)
                    {
                        // Then the colony is a police station
                        _variables.Colony[cols, rows] = new PoliceStation();
                        // and the land is an emptyland
                        _variables.Land[cols, rows] = new EmptyLand();
                    }
                    else
                    {
                        // Then the colony is a wilderness
                        _variables.Colony[cols, rows] = new Wilderness();
                        // and the land is an wilderness
                        _variables.Land[cols, rows] = new Wilderness();
                    }
                }
            }
        }
Пример #3
0
 //constructor for MaxModel that passes in sharedvariables as parameter
 public MaxModel(SharedVariables variables)
 {
     //save the variables in a variables
     _variables = variables;
 }