コード例 #1
0
ファイル: GameScript.cs プロジェクト: vahnilah/100Puzzle
    // Start is called before the first frame update
    void Start()
    {
        //WindowManager.instance.ScreenSizeChangeEvent += Instance_ScreenSizeChangeEvent;

        DetectPossibleMoves.SetBooleans();
        GamePieces.FindGameBlocks();
        GamePieces.FindGamePieces();

        clickAndDropScript = gameObject.GetComponent <ClickAndDrop>();
        gameOverCanvas     = GameObject.FindGameObjectWithTag("GameOverCanvas");
        restartButton      = GameObject.FindGameObjectWithTag("RestartButton");
        changeColorButton  = GameObject.FindGameObjectWithTag("ChangeColor");
        highScoreIcon      = GameObject.FindGameObjectWithTag("HighScoreIcon");

        background = GameObject.FindGameObjectWithTag("BlurBG");

        gameOverCanvas.SetActive(false);
        restartButton.SetActive(false);
        changeColorButton.SetActive(true);
        background.SetActive(false);
        highScoreIcon.SetActive(true);


        // Change BG
        var camera = (Camera)FindObjectOfType(typeof(Camera));

        camera.backgroundColor = SetColor.GetColor("Background");

        // Change Grid
        AnimateGrid.SetGrid();

        UpdateColor();
    }
コード例 #2
0
        public void Test_That_Cancel_Stays_False_On_Creating_Grid()
        {
            //Arrange
            var lifeGridControl = new exDGV();

            //Act
            var animateGrid = new AnimateGrid(lifeGridControl);

            //Assert
            Assert.AreEqual(animateGrid.Cancelled, false);
        }
コード例 #3
0
ファイル: GameScript.cs プロジェクト: vahnilah/100Puzzle
    void UpdateAnimation()
    {
        // If there is a row clear, del played blocks
        if (GameGrid.canRowsBeCleared)
        {
            // Delete played row blocks
            GameGrid.DeletePlayedBlocksOnRow();
        }

        // If there is a col clear, del played blocks
        if (GameGrid.canColsBeCleared)
        {
            GameGrid.DeletePlayedBlocksOnCollumns();
        }

        if (GameGrid.canRowsBeCleared || GameGrid.canColsBeCleared)
        {
            // Reset the bool variables
            GameGrid.canRowsBeCleared = false;
            GameGrid.canColsBeCleared = false;

            // Remove cleared pieces from board
            if (GamePieces.isAPlayValid)
            {
                GameGrid.UpdatePlayedPiecesOnGrid(this);
            }

            // Run the clear row/col animation
            AnimateGrid.AnimateBgGrid(this);

            // Add the amount of rows cleared for scoring, must be reset in score class
            GameGrid.howManyRowsColsWereFilled += GameGrid.whatRowIsFilled.Count;
            GameGrid.howManyRowsColsWereFilled += GameGrid.whatColIsFilled.Count;

            // Clear the HashSet's of stored clears
            GameGrid.whatRowIsFilled.Clear();
            GameGrid.whatColIsFilled.Clear();
            AnimateGrid.bg_rows.Clear();
            AnimateGrid.bg_cols.Clear();
        }
    }
