Esempio n. 1
0
 private void ClearSelection()
 {
     if (selectedTile != null)
     {
         selectedTile.selected = false;
         selectedTile          = null;
         leftArea = false;
     }
 }
Esempio n. 2
0
    void PlaceWord(string word, int row, int offset)
    {
        //UnityEngine.Debug.Log("PlaceWord(word = " + word + ", row = " + row + ", offset = " + offset + ")");
        List <LibrettoTile> wordTiles = wordGrid.GetRowTiles(word.Length, row, offset);
        var chars = word.ToCharArray();

        for (int i = 0; i < word.Length; i++)
        {
            LibrettoTile tile = wordTiles[i];
            tile.SetTileData(chars[i]);
            tile.ShowFixed();
        }
    }
Esempio n. 3
0
    void NewPuzzle()
    {
        wordGrid.BuildGrid();
        panelGrid.BuildGrid();
        SelectWords();

        // Place horizontal words and select tiles for vertical word.
        Assert.AreEqual(topIntercept, bottomIntercept); // currently constrained to be at some intercepts
        int diff = topIntercept - bottomIntercept;
        List <LibrettoTile> tiles;

        if (diff >= 0)
        {
            PlaceWord(topWord, topWordRow, 0);
            PlaceWord(bottomWord, bottomWordRow, diff);
            tiles = wordGrid.GetColumnTiles(topIntercept, mysteryWord.Length);
        }
        else
        {
            PlaceWord(topWord, topWordRow, -diff);
            PlaceWord(bottomWord, bottomWordRow, 0);
            tiles = wordGrid.GetColumnTiles(bottomIntercept, mysteryWord.Length);
        }

        // Show gap tiles and build up letters for panel.
        puzzleWord  = new PuzzleWord(mysteryWord, tiles);
        buttonChars = new List <char>();
        for (int i = 0; i < mysteryWord.Length; i++)
        {
            LibrettoTile tile = tiles[i];
            if (tile.tileType == LibrettoTile.TILE_TYPE.EMPTY)
            {
                tile.ShowGap();
                buttonChars.Add(mysteryWord[i]);
            }
        }

        // Set up distractors.
        distractorChars = new List <char>();
        for (int i = 0; i < NUM_DISTRACTERS; i++)
        {
            char distractor = LibrettoTileBag.GetLetter();
            distractorChars.Add(distractor);
            buttonChars.Add(distractor);
        }
        Debug.Log("distractorChars: " + new string(distractorChars.ToArray()));
        buttonChars = Utils.Scramble <char>(buttonChars);
        Debug.Log("buttonChars: " + new string(buttonChars.ToArray()));
        panelGrid.ShowRowChars(buttonChars);
    }
Esempio n. 4
0
    public void HandleTouchDown(Vector2 touch)
    {
        ClearSelection();

        touchPosition   = Camera.main.ScreenToWorldPoint(touch);
        touchPosition.z = 0;

        //check panel grid
        var tile = panelGrid.TileCloseToPoint(touchPosition);

        if (tile == null || !tile.gameObject.activeSelf)
        {
            //check word grid
            tile = wordGrid.TileCloseToPoint(touchPosition);
            if (tile != null && tile.gameObject.activeSelf && tile.IsMovable())
            {
                //pick tile from panel
                var tempTile = Instantiate(panelGrid.gridTileGO) as GameObject;
                tempTileOrigin = tile;

                selectedTile = tempTile.GetComponent <LibrettoTile>();
                selectedTile.transform.localScale = panelGrid.transform.localScale;
                selectedTile.transform.parent     = wordGrid.transform;

                selectedTile.transform.localPosition = tile.transform.localPosition;
                selectedTile.gridType = LibrettoGrid.GRID_TYPE.WORD_GRID;
                selectedTile.SetTileData(tile.TypeChar);
                selectedTile.ShowTemporary();

                tile.ShowGap();
            }
        }
        else
        {
            selectedTile = tile;
        }

        if (selectedTile != null)
        {
            selectedTile.Select(true);
        }
    }
Esempio n. 5
0
    public void GiveHint()
    {
        // First, remove a distractor if any remain.
        if (distractorChars.Count > 0)
        {
            char distractor = distractorChars[0];
            distractorChars.RemoveAt(0);

            //  This removes a tile with the distracting letter from the panel
            // but not from the word grid if it has been placed.
            foreach (LibrettoTile tile in panelGrid.tiles)
            {
                if (tile.TypeChar == distractor)
                {
                    // Remove from tile panel.
                    panelGrid.tiles.Remove(tile);   // remove so it won't be used later for hint
                    buttonChars.Remove(distractor); // so it won't reappear on reset
                    bool placed = !tile.IsActive();
                    tile.ShowEmpty();

                    // Remove from word grid if placed there.
                    if (placed)
                    {
                        foreach (LibrettoTile wordTile in puzzleWord.wordTiles)
                        {
                            if (wordTile.TypeChar == distractor &&
                                wordTile.tileType == LibrettoTile.TILE_TYPE.PLACED)
                            {
                                wordTile.ShowGap();
                                return;
                            }
                        }
                        Assert.IsTrue(false);
                    }
                    return;
                }
            }
            Assert.IsTrue(false); // The tile was not found in panel
        }

        // If no distractors are available, show any misplaced letters.
        if (puzzleWord.Has(LibrettoTile.TILE_TYPE.PLACED))
        {
            bool foundWrong = false;
            for (var i = 0; i < puzzleWord.word.Length; i++)
            {
                LibrettoTile wordTile = puzzleWord.wordTiles[i];
                if (wordTile.tileType == LibrettoTile.TILE_TYPE.PLACED && wordTile.TypeChar != puzzleWord.word[i])
                {
                    wordTile.ShowWrong();
                    foundWrong = true;
                }
            }

            if (foundWrong)
            {
                return;
            }
        }

        // fill in a letter from the panel.
        var index = 0;

        foreach (LibrettoTile wordTile in puzzleWord.wordTiles)
        {
            if (wordTile.tileType == LibrettoTile.TILE_TYPE.GAP)
            {
                char c = puzzleWord.word[index];
                foreach (LibrettoTile panelTile in panelGrid.tiles)
                {
                    if (panelTile.TypeChar == c)
                    {
                        // Also make sure this works with dead distractor tiles.
                        if (panelTile.IsActive())
                        {
                            wordTile.Place(c);
                            panelTile.HideInPanel();
                            CheckSolution();
                            return;
                        }
                        // We can't use this panel tile, since it's already been played, but
                        // maybe there's another panel tile with the same letter, so keep looking.
                    }
                }
            }
            index++;
        }
    }