public void OnEndTurn()
 {
     if (CurrentTiles.Count > 0)
     {
         if (CheckWords())
         {
             _turnsSkipped = 0;
             CurrentTurn++;
             var points = CountPoints();
             if (CurrentPlayer == 1)
             {
                 Player1.ChangeBox(7 - Player1.CurrentLetters.Count);
                 Player1.Score += points;
                 if (Player1.CurrentLetters.Count == 0)
                 {
                     EndGame(Player1);
                 }
                 Player1.gameObject.SetActive(false);
                 Player2.gameObject.SetActive(true);
                 CurrentTiles.Clear();
                 CurrentDirection = Direction.None;
                 CurrentPlayer    = 2;
                 Controller.InvalidatePlayer(1, Player1.Score);
                 isFirstTurn = false;
             }
             else
             {
                 Player2.ChangeBox(7 - Player2.CurrentLetters.Count);
                 Player2.Score += points;
                 if (Player2.CurrentLetters.Count == 0)
                 {
                     EndGame(Player2);
                 }
                 Player1.gameObject.SetActive(true);
                 Player2.gameObject.SetActive(false);
                 CurrentDirection = Direction.None;
                 CurrentTiles.Clear();
                 CurrentPlayer = 1;
                 Controller.InvalidatePlayer(2, Player2.Score);
                 isFirstTurn = false;
             }
             if (_timerEnabled)
             {
                 _timeRemaining = (float)_timerLength + 1;
             }
         }
         else
         {
             Controller.ShowNotExistError();
         }
     }
     else
     {
         Controller.ShowZeroTilesError();
     }
     _wordsFound = new List <TileH>();
 }
Exemple #2
0
    //Removes stuck letter from field
    public void Fix()
    {
        parent.FreeCoordinates.Add(DragHandler.StartPosition);
        parent.ChangeBox(1, LetterText.text);
        var index = parent.FindIndex(this);

        parent.CurrentLetters[index] = parent.CurrentLetters[parent.CurrentLetters.Count - 1];
        parent.CurrentLetters.RemoveAt(parent.CurrentLetters.Count - 1);
        transform.position = new Vector3(-1500, -1500);
    }
    public void OnEndTurn()
    {
        //print ("clicked it");
        if (CurrentTiles.Count > 0)
        {
            if (CheckWords())               //if successfully words are being checked

            {
                _turnsSkipped = 0;
                CurrentTurn++;
                var points = CountPoints();
                if (CurrentPlayer == 1)
                {
                    Player1.ChangeBox(7 - Player1.CurrentLetters.Count);
                    Player1.Score += points;
                    if (Player1.CurrentLetters.Count == 0)
                    {
                        EndGame(Player1);
                    }
                    Player1.gameObject.SetActive(false);
                    Player2.gameObject.SetActive(true);
                    CurrentTiles.Clear();
                    CurrentDirection = Direction.None;
                    CurrentPlayer    = 2;
                    Controller.InvalidatePlayer(1, Player1.Score);
                    isFirstTurn = false;
                }
                else
                {
                    Player2.ChangeBox(7 - Player2.CurrentLetters.Count);
                    Player2.Score += points;
                    if (Player2.CurrentLetters.Count == 0)
                    {
                        EndGame(Player2);
                    }
                    Player1.gameObject.SetActive(true);
                    Player2.gameObject.SetActive(false);
                    CurrentDirection = Direction.None;
                    CurrentTiles.Clear();
                    CurrentPlayer = 1;
                    Controller.InvalidatePlayer(2, Player2.Score);
                    isFirstTurn = false;
                }
                if (_timerEnabled)
                {
                    _timeRemaining = (float)_timerLength + 1;
                }
            }
            else
            {
                this.OnRemoveAll(); // go back tiles when word is not exist
                if (!Field[5, 5].HasLetter)
                {
                    Field[5, 5].CanDrop = true;
                }
                Controller.ShowNotExistError();
            }
        }
        else
        {
            Controller.ShowZeroTilesError();
        }

        _wordsFound = new List <TileH>();
    }