コード例 #4
0
        partial void OnLoad()
        {
            #region 物品管理

            this.filterMask = GetTransform("Image_BackGround/ItemBg/Mask");

            this.grid = GetComponent <AnimateGrid>("Image_BackGround/ItemBg/Image_ItemGrid");

            Assert.IsTrue(this.filterMask && this.grid);
            this.grid.CheckIfSort =
                childRect =>
            {
                var data = childRect.GetComponent <HiveFiveItemSlot>().ItemData;

                switch (_filterType)
                {
                case FilterType.Drag:
                    return(data is DragData);

                case FilterType.Gem:
                    return(data is GemData);

                default:
                    return(true);
                }
            };

            var allBtn = GetComponent <Image>("Image_BackGround/ItemBg/BtnBar/AllBtn");
            allBtn.gameObject.AddComponent <UIInputer>().eventOnPointerClick +=
                data => OnClickBtn(FilterType.All, allBtn.transform);

            var dragBtn = GetComponent <Image>("Image_BackGround/ItemBg/BtnBar/DragBtn");
            dragBtn.gameObject.AddComponent <UIInputer>().eventOnPointerClick +=
                data => OnClickBtn(FilterType.Drag, dragBtn.transform);

            var gemBtn = GetComponent <Image>("Image_BackGround/ItemBg/BtnBar/GemBtn");
            gemBtn.gameObject.AddComponent <UIInputer>().eventOnPointerClick +=
                data => OnClickBtn(FilterType.Gem, gemBtn.transform);


            #endregion

            #region 物品详情的展示

            this.itemInfo = GetTransform("Image_BackGround/ItemInfo");

            itemInfo.gameObject.AddComponent <UIInputer>().eventOnPointerClick += data => SwitchMode(WorkMode.Normal);


            this.showPos = this.itemInfo.GetComponent <RectTransform>("ShowPos");

            this.infoMask = this.itemInfo.GetComponent <RectTransform>("ItemInfo");


            this.itemNameText   = this.itemInfo.GetComponent <Text>("ItemInfo/InfoBg/ItemName");
            this.itemPriceText  = this.itemInfo.GetComponent <Text>("ItemInfo/InfoBg/Price");
            this.itemStatements = this.itemInfo.GetComponent <Text>("ItemInfo/InfoBg/Statements");
            this.itemStory      = this.itemInfo.GetComponent <Text>("ItemInfo/InfoBg/Story");
            this.itemAccesses   = this.itemInfo.GetComponent <Text>("ItemInfo/InfoBg/Accesses");


            #endregion

            #region 宝石槽初始化

            effectiveGemBar = GetTransform("Image_BackGround/Image_Player/EffectiveGemBar");
            Assert.IsTrue(effectiveGemBar);

            var gemCount = effectiveGemBar.childCount;
            if (gemItems == null)
            {
                gemItems = new HighFiveItem[gemCount];
            }

            #endregion

            //恢复背包信息
            foreach (var kv in GlobalVar.G_Player.GetItems())
            {
                var item = kv.Value;
                OnAddItem(item.ID, item.Count);
            }
        }
