//returns true and triggers end game behavior
    public bool CheckWin()
    {
        if (tileDistributor.GetBagCount() < numPlayers)
        {
            return(true);
        }
        else
        {
            return(false);
        }

        //tell all players
    }
Example #2
0
    /*Checks board that player is using*/
    public void CheckBoard()
    {
        char[,] boardLetters = new char[16, 25];
        int totalLetters = 0;

        //ask each cell if it has a child, if so get the letter
        for (int i = 0; i < 16; i++)
        {
            for (int j = 0; j < 25; j++)
            {
                //Debug.Log("Index: " + cells[i,j].transform.GetSiblingIndex());
                //if the cell has a child
                if (cells[i, j].transform.childCount > 0)
                {
                    GameObject child = cells[i, j].transform.GetChild(0).gameObject;
                    //get letter
                    LetterValue letterObj = child.GetComponent(typeof(LetterValue)) as LetterValue;
                    if (letterObj != null)
                    {
                        boardLetters[i, j] = letterObj.GetLetter();
                        totalLetters++;
                    }
                    else
                    {
                        boardLetters[i, j] = ' ';
                    }
                }
                else
                {
                    boardLetters[i, j] = ' ';
                }
            }
        }

        //if not all letters were played
        if (totalLetters < hand.Length)
        {
            Debug.Log("Not all tiles were played.");
            modalPanel.Choice("You must play all tiles.", okayErrorAction);
        }
        else
        {
            //check board
            int error = boardChecker.CheckBoard(boardLetters, 16, 25);
            Debug.Log("BoardChecker returned: " + error);
            //if board is all good
            if (error == 0)
            {
                Debug.Log("Bag count: " + tileDistributor.GetBagCount());
                if (tileDistributor.GetBagCount() <= 1)
                {
                    Debug.Log("You win!");
                    modalPanel.Choice("You win!\nYou have used all tiles.", okayErrorAction);
                }
                else
                {
                    modalPanel.Choice("Good job! Here's another tile!", dealOneTileAction);
                }
            }
            //disconnected tile
            else if (error == 1)
            {
                modalPanel.Choice("It looks like you have a disconnected word!", okayErrorAction);
            }
            //wrong word
            else if (error == 2)
            {
                modalPanel.Choice("Oops...you misspelled a word.", okayErrorAction);
            }
        }
        Print2DArray(boardLetters);
    }