示例#1
0
    //-------------------------------------------------------------------------
    public void PieceToggled(GamePiece piece)
    {
        var alreadyInWord = piece.UsedInWord;

        if (!alreadyInWord)
        {
            if (ActiveWord.Length > 0 && ActiveWordDepth != piece.Depth)
            {
                return;
            }
            ActiveWordDepth  = piece.Depth;
            ActiveWord      += piece.Letter;
            piece.UsedInWord = true;
            ActiveWordPieces.Add(piece);
        }
        else
        {
            var idx = ActiveWordPieces.IndexOf(piece);
            if (idx >= 0)
            {
                ActiveWord = ActiveWord.Remove(idx, 1);
            }
            ActiveWordPieces.Remove(piece);
            piece.UsedInWord = false;
        }
    }
示例#2
0
    public void Update()
    {
        // hacks to fix scaling
        BoxDimensionHack.x = Screen.width * 6.7f / 9f;
        Style.fontSize     = (int)(_defaultFontSize * Screen.width / 430f);

        if (Timer <= 0)
        {
            SceneDataPasser.LastScore = Score;
            Application.LoadLevel("ScoreBoard");
            return;
        }

        if (IgnoreColorTime > 0)
        {
            IgnoreColorTime -= Time.deltaTime;
            if (IgnoreColorTime <= 0)
            {
                foreach (var piece in GamePieces)
                {
                    piece.IgnoreDepth = false;
                    piece.MatchDepthColor();
                }
            }
        }

        if (ScoreMultiplyTime > 0)
        {
            ScoreMultiplyTime -= Time.deltaTime;
            if (ScoreMultiplyTime <= 0)
            {
                GamePiece.Multiplier /= 2;
            }
        }

        if (TimeStopTime <= 0)
        {
            Timer -= Time.deltaTime;
        }
        else
        {
            TimeStopTime -= Time.deltaTime;
        }

        if (Input.GetMouseButton(0))
        {
            var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            mouseWorldPos.z = 0;

            var overlapPiece = Physics2D.OverlapPoint(mouseWorldPos);
            if (overlapPiece)
            {
                var closeEnoughToActivate = (overlapPiece.transform.position - mouseWorldPos).sqrMagnitude < MouseActivateDistance;
                if (closeEnoughToActivate)
                {
                    var gamePiece = overlapPiece.GetComponent <GamePiece>();
                    if (gamePiece)
                    {
                        if (ActiveWord.Length > 0 && ((ActiveWordDepth != gamePiece.Depth && !gamePiece.IgnoreDepth) || gamePiece.Locked))
                        {
                            OnSend();
                            return;
                        }

                        if (gamePiece.Locked)
                        {
                            return;
                        }

                        // HEY THEY'RE TRYING TO CHEAT!
                        if (ActiveWordPieces.Count > 0)
                        {
                            var lastPiece = ActiveWordPieces[ActiveWordPieces.Count - 1];
                            var colDif    = lastPiece.Col - gamePiece.Col;
                            var rowDif    = lastPiece.Row - gamePiece.Row;
                            if (rowDif <= -2 || rowDif >= 2 || colDif <= -2 || colDif >= 2)
                            {
                                OnSend();
                                return;
                            }
                        }

                        // TODO make sure user can't squeeze in the space between!
                        if (ActiveWordPieces.Contains(gamePiece))
                        {
                            // if it's the second from the end the user is moving backwards, want to remove the last piece
                            if (ActiveWordPieces.IndexOf(gamePiece) == ActiveWordPieces.Count - 2)
                            {
                                // remove the last piece
                                ActiveWordPieces.RemoveAt(ActiveWordPieces.Count - 1);
                                ActiveWord = ActiveWord.Remove(ActiveWord.Length - 1);
                            }
                        }
                        else
                        {
                            ActiveWordPieces.Add(gamePiece);
                            ActiveWord     += gamePiece.Letter;
                            ActiveWordDepth = gamePiece.Depth;
                        }
                    }
                }
            }

            // update the line
            Line.enabled = true;
            Line.SetVertexCount(ActiveWordPieces.Count + 1);
            for (var i = 0; i < ActiveWordPieces.Count; ++i)
            {
                Line.SetPosition(i, ActiveWordPieces[i].transform.position + new Vector3(0, 0, -1));
            }
            Line.SetPosition(ActiveWordPieces.Count, mouseWorldPos + new Vector3(0, 0, -1));
        }
        else if (Input.GetMouseButtonUp(0))
        {
            OnSend();
            Line.enabled = false;
        }
    }