コード例 #5
0
ファイル: GamePieces.cs プロジェクト: vahnilah/100Puzzle
    // Main method that runs to find what objects are valid and plays it on the grid
    public static void WhereAreGamePiecesToPlay()
    {
        GamePieces.isAPlayValid = false;
        foreach (GameObject oneGamePiece in CollectionOfGamePieces)
        {
            bool isAGameBlockOutsideTheBoard       = false;
            bool isAGameBlockOverLappingAValidPlay = false;
            bool isObjectClicked = false;
            gameObjectDetection = oneGamePiece.GetComponent <DetectObjectClicked>();
            objectClickAndDrop  = oneGamePiece.GetComponent <ClickAndDrop>();
            if (gameObjectDetection.IsObjectClicked)
            {
                objectClickAndDrop.enabled = true;
            }


            // Save position of gamePiece if invalid placement
            if (Input.GetMouseButtonDown(0))
            {
                // Detect if gamePiece has the script
                if (oneGamePiece.GetComponent <DetectObjectClicked>() != null)
                {
                    isObjectClicked = gameObjectDetection.IsObjectClicked;

                    // Get the Block ID if an object has been clicked.
                    if (isObjectClicked && hasClickedObjectBeenReleased)
                    {
                        UUIDofObject = gameObjectDetection.UUID;

                        hasClickedObjectBeenReleased = false;
                    }
                }
            }

            // Get children
            Transform[] manyGameBlocks = oneGamePiece.GetComponentsInChildren <Transform>();

            // Get children position for valid placement
            foreach (var oneGameBlock in manyGameBlocks)
            {
                //  The main game block [Not the children of it]
                if (GetGameBlockTag(oneGameBlock))
                {
                    float x = oneGameBlock.position.x;
                    float y = oneGameBlock.position.y;

                    //Debug.Log("X: " + x + " Y: " + y);
                    //Debug.Log(InsideBorder(x, y));
                    isAGameBlockOutsideTheBoard = InsideBorder(x, y) ? isAGameBlockOutsideTheBoard : true;
                    //if (!InsideBorder(x, y))
                    //    isAGameBlockOutsideTheBoard = true;

                    Vector2 v = GameGrid.Vector2Round(oneGameBlock.position);

                    // Mark true: if a game piece is overlapping
                    if (GameGrid.IsAGamePieceInsideGridAt(v))
                    {
                        isAGameBlockOverLappingAValidPlay = true;
                    }
                }
            }

            // FOR VALID PLAY
            // If: children position is valid, destory gamepiece & leave gameblocks on board
            // When the mouse is released
            bool isAGameBlockInsideTheBoard = !isAGameBlockOutsideTheBoard;
            if (!isAGameBlockOverLappingAValidPlay && isAGameBlockInsideTheBoard && Input.GetMouseButtonUp(0))
            {
                foreach (var oneGameBlock in manyGameBlocks)
                {
                    // Align the gameblocks on the grid
                    var pos = GameGrid.Vector2Round(oneGameBlock.position);
                    oneGameBlock.position = pos;

                    if (GetGameBlockTag(oneGameBlock))
                    {
                        oneGameBlock.parent = null;
                        Destroy(oneGamePiece);

                        // Place valid piece on game grid
                        Vector2 v = GameGrid.Vector2Round(oneGameBlock.position);
                        GameGrid.grid[(int)v.x, (int)v.y] = oneGameBlock;

                        // Change the background grid color
                        AnimateGrid.ChangeBgGridColor((int)v.x, (int)v.y);

                        hasClickedObjectBeenReleased = true;
                        isAPlayValid = true;
                    }
                }
            }

            // FOR INVALID PLAY
            // Else: restore gamepiece to it's orginal location for an invalid play
            else if (isAGameBlockOverLappingAValidPlay && Input.GetMouseButtonUp(0) ||
                     isAGameBlockOutsideTheBoard && Input.GetMouseButtonUp(0))
            {
                if (UUIDofObject == gameObjectDetection.UUID)
                {
                    oneGamePiece.transform.position = gameObjectDetection.PositionOfObject;
                    var localScale = oneGamePiece.transform.localScale;
                    localScale.x = OriginalScale;
                    localScale.y = OriginalScale;
                    oneGamePiece.transform.localScale = localScale;
                    hasClickedObjectBeenReleased      = true;
                    //objectClickAndDrop.enabled = false;
                }
            }
        }
    }
コード例 #6
0
ファイル: GameScript.cs プロジェクト: vahnilah/100Puzzle
    void UpdateColor()
    {
        // Change BG
        var camera = (Camera)FindObjectOfType(typeof(Camera));

        camera.backgroundColor = SetColor.GetColor("Background");

        // Change Grid
        AnimateGrid.SetGrid();

        // Change Icon Color on highscore
        SpriteRenderer HighScoreIconRender = highScoreIcon.GetComponent <SpriteRenderer>();

        if (SetColor.GetDarkMode() == true)
        {
            HighScoreIconRender.color = SetColor.GetColor("Font");
        }
        else
        {
            HighScoreIconRender.color = SetColor.GetColor("Font");
        }

        // Change ChangeIconImage Image
        Image changeColorButtonImage = changeColorButton.GetComponent <Image>();

        //Debug.Log(changeColorButtonImage);

        if (SetColor.GetDarkMode() == true)
        {
            changeColorButtonImage.sprite = Resources.Load <Sprite>("Images/GridIconAlt");
        }
        else
        {
            changeColorButtonImage.sprite = Resources.Load <Sprite>("Images/GridIconDark");
        }

        // Change Labels
        GameObject[] labels = GameObject.FindGameObjectsWithTag("TextLabel");
        foreach (var a in labels)
        {
            MeshRenderer bgBlock  = a.GetComponent <MeshRenderer>();
            Material[]   meshMats = bgBlock.materials;

            if (SetColor.GetDarkMode() == true)
            {
                meshMats[0] = null;
                meshMats[0] = SetColor.GetMaterial("Grid");
            }
            else
            {
                meshMats[0] = null;
                meshMats[0] = SetColor.GetMaterial("Grid");
            }

            bgBlock.materials = meshMats;
        }

        // Changel Text on Labels
        GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText");
        // Set UI Text to objects to access
        //Debug.Log(objs.Length);
        foreach (var i in textLabels)
        {
            var t = i.GetComponent <Text>();
            if (t.name.Equals("HighScore"))
            {
                if (SetColor.GetDarkMode() == true)
                {
                    t.color = SetColor.GetColor("Font");
                }
                else
                {
                    t.color = SetColor.GetColor("Font");
                }
            }
            if (t.name.Equals("CurrentScore"))
            {
                if (SetColor.GetDarkMode() == true)
                {
                    t.color = SetColor.GetColor("Font");
                }
                else
                {
                    t.color = SetColor.GetColor("Font");
                }
            }
        }
    }
