示例#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 AddLetter_BeginsWord()
        {
            var word = new ActiveWord();

            word.AddAlphaNumeric(new KeyData(Keys.A, "a", null, DateTime.UtcNow));

            Assert.False(word.IsComplete);
            Assert.That(word.CurrentData.Length == 1);
        }
示例#3
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;
        }
    }