Esempio n. 1
0
    public void RetractStep()
    {
        if (ArchivedSteps.Count > 0)
        {
            ArchivedStep archivedStep = ArchivedSteps.Pop();
            foreach (ArchivedStep.Step step in archivedStep.AllGridChanges)
            {
                FragmentMatrix[step.GP.x, step.GP.z].Front = step.BeforeIsFront;
            }

            MoveCount--;
            Reward++;
        }
    }
Esempio n. 2
0
    public void Update()
    {
        if (GameStateManager.Instance.GetState() == GameState.Playing)
        {
            //SkillGridIndicatorGroup.RectTransform.anchoredPosition = Input.mousePosition - new Vector3(Screen.width / 2f, Screen.height / 2f, 0);

            if (Input.GetKeyDown(KeyCode.R))
            {
                if (currentSkill != null)
                {
                    currentSkill.RotateOccupiedPositions();
                    SkillGridIndicatorGroup.Init(currentSkill.OccupiedPositions, SkillIndicatorGridSize, false, CurrentScale * SkillIndicatorScaleFactor);
                }
            }

            if ((!EventSystem.current.IsPointerOverGameObject() && Input.GetMouseButtonUp(0)) || Input.GetMouseButtonUp(1))
            {
                if (Reward + CurrentCoin > 0)
                {
                    Ray          cursorRay    = Camera.main.ScreenPointToRay(Input.mousePosition);
                    ArchivedStep archivedStep = new ArchivedStep();
                    if (currentSkill != null)
                    {
                        foreach (SkillConfig.SkillGrid sg in currentSkill.OccupiedPositions)
                        {
                            Ray ray = new Ray(cursorRay.origin + new Vector3(sg.GridPos.x, sg.GridPos.z, 0) * CurrentScale, cursorRay.direction);
                            if (Physics.Raycast(ray, out RaycastHit hit, 1000, LayerManager.Instance.LayerMask_Fragment))
                            {
                                FragmentCollider fc = hit.collider.gameObject.GetComponent <FragmentCollider>();
                                switch (sg.SkillGridType)
                                {
                                case SkillGridType.Flip:
                                {
                                    ArchivedStep.Step step = new ArchivedStep.Step(fc.SquireFragment.GridPos, fc.SquireFragment.Front);
                                    archivedStep.AllGridChanges.Add(step);
                                    fc.SquireFragment.FlipFragment();
                                    break;
                                }

                                case SkillGridType.TintWhite:
                                {
                                    if (!fc.SquireFragment.Front)
                                    {
                                        ArchivedStep.Step step = new ArchivedStep.Step(fc.SquireFragment.GridPos, fc.SquireFragment.Front);
                                        archivedStep.AllGridChanges.Add(step);
                                        fc.SquireFragment.Front = true;
                                    }

                                    break;
                                }

                                case SkillGridType.TintBlack:
                                {
                                    if (fc.SquireFragment.Front)
                                    {
                                        ArchivedStep.Step step = new ArchivedStep.Step(fc.SquireFragment.GridPos, fc.SquireFragment.Front);
                                        archivedStep.AllGridChanges.Add(step);
                                        fc.SquireFragment.Front = false;
                                    }

                                    break;
                                }
                                }
                            }
                        }
                    }
                    else // no skill, can only flip one grid
                    {
                        if (Physics.Raycast(cursorRay, out RaycastHit hit, 1000, LayerManager.Instance.LayerMask_Fragment))
                        {
                            FragmentCollider  fc   = hit.collider.gameObject.GetComponent <FragmentCollider>();
                            ArchivedStep.Step step = new ArchivedStep.Step(fc.SquireFragment.GridPos, fc.SquireFragment.Front);
                            archivedStep.AllGridChanges.Add(step);
                            fc.SquireFragment.FlipFragment();
                        }
                    }

                    if (archivedStep.AllGridChanges.Count > 0)
                    {
                        CurrentSelectedSkillKey = String.Empty;
                        ArchivedSteps.Push(archivedStep);
                        MoveCount++;
                        Reward--;
                    }

                    if (CurrentFrontCount >= SuccessFrontCount)
                    {
                        LevelPass();
                    }
                }
                else
                {
                    Failed();
                }
            }

            if (Input.GetKeyUp(KeyCode.F9))
            {
                LoadNextLevel();
            }

            if (Input.GetKeyUp(KeyCode.Escape))
            {
                CurrentSelectedSkillKey = String.Empty;
            }
        }
    }