コード例 #7
0
ファイル: GameScript.cs プロジェクト: vahnilah/100Puzzle
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonUp(0) || Input.GetMouseButton(0))
        {
            _canUpdateColor  = true;
            _canUpdateGrid   = true;
            _gatherColorTime = 0f;
        }

        // Set the color of the grid
        if (AnimateGrid.setGrid == false && _updateOnce == true)
        {
            //_gatherGridTime += Time.deltaTime;
            //if (_gatherGridTime > _waitTime)
            //_canUpdateGrid = false;

            AnimateGrid.SetGrid();
            AnimateGrid.setGrid = true;

            // Changel Text on Labels
            GameObject[] textLabels = GameObject.FindGameObjectsWithTag("ScoreText");
            // Set UI Text to objects to access
            //Debug.Log(objs.Length);
            foreach (var i in textLabels)
            {
                var t = i.GetComponent <Text>();
                if (t.name.Equals("HighScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
                if (t.name.Equals("CurrentScore"))
                {
                    if (SetColor.GetDarkMode() == true)
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                    else
                    {
                        t.color = SetColor.GetColor("Font");
                    }
                }
            }

            _updateOnce = false;
        }

        // Change colors to Light / Dark mode
        if (SetColor.WillChangeColor == true && _canUpdateColor == true)
        {
            _gatherColorTime += Time.deltaTime;
            if (_gatherColorTime > _waitTime)
            {
                _canUpdateColor = false;
            }

            UpdateColor();


            SetColor.WillChangeColor = false;
        }

        // Restart game
        if (GameOverInfo.RestartGame == true)
        {
            gameOverCanvas.SetActive(false);
            restartButton.SetActive(false);
            background.SetActive(false);
            GameOverInfo.RestartGame = false;
            AnimateGrid.setGrid      = false;
            SetColor.WillChangeColor = true;
            _updateOnce = true;

            SceneManager.LoadScene(SceneManager.GetActiveScene().name);
        }

        // Check if Game Over
        if (DetectPossibleMoves.IsGameOver == true)
        {
            if (triggerOnce == true)
            {
                GameOver();

                //Debug.Log("Game Over");
                triggerOnce = false;
            }
        }
        else
        {
            if (!checkedAvaliablePieces || DetectPossibleMoves.DidNewBlocksSpawn)
            {
                DetectPossibleMoves.SetBooleans();

                DetectPossibleMoves.AnalyzeGrid();

                DetectPossibleMoves.IsThereAValidMove();

                checkedAvaliablePieces = true;
                GamePieces.HasAnGamePieceBeenPlayedToUpdateScore = true;
            }

            // Logic for the grid
            GamePieces.FindGameBlocks();
            GamePieces.FindGamePieces();
            GamePieces.WhereAreGamePiecesToPlay();
            AnimateGrid.FindBackgroundBlocks();

            /* If the left (main) mouse click is released
             * remove cleared blocks */
            if (Input.GetMouseButtonUp(0) || isMouseReleased)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                UpdateGameLogic();

                getRefresh      = true;
                isMouseReleased = false;

                UpdateAnimation();
            }

            if (GamePieces.isAPlayValid)
            {
                if (GamePieces.isAPlayValid)
                {
                    GameGrid.UpdatePlayedPiecesOnGrid(this);
                }

                checkedAvaliablePieces = false;
            }
        }
    }