Exemple #1
0
        public IField CreateField(int x, int y, Robot robot)
        {
            this.robot = robot;
            var resArr = new IGameObject[x, y];

            robot.GetPosY = 0;
            robot.GetPosX = 0;
            resArr[robot.GetPosY, robot.GetPosX] = robot;
            int cargoAmount = x * 3;
            var rand        = new Random();

            for (int i = 0; i < cargoAmount; i++)
            {
                int  px        = rand.Next(0, x);
                int  py        = rand.Next(0, y);
                Type typecargo = PickCargoType();
                this.cargoFactory = PickFactory(typecargo);
                var cargo = this.cargoFactory.CreateCargo(px, py);

                if (resArr[py, px] == null)
                {
                    resArr[py, px] = cargo;
                }
            }

            var res = new Field(resArr, robot);

            return(res);
        }
Exemple #2
0
        private CargoAbstractFactory PickFactory(Type type1)
        {
            CargoAbstractFactory res = null;

            if (type1 == typeof(ToxicCargo))
            {
                res = new ToxicCargoFactory();
            }
            else if (type1 == typeof(SpoilableCargo))
            {
                res = new SpoilableCargoFactory();
            }
            else if (type1 == typeof(ProtectedCargo))
            {
                res = new ProtectedCargoFactory();
            }
            else if (type1 == typeof(Cargo))
            {
                res = new CargoFactory();
            }

            return(res);
        }