Ejemplo n.º 1
0
    // 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();
    }
Ejemplo n.º 2
0
    public static Color GetColor(double target)
    {
        //if (target == 0)
        //    return Color.red;
        //else if (target == 1)
        //    return Color.blue;
        //else if (target == 2)
        //    return Color.green;
        //else
        //    return Color.red;

        return(SetColor.GetColor(target));
    }
Ejemplo n.º 3
0
        /// <summary>
        /// Grids the view.
        /// </summary>
        /// <param name="list">The list.</param>
        public void GridView(IList <NotesData> list, IList <CreateNewLabel> listLabel)
        {
            try
            {
                ///// Creates column defination of width 170
                GridLayout.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(170)
                });
                GridLayout.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(170)
                });
                GridLayout.Margin = 5;
                int rowCount = 0;

                //// Creates number of columns as lables are added
                for (int row = 0; row < list.Count; row++)
                {
                    //// Adds new row after 2 labels
                    if (row % 2 == 0)
                    {
                        GridLayout.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(2, GridUnitType.Auto)
                        });
                        rowCount++;
                    }
                }

                var index = -1;

                //// Adds label to row and columns
                for (int rowIndex = 0; rowIndex < rowCount; rowIndex++)
                {
                    for (int columnIndex = 0; columnIndex < 2; columnIndex++)
                    {
                        NotesData data = null;

                        index++;
                        if (index < list.Count)
                        {
                            data = list[index];
                        }

                        //// Creates Labels
                        var label = new Xamarin.Forms.Label
                        {
                            Text              = data.Title,
                            TextColor         = Color.Black,
                            FontAttributes    = FontAttributes.Bold,
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.Start,
                        };

                        //// Created label key
                        var labelKey = new Xamarin.Forms.Label
                        {
                            Text      = data.Key,
                            IsVisible = false
                        };

                        var colorlabel = new Xamarin.Forms.Label
                        {
                            Text      = data.ColorNote,
                            IsVisible = false
                        };

                        //// Content view
                        var content = new Xamarin.Forms.Label
                        {
                            Text              = data.Notes,
                            VerticalOptions   = LayoutOptions.Center,
                            HorizontalOptions = LayoutOptions.Start,
                        };

                        //// Creates stack layout for each label
                        StackLayout layout = new StackLayout()
                        {
                            Spacing = 2,
                            Margin  = 2,
                            ////  BackgroundColor = Color.White
                        };

                        //// Tapgesture is created
                        var tapGestureRecognizer = new TapGestureRecognizer();
                        layout.Children.Add(labelKey);
                        layout.Children.Add(label);
                        layout.Children.Add(content);
                        layout.Children.Add(colorlabel);
                        layout.GestureRecognizers.Add(tapGestureRecognizer);
                        layout.Spacing = 2;
                        layout.Margin  = 2;
                        //// layout.BackgroundColor = Color.White;
                        var frame = new Frame();
                        frame.BorderColor = Color.Black;
                        frame.Content     = layout;

                        //// Setting the color class
                        SetColor setColor = new SetColor();
                        setColor.GetColor(data, frame);

                        //// Loops over the labels class
                        foreach (CreateNewLabel createNewLabel in listLabel)
                        {
                            IList <string> labellist = data.LabelData;

                            //// Loops over the list of labels added to the notes
                            foreach (var labelid in labellist)
                            {
                                //// Checks if the labels are equal from the label list
                                if (createNewLabel.LabelKey.Equals(labelid))
                                {
                                    var labelName = new Label
                                    {
                                        Text = createNewLabel.Label,
                                        HorizontalOptions = LayoutOptions.Center,
                                        VerticalOptions   = LayoutOptions.Start,
                                        FontSize          = 12,
                                    };
                                    var labelFrame = new Frame();
                                    labelFrame.CornerRadius    = 28;
                                    labelFrame.HeightRequest   = 14;
                                    labelFrame.BorderColor     = Color.Gray;
                                    labelFrame.Content         = labelName;
                                    labelFrame.BackgroundColor = Color.FromHex(SetColor.GetHexColor(data));
                                    layout.Children.Add(labelFrame);
                                }
                            }
                        }
                        if (data.Area != null)
                        {
                            var image = new Image
                            {
                                Source            = "location.png",
                                VerticalOptions   = LayoutOptions.Start,
                                HorizontalOptions = LayoutOptions.Start,
                                HeightRequest     = 13,
                                WidthRequest      = 13
                            };
                            var location = new Label
                            {
                                Text = data.Area,
                                HorizontalOptions = LayoutOptions.CenterAndExpand,
                                VerticalOptions   = LayoutOptions.StartAndExpand,
                                FontSize          = 12,
                            };
                            StackLayout framelayout = new StackLayout()
                            {
                                Spacing = 1,
                                Margin  = 1,
                            };
                            framelayout.Children.Add(image);
                            framelayout.Children.Add(location);
                            var locationFrame = new Frame();
                            locationFrame.CornerRadius  = 28;
                            locationFrame.HeightRequest = 10;
                            locationFrame.WidthRequest  = 30;
                            locationFrame.BorderColor   = Color.Gray;
                            locationFrame.Content       = framelayout;
                            // locationFrame.Content = image;

                            locationFrame.BackgroundColor = Color.FromHex(SetColor.GetHexColor(data));
                            //layout.Children.Add(image);
                            layout.Children.Add(locationFrame);
                        }

                        //// when tapped opens or navigates to particular page
                        tapGestureRecognizer.Tapped += (object sender, EventArgs args) =>
                        {
                            StackLayout         layout123 = (StackLayout)sender;
                            IList <View>        item      = layout123.Children;
                            Xamarin.Forms.Label KeyValue  = (Xamarin.Forms.Label)item[0];
                            var Keyvalue = KeyValue.Text;
                            Navigation.PushAsync(new UnArchive(Keyvalue));
                        };
                        GridLayout.Children.Add(frame, columnIndex, rowIndex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Ejemplo n.º 4
0
    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");
                }
            }
        }
    }
Ejemplo n.º 5
0
    // 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;
            }
        }
    }