示例#3
0
    public void OnSend()
    {
        var wordlookup  = GameObject.FindObjectOfType <WordLookup>();
        var isValidWord = wordlookup.CheckValidWord(ActiveWord);

        if (isValidWord)
        {
            var score = ScoreActiveWord();
            Score += score;
            Timer += AddTimePerPointScored * score;

            if (ScoreJuiceObject)
            {
                var mouseWorldPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                var go            = GameObject.Instantiate(ScoreJuiceObject.gameObject, mouseWorldPos, Quaternion.identity) as GameObject;
                var juice         = go.GetComponent <ScoreJuice>();
                var uiPos         = Input.mousePosition;
                uiPos.y     = Screen.height - uiPos.y;
                juice.Pos   = uiPos;
                juice.Score = score;
            }

            foreach (var piece in ActiveWordPieces)
            {
                if (piece == null)
                {
                    continue;
                }

                // grant power
                if (piece.GrantPower != GameButton.SuperPower.None)
                {
                    GrantPower(piece.GrantPower);
                }

                // get rid of piece
                GetRidOfPiece(piece, ActiveWordDepth + 1, _rand);
            }
            Camera.main.GetComponent <CameraShaker>().Shake();
        }
        else
        {
            foreach (var piece in ActiveWordPieces)
            {
                if (piece == null)
                {
                    continue;
                }

                // lock all the used pieces
                if (LockBadWords)
                {
                    piece.ToggleLock();
                }

                piece.UsedInWord = false;
            }

            ActiveWordPieces.Clear();
        }

        ActiveWordPieces.Clear();
        ActiveWord = "";
    }
示例#4
0
    public void GetRidOfPiece(GamePiece piece, int newDepth, System.Random rand)
    {
        if (piece.BeingDestroyed || piece.Fresh)
        {
            return;
        }

        GameObject.Destroy(piece.gameObject);
        piece.BeingDestroyed = true;
        // particle effects
        if (PieceExplodeParticleObject)
        {
            var particle = GameObject.Instantiate(PieceExplodeParticleObject, piece.gameObject.transform.position, Quaternion.identity) as GameObject;
            if (particle)
            {
                var system = particle.particleSystem;
                system.startColor = piece.RegularColor;
                system.Play();
                GameObject.Destroy(particle, system.startLifetime);
            }
        }

        // if it's a bomb destroy the neighbors!
        if (piece.Bomb)
        {
            for (var c = Mathf.Max(piece.Col - 1, 0); c <= Mathf.Min(piece.Col + 1, Cols - 1); ++c)
            {
                for (var r = Mathf.Max(piece.Row - 1, 0); r <= Mathf.Min(piece.Row + 1, Rows - 1); ++r)
                {
                    Debug.Log("trying to bomb r" + r + " c" + c + "from r" + piece.Row + " c" + piece.Col);
                    var bombedPiece = GamePieces[c, r];
                    if (!ActiveWordPieces.Contains(bombedPiece) && !bombedPiece.BeingDestroyed)
                    {
                        GetRidOfPiece(bombedPiece, newDepth, rand);
                    }
                }
            }
        }

        // add preivew beneath
        var newPiece = AddRandomPiece(piece.Row, piece.Col, newDepth, rand);

        newPiece.MatchDepthColor(true);
        newPiece.Fresh = true;

        var makeRainbow = rand.NextDouble() < RainbowChance;

        if (makeRainbow)
        {
            newPiece.GrantPower = GameButton.SuperPower.AllColor;
        }

        var makeSuper = !makeRainbow && rand.NextDouble() < SuperChance;

        if (makeSuper)
        {
            var powers = new List <GameButton.SuperPower>(System.Enum.GetValues(typeof(GameButton.SuperPower)) as GameButton.SuperPower[]);
            powers.Remove(GameButton.SuperPower.None);

            // all color handled separately
            powers.Remove(GameButton.SuperPower.AllColor);

            newPiece.GrantPower = powers[rand.Next(0, powers.Count)];
        }

        var makeBomb = !makeSuper && rand.NextDouble() < BombChance;

        if (makeBomb)
        {
            Debug.Log("Making bomb");
            newPiece.Bomb = true;
        }
    }