Esempio n. 1
0
    void PrintBag()
    {
        string output = "";

        for (int i = 0; i < tiles.Length; i++)
        {
            if (tiles[i] != null)
            {
                LetterValue letter = tiles[i].GetComponent(typeof(LetterValue)) as LetterValue;
                if (letter != null)
                {
                    output += letter.GetLetter();
                }
                else
                {
                    output += ',';
                }
            }
            else
            {
                output += "null";
            }
        }
        Debug.Log(output);
    }
Esempio n. 2
0
    //returns the tile with a specific letter value
    //returns null if all such tiles are used up
    public GameObject DealSpecificTile(char letter)
    {
        int index = 150;         //arbitrary large value

        //find the tile
        for (int i = 0; i < tiles.Length; i++)
        {
            if (tiles[i] != null)
            {
                LetterValue letterVal = tiles[i].GetComponent(typeof(LetterValue)) as LetterValue;
                if (letterVal != null)
                {
                    if (letterVal.GetLetter() == letter)
                    {
                        index = i;
                    }
                }
            }
        }
        //if a matching tile was found
        if (index != 150)
        {
            GameObject tile = tiles[index];
            tiles[index] = null;
            PrintBag();
            bagCount--;
            return(tile);
        }
        else
        {
            return(null);
        }
    }
Esempio n. 3
0
    /*Prints letters in player's hand to console*/
    void PrintHand()
    {
        string output = "PlayerHand: ";

        for (int i = 0; i < hand.Length; i++)
        {
            LetterValue letter = hand[i].GetComponent(typeof(LetterValue)) as LetterValue;
            if (letter != null)
            {
                output += letter.GetLetter();
            }
            else
            {
                output += ',';
            }
        }
        //Debug.Log(output);
    }
Esempio n. 4
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);
    }