Beispiel #1
0
        public void StartLoading()
        {
            GetPanel <LoadingPanel>().OpenPanel();

            _invoker = GetSystem <CommandInvoker>();

            // create mission command
            var missionCommand = new LoadingCommand <MissionModel>(ApiList.Missions);

            missionCommand.OnComplete += result => _models.missions = result;
            _invoker.AddCommand(missionCommand);

            //create history command
            var historyCommand = new LoadingCommand <HistoryModel>(ApiList.History);

            historyCommand.OnComplete += result => _models.history = result;
            _invoker.AddCommand(historyCommand);

            //create rockets command
            var rocketsCommand = new LoadingCommand <RocketModel>(ApiList.Rockets);

            rocketsCommand.OnComplete += result => _models.rocket = result;
            _invoker.AddCommand(rocketsCommand);


            _invoker.OnComplete += LoadingComplete;
            _invoker.StartInvoker();
        }
Beispiel #2
0
        /// <summary>
        /// 根据表格的行信息执行控制
        /// </summary>
        /// <param name="model"></param>
        private void GetControlCommand(DeviceModel model, ref CommandInvoker cmdInvoker)
        {
            if (model == null)
            {
                return;
            }

            if (model.IsDoorOperate)
            {
                if (model.DoorOperateFlag == true)
                {
                    // 开门操作
                    OpenDoorCommand cmd = new OpenDoorCommand(Controller, model.DeviceNo);
                    cmdInvoker.AddCommand(cmd);
                }
                else
                {
                    // 关门操作
                    CloseDoorCommand cmd = new CloseDoorCommand(Controller, model.DeviceNo);
                    cmdInvoker.AddCommand(cmd);
                }
            }

            if (model.IsGoLayer)
            {
                // 走层操作
                RunCommand cmd = new RunCommand(Controller, model.DeviceNo);
                cmd.dstLayers = new int[1] {
                    model.DstLayerNo
                };
                cmdInvoker.AddCommand(cmd);
            }
        }
Beispiel #3
0
    public override void StartExecution(Action <Command> OnCommandFinished)
    {
        base.StartExecution(OnCommandFinished);

        invoker = new CommandInvoker(OnStageStarted, OnStageFinished, null);

        Command destroyPools = new ActionCommand(
            "DestroyPools",
            PopupSystem.instance.DestroyPools
            );
        Command createPools = new ActionCommand(
            "CreatePools",
            PopupSystem.instance.CreatePools
            );
        Command initPools = new ActionCommand(
            "InitPools",
            PopupSystem.instance.InitPools
            );

        invoker.AddCommand(destroyPools);
        invoker.AddCommand(createPools);
        invoker.AddCommand(initPools);

        invoker.Start();
        invoker.onExecutionFinished += FinishExecution;
    }
Beispiel #4
0
    private void PrepareCommands(GameObject go)
    {
        var tiles = mapGenerator.GetTile(13);

        CommandInvoker invoker = go.GetComponent <CommandInvoker>();

        invoker.AddCommand(new MoveToCommand(new Controller[] { go.GetComponent <MovementController>() }, tiles, new Vector3(1.28f / 2, 1.28f, 0)));
        invoker.AddCommand(new DelayCommand(new Controller[] { go.GetComponent <MovementController>() }, Random.Range(3, 10)));
        invoker.AddCommand(new MoveToCommand(new Controller[] { go.GetComponent <MovementController>() }, tiles, new Vector3(1.28f / 2, 1.28f, 0)));
        invoker.AddCommand(new DelayCommand(new Controller[] { go.GetComponent <MovementController>() }, Random.Range(3, 10)));
        invoker.isLooping = true;
    }
Beispiel #5
0
    private void PaintAt(Vector3 position)
    {
        Color c = new Color(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), Random.Range(0.5f, 1f));

        if (_activeTool == PaintTool.Cube)
        {
            _invoker.AddCommand(new PlaceObjectCommand(position, c, _cubePrefab));
        }
        else if (_activeTool == PaintTool.Sphere)
        {
            _invoker.AddCommand(new PlaceObjectCommand(position, c, _spherePrefab));
        }
    }
        public void RunCommandTest()
        {
            var openCommand    = new OpenCommand();
            var closeCommand   = new CloseCommand();
            var changeCommand  = new ChangeCommand();
            var commandInvoker = new CommandInvoker();

            commandInvoker.AddCommand(openCommand);
            commandInvoker.AddCommand(closeCommand);

            commandInvoker.RunCommand();

            Assert.True(commandInvoker.Records[0] == "Open" &&
                        commandInvoker.Records[1] == "Close");
        }
Beispiel #7
0
        public void CommandInvoker_Should_Throw_Exception_When_Rover_Is_Not_In_Area()
        {
            //Arrange
            string commands = "MMMMMM";
            var    plateau  = new Plateau(5, 5);
            var    rover    = new Rover
            {
                Direction = MarsRover.Enums.Directions.N,
                Position  = new Position
                {
                    X = 1,
                    Y = 2
                },
                Plateau = plateau
            };

            plateau.Rovers.Add(rover);

            plateau.ParseCommands(rover, commands.ToCharArray());

            //Act
            CommandInvoker commandInvoker = new CommandInvoker();

            commandInvoker.AddCommand(rover.Commands.ToArray());

            //Assert
            Assert.Throws <OutOfAreaException>(() => commandInvoker.RunCommands());
        }
Beispiel #8
0
    //20f(每帧发送按键输入)
    public override void FixedUpdate()
    {
        //base.FixedUpdate();

        if (!GameManager.Instance.IsStart)
        {
            return;
        }

        Tick++;

        //模拟发送
        InputBuffer buffer = new InputBuffer();

        buffer.UID  = 1;
        buffer.Tick = this.Tick;
        buffer.W    = W();
        buffer.S    = S();
        buffer.A    = A();
        buffer.D    = D();

        //模拟解析
        ICommand command = new MoveCommand(this, buffer);

        CommandInvoker.AddCommand(command);
    }
Beispiel #9
0
        public void CommandInvoker_Should_Move_Rover_To_Correct_Position()
        {
            //Arrange
            string commands = "LMLMLMLMM";
            var    plateau  = new Plateau(5, 5);
            var    rover    = new Rover
            {
                Direction = MarsRover.Enums.Directions.N,
                Position  = new Position
                {
                    X = 1,
                    Y = 2
                },
                Plateau = plateau
            };

            plateau.Rovers.Add(rover);

            plateau.ParseCommands(rover, commands.ToCharArray());

            //Act
            CommandInvoker commandInvoker = new CommandInvoker();

            commandInvoker.AddCommand(rover.Commands.ToArray());
            commandInvoker.RunCommands();

            //Assert
            Assert.Equal(1, rover.Position.X);
            Assert.Equal(3, rover.Position.Y);
            Assert.Equal(MarsRover.Enums.Directions.N, rover.Direction);
        }
Beispiel #10
0
        /// <summary>
        /// 开门
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenDoor_Click(object sender, EventArgs e)
        {
            // 检查回转库编号的合理性
            if (string.IsNullOrEmpty(lblGroupNo.Text) || (Convert.ToInt32(lblGroupNo.Text) == 0))
            {
                MessageUtil.ShowWarning("回转库编号没有正确配置,请检查设置!");
                return;
            }

            // 执行开门指令
            try
            {
                // 开门命令
                OpenDoorCommand cmd = new OpenDoorCommand(Controller, Convert.ToInt32(lblGroupNo.Text));
                commandInvoker.AddCommand(cmd);

                // 执行命令
                commandInvoker.ExecuteCommand();
            }
            catch (Exception ex)
            {
                MessageUtil.ShowWarning(ex.Message);
                return;
            }
        }
Beispiel #11
0
        public void setUp()
        {
            SetUpBase();

            // Add all commands which are necessary to execute this unit test
            // Important: Other commands are not available unless added here.
            commandInvoker.AddCommand(new CmdTestSetup("testsetup", drive));
        }
Beispiel #12
0
        /// <summary>
        /// 全部开门
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpenDoor_Click(object sender, EventArgs e)
        {
            // 获得选中的行
            int[] selectedIdx = gvDeviceInfo.GetSelectedRows();

            foreach (int item in selectedIdx)
            {
                // 将选中行的信息转换为设备模型对象
                DeviceModel model = (DeviceModel)gvDeviceInfo.GetRow(item);

                // 生成开门命令
                OpenDoorCommand cmd = new OpenDoorCommand(Controller, model.DeviceNo);
                commandInvoker.AddCommand(cmd);
            }

            // 执行命令队列里的所有命令
            commandInvoker.ExecuteCommand();
        }
Beispiel #13
0
        public void setUp()
        {
            IDrive drive = new Drive("C");

            commandInvoker = new CommandInvoker();
            testcmd        = new TestCommand("dIR", drive);
            commandInvoker.AddCommand(testcmd);

            output = new TestOutput();
        }
Beispiel #14
0
    public void RotatePlayerInNewDirection(UnitBase.FacingDirection newDirection)
    {
        UnitBase currentPlayer = LM.selectedCharacter;

        ICommand command = new MoveCommand(newDirection, currentPlayer.currentFacingDirection,
                                           currentPlayer.myCurrentTile, LM.tileToMoveAfterRotate,
                                           LM.TM.currentPath, currentPlayer,
                                           currentPlayer.buffbonusStateDamage, currentPlayer.turnsWithBuffOrDebuff, currentPlayer.movementUds, currentPlayer.turnsWithMovementBuffOrDebuff);

        CommandInvoker.AddCommand(command);
    }
Beispiel #15
0
 void PlaceObject(Vector3 position)
 {
     if (useCommandWorkflow)
     {
         ICommand newCommand = new PlaceObjectCommand(position); //METODO EXPERIMENTAL, NO SE USA POR DEFECTO
         CommandInvoker.AddCommand(newCommand);
     }
     else
     {
         ObjectPlacer.PlaceObject(position, objectSelected); //METODO COMUN PARA COLOCAR OBJETOS USADO POR DEFECTO
     }
 }
Beispiel #16
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(1))
     {
         Ray ray = cam.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out HitInfo, Mathf.Infinity))
         {
             ICommand command = new PlaceObjectCommand(HitInfo.point, Cube);
             CommandInvoker.AddCommand(command);
         }
     }
 }
Beispiel #17
0
        /// <summary>
        /// 开架
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOpen_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbxGroupNo.Text) || string.IsNullOrEmpty(cbxColumnNo.Text))
            {
                MessageBox.Show("请指定区号和列号!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            // 列号
            int columnNo = Convert.ToInt32(cbxColumnNo.Text.Substring(0, cbxColumnNo.Text.ToString().Length - 1));
            // 列方向
            string columnDir = cbxColumnNo.Text.Substring(cbxColumnNo.Text.ToString().Length - 1, 1);

            // 开架命令(所有的站号都是1)
            OpenCommand cmd = new OpenCommand(Controller, Convert.ToInt32(cbxGroupNo.Text), columnNo, columnDir);

            commandInvoker.AddCommand(cmd);

            // 执行命令
            //commandInvoker.ExecuteCommand();
            commandInvoker.AsyncExecuteCommand();
        }
Beispiel #18
0
 private void Update()
 {
     if (Input.GetMouseButtonDown(0))
     {
         Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
         {
             Color    c       = new Color(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), Random.Range(0.5f, 1f));
             ICommand command = new PlaceCubeCommand(hitInfo.point, c, cubePrefab);
             CommandInvoker.AddCommand(command);
         }
     }
 }
    public override void StartExecution(Action <Command> OnCommandFinished)
    {
        base.StartExecution(OnCommandFinished);
        invoker = new CommandInvoker(OnStageStarted, OnStageFinished, null);

        bool loadFromSave = PhotonNetwork.CurrentRoom.CustomProperties.ContainsKey("loadSavedGame") && (bool)PhotonNetwork.CurrentRoom.CustomProperties["loadSavedGame"];

        if (GameplayController.instance.session.roomOwner.IsLocal && loadFromSave)
        {
            Action switchLoadSaveState = delegate
            {
                Hashtable table = new Hashtable();
                table.Add("loadSavedGame", false);
                PhotonNetwork.CurrentRoom.SetCustomProperties(table);
            };

            invoker = new CommandInvoker(OnStageStarted, OnStageFinished, switchLoadSaveState);
            GameSave save = new GameSave();

            string fileName = (string)PhotonNetwork.CurrentRoom.CustomProperties["saveFileName"];
            FileManager.LoadGame(ref save, fileName);

            Command loadSaveSession = new ActionCommand(
                "LoadSaveSession",
                delegate { GameplayController.instance.session.LoadFromSave(ref save); }
                );
            Command loadSaveBoard = new ActionCommand(
                "LoadSaveBoard",
                delegate { GameplayController.instance.board.LoadFromSave(ref save); }
                );

            invoker.AddCommand(loadSaveSession);
            invoker.AddCommand(loadSaveBoard);
        }

        invoker.Start();
    }
Beispiel #20
0
    // Update is called once per frame
    void Update()
    {
        float x = Input.GetAxisRaw("Horizontal");
        float y = Input.GetAxisRaw("Vertical");

        rb2d.velocity = new Vector3(x * p_Speed, y * p_Speed);

        //if (Input.GetKeyDown(KeyCode.Mouse0) || Input.GetKeyDown(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.Space)) {
        if (Input.anyKeyDown)
        {
            DetectInput();
            ICommand command = new KeyCodeCommand(kCode, this.gameObject);
            CommandInvoker.AddCommand(command);
        }
    }
    void Card(GameObject card)
    {
        if (card.GetComponent <CardFace>().selectable)
        {
            if (selected == null || selected != card)
            {
                selected       = card;
                originPosition = selected.transform.position;
                CardColorYellow(selected);

                //ignore by raycast if they are being moveds
                selected.layer = 2;
            }
            else if (selected == card)
            {
                int foundationIndx = solitaire.IntoAllFoundations(selected);
                if (selected.transform.childCount == 0 && foundationIndx == -1)
                {
                    //when the same card clicked twice
                    //put the card into fountains if possible
                    //otherwise put the card into available free cell
                    //don't move the card if it already in the free cell
                    int freeCellIndx = solitaire.FreeCell("");

                    if (freeCellIndx != -1)
                    {
                        ICommand command = new FreeCellCommand(freeCellIndx, selected, originPosition);
                        CommandInvoker.AddCommand(command);
                    }
                }
                else if (foundationIndx != -1)
                {
                    ICommand command = new FoundationCommand(selected, originPosition, foundationIndx);
                    CommandInvoker.AddCommand(command);
                }

                selected.layer = 0;
                selected       = null;
            }
        }

        else if (selected != null)
        {
            CardColorWhite(selected);
            selected = null;
            //warn the player that this card is not selectable
        }
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;

            if (Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), out hit, 1000))
            {
                if (hit.collider.CompareTag("Player"))
                {
                    selectedTarget = hit.transform;
                    oldPos         = selectedTarget.position;
                    selectedTarget.GetComponent <Player>().PlayerSelected();
                    return;
                }

                if (selectedTarget == null)
                {
                    return;
                }
                newPos = new Vector3(hit.point.x, selectedTarget.position.y, hit.point.z);
                positions.Add(newPos);
                ICommand command = new MovePlayerCommand(selectedTarget, oldPos, newPos);
                CommandInvoker.AddCommand(command);
                oldPos = newPos;
            }
        }


        if (Input.GetKeyDown(KeyCode.Z))
        {
            CommandInvoker.UndoCommand();
        }

        if (Input.GetKeyDown(KeyCode.Y))
        {
            CommandInvoker.RedoCommand();
        }



        //if (selectedTarget != null &&selectedTarget.position == newPos) {
        //    positions.RemoveRange(0, positions.Count);
        //}
    }
Beispiel #23
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hitInfo;
            if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity))
            {
                Color c = new Color(Random.Range(0.5f, 1), Random.Range(0.5f, 1), Random.Range(0.5f, 1));

                // 传统写法
                //CubePlacer.PlaceCube(hitInfo.point, c, cubePrefab);

                // 命令模式
                ICommand command = new PlaceCubeCommand(hitInfo.point, c, cubePrefab);
                CommandInvoker.AddCommand(command);
            }
        }
    }
Beispiel #24
0
        static void Main(string[] args)
        {
            try
            {
                var plateau = new Plateau();

                CommandInvoker commandInvoker = new CommandInvoker();
                foreach (var rover in plateau.Rovers)
                {
                    commandInvoker.AddCommand(rover.Commands.ToArray());
                    commandInvoker.RunCommands();

                    Console.WriteLine(rover);
                }
            }
            catch (Exception)
            {
                Console.WriteLine("Error has occured.");
            }
        }
Beispiel #25
0
    private void PrepareCommands(GameObject go)
    {
        var exitDoor = mapGenerator.GetTile(15);
        var stools   = mapGenerator.GetTile(10);
        var bars     = mapGenerator.GetTile(8).Concat(mapGenerator.GetTile(9)).ToList();

        CommandInvoker invoker = go.GetComponent <CommandInvoker>();

        invoker.AddCommand(new MoveToCommand(new Controller[] { go.GetComponent <MovementController>() }, stools, new Vector3(1.28f / 2, 1.28f, 0)));
        invoker.AddCommand(new DelayCommand(new Controller[] { go.GetComponent <MovementController>() }, UnityEngine.Random.Range(10, 30)));
        invoker.AddCommand(new MoveToCommand(new Controller[] { go.GetComponent <MovementController>() }, bars, new Vector3(-1.28f / 2, 2.28f, 0)));
        invoker.AddCommand(new OrderCommand(new Controller[] { go.GetComponent <CustomerOrderController>() }, MaxOrderTakeTime, MaxOrderMakeTime));
        invoker.AddCommand(new MoveToCommand(new Controller[] { go.GetComponent <MovementController>() }, exitDoor, new Vector3(1.28f / 2, 1.28f + 1, 0)));
        invoker.AddCommand(new DestroyCommand(new Controller[] { go.GetComponent <CustomerDestroyerController>() }, customers, 1));
        invoker.isLooping = false;
    }
Beispiel #26
0
        private void HandleObjectPlacement()
        {
            RaycastHit   hitInfo;
            Ray          rayHover = _camera.ScreenPointToRay(Input.mousePosition);
            GridPosition selectedObjectGridPosition;

            if (Physics.Raycast(rayHover, out hitInfo))
            {
                selectedObjectGridPosition = _grid.GetNearestPointOnGrid(hitInfo.point);
                _isPositionValid           = _grid.CheckIfGridPositionIsValid(selectedObjectGridPosition);

                _selectedObject.transform.position = selectedObjectGridPosition.Position;
                _selectedObject.SetVisability(_isPositionValid);

                if (Input.GetMouseButtonDown(0))
                {
                    if (_isPositionValid)
                    {
                        ICommand command = new PlaceLevelObjectCommand(_objectToPlace, selectedObjectGridPosition, _grid);
                        CommandInvoker.AddCommand(command);
                    }
                }

                if (Input.GetMouseButtonDown(1))
                {
                    LevelObject objectToDelete = hitInfo.collider.transform.GetComponent <LevelObject>();
                    if (objectToDelete != null)
                    {
                        ICommand command = new DeleteLevelObjectCommand(
                            objectToDelete,
                            _grid.GetNearestPointOnGrid(objectToDelete.transform.position),
                            _grid);

                        CommandInvoker.AddCommand(command);
                    }
                }
            }
        }
Beispiel #27
0
    /// <summary>
    /// Dodaje komendy do startowego CommandInvokera
    /// </summary>
    private void AddCommands()
    {
        SyncCommand sync0           = new SyncCommand(0);
        SyncCommand sync1           = new SyncCommand(1);
        Command     temporaryRoom   = new TemporaryRoomCommand();
        Command     subscribeEvents = new SubscribeEventsCommand(new List <IEventSubscribable>
        {
            instance,
            this.banking,
            this.session,
            menu,
            this.board,
            this.arController,
            this.flow,
            sync0,
            sync1
        });
        Command session            = new SessionCommand(this.session);
        Command board              = new BoardCommand(this.board);
        Command gameMenu           = new GameMenuCommand(menu);
        Command banking            = new BankingControllerCommand(this.banking);
        Command arController       = new ARControllerCommand(this.arController);
        Command gameplayController = new GameplayControllerCommand(instance);
        Command loadFromSave       = new LoadFromSaveCommand();
        Command popupSystem        = new PopupSystemCommand();

        invoker = new CommandInvoker(null, null, delegate { OnExecutionFinished(); sync0.UnsubscribeEvents(); sync1.UnsubscribeEvents(); });

        invoker.AddCommand(temporaryRoom);
        invoker.AddCommand(subscribeEvents);
        invoker.AddCommand(session);
        invoker.AddCommand(board);
        invoker.AddCommand(gameMenu);
        invoker.AddCommand(banking);
        invoker.AddCommand(gameplayController);
        invoker.AddCommand(loadFromSave);
        invoker.AddCommand(sync0);
        invoker.AddCommand(arController);
        invoker.AddCommand(popupSystem);
        invoker.AddCommand(sync1);
    }
    void MouseInput()
    {
        if (Input.GetMouseButtonDown(0))
        {
            if (selected != null)
            {
                ResetCard(selected);
            }
            //get origin mouse position for drag calculation
            mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
            RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);
            if (hit)
            {
                if (hit.collider.CompareTag("Card"))
                {
                    Card(hit.collider.gameObject);
                }
                if (hit.collider.CompareTag("Foundation"))
                {
                    selected = null;
                }
            }
            else
            {
                selected = null;
            }
        }

        //when dragging, card moves with mouse
        if (Input.GetMouseButton(0))
        {
            float deltaX = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f)).x - mousePosition.x;
            float deltaY = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f)).y - mousePosition.y;

            if (selected != null)
            {
                selected.transform.position = new Vector3(originPosition.x + deltaX, originPosition.y + deltaY, -0.35f);
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            if (selected != null && selected.transform.position != originPosition)
            {
                Debug.Log("mouse up");
                mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0f));
                RaycastHit2D hit = Physics2D.Raycast(mousePosition, Vector2.zero);
                if (hit)
                {
                    //when card drag to another card
                    if (hit.collider.CompareTag("Card"))
                    {
                        Debug.Log(hit.collider.name);
                        if (Stackable(selected, hit.collider.gameObject))
                        {
                            ICommand command = new StackCommand(selected, hit.collider.gameObject, originPosition);
                            CommandInvoker.AddCommand(command);
                            CardColorWhite(selected);
                            selected.layer = 0;
                            selected       = null;
                        }
                    }
                    //when card drag to foundation area
                    if (hit.collider.CompareTag("Foundation"))
                    {
                        int foundationIndx = solitaire.IntoAllFoundations(selected);
                        if (foundationIndx == -1)
                        {
                            ResetCard(selected);
                        }
                        else
                        {
                            ICommand command = new FoundationCommand(selected, originPosition, foundationIndx);
                            CommandInvoker.AddCommand(command);
                        }
                        CardColorWhite(selected);
                        selected = null;
                    }
                    //when card drag to an empty cascade
                    if (hit.collider.CompareTag("Empty Cascade"))
                    {
                        //check if the cascade is really empty
                        if (hit.collider.transform.childCount == 0)
                        {
                            ICommand command = new EmptyCascadeCommand(selected, hit.collider.gameObject, originPosition);
                            CommandInvoker.AddCommand(command);
                            CardColorWhite(selected);
                            selected.layer = 0;
                            selected       = null;
                        }
                    }
                    //when card drag to free cell
                    if (hit.collider.CompareTag("Free Cell"))
                    {
                        if (selected.transform.childCount == 0)
                        {
                            int freeCellIndx = hit.collider.transform.GetSiblingIndex();
                            if (solitaire.freeCells[freeCellIndx] == "")
                            {
                                ////remove from the free cell if the card is in it
                                ICommand command = new FreeCellCommand(freeCellIndx, selected, originPosition);
                                CommandInvoker.AddCommand(command);

                                CardColorWhite(selected);
                                selected.layer = 0;
                                selected       = null;
                            }
                        }
                    }
                }
                else
                {
                    ResetCard(selected);
                    //selected = null;
                }

                if (selected != null)
                {
                    ResetCard(selected, false);
                }
            }
        }
    }
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Alpha1))
        {
            thisObj    = factory.metalSpawn();
            cubePrefab = thisObj.transform;
            //prefab = myPrefabs[0];

            cubeMetal.color = Color.gray;
            cubeSand.color  = Color.white;
            cubeBrick.color = Color.white;

            itemID = 0;
        }

        if (Input.GetKeyUp(KeyCode.Alpha2))
        {
            thisObj    = factory.sandSpawn();
            cubePrefab = thisObj.transform;
            //Factory.sandSpawn();
            //prefab = myPrefabs[1];

            cubeSand.color  = Color.gray;
            cubeMetal.color = Color.white;
            cubeBrick.color = Color.white;

            itemID = 1;
        }

        if (Input.GetKeyUp(KeyCode.Alpha3))
        {
            thisObj    = factory.brickSpawn();
            cubePrefab = thisObj.transform;
            //Factory.brickSpawn();

            //prefab = myPrefabs[2];

            cubeBrick.color = Color.gray;
            cubeMetal.color = Color.white;
            cubeSand.color  = Color.white;

            itemID = 2;
        }

        if (Input.GetMouseButtonDown(0))
        {
            Ray ray = mainCam.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, Mathf.Infinity))
            {
                //Factory.SpawnObj(hit.point, thisObj, cubePrefab);
                ICommand command = new PlaceCubCommand(hit.point, thisObj, cubePrefab);
                CommandInvoker.AddCommand(command);

                SavePosition(thisObj.transform.position.x, thisObj.transform.position.y, thisObj.transform.position.z, itemID);
            }
        }

        if (Input.GetKeyUp(KeyCode.L))
        {
            theCubes = LoadPosition();

            for (int i = 0; i < theCubes.Length; i++)
            {
                Debug.Log(theCubes[i]);
            }
        }
    }