Ejemplo n.º 1
0
    public void SetCharInContainerButton(LetterButton b)
    {
        if (blockInput)
        {
            return;
        }

        if (selectedContainer == nothingWordContainer)
        {
            b.ConsumeLetter();
            nothingWordContainer.TrySetWord(b.GetCharacter());
            return;
        }

        if (selectedContainer != null)
        {
            if (selectedContainer.TrySetWord(b.GetCharacter()))
            {
                b.ConsumeLetter();
                nothingWordContainer.TrySetWord(b.GetCharacter());
            }
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructor. Nothing much to say.
        /// </summary>
        /// <param name="x">The initial size of the grid in the x-direction, must be less than GRID_MAX_X</param>
        /// <param name="y">The initial size of the grid in the y-direction, must be less than GRID_MAX_Y</param>
        /// <param name="window">A reference to the parent form of this grid</param>
        public LetterGrid(int x, int y, MainWindow window)
        {
            ParentWindow = window;

            if (x > GRID_MAX_X || y > GRID_MAX_Y)
            {
                throw new ArgumentOutOfRangeException("X or Y values greater than allowed size");
            }
            SizeX = x;
            SizeY = y;

            Options = new GameOptions(false);

            Buttons = new LetterButton[GRID_MAX_Y][];
            for (int i = 0; i < GRID_MAX_Y; i++)
            {
                Buttons[i] = new LetterButton[GRID_MAX_X];
                for (int j = 0; j < GRID_MAX_X; j++)
                {
                    Buttons[i][j] = new LetterButton(j, i).Sync(this);
                }
            }
        }
    //TODO:
    //Compare shuffled list to starting list
    //Keep shuffling until they are different
    //handle case of 1 rack shuffle
    public void Shuffle()
    {
        List <LetterButton> lettersToShuffle = new List <LetterButton>();

        //Remove tiles from slots and add to a list
        foreach (LetterSlot slot in slots)
        {
            if (slot.IsOccupied)
            {
                lettersToShuffle.Add(slot.LetterButton);
                slot.ClearSlot();
            }
        }
        //Shuffle the list
        LetterButton[] letters = lettersToShuffle.ToArray();
        for (int i = 0; i < letters.Length; i++)
        {
            LetterButton temp        = letters[i];
            int          randomIndex = Random.Range(i, letters.Length);
            letters[i]           = letters[randomIndex];
            letters[randomIndex] = temp;
        }
        //Add back to the slots

        int tilesToAddIndex = 0;

        //Only add tiles slots that are empty in the play rack
        for (int i = 0; i < slots.Count; i++)
        {
            Debug.Log(_dependentRack.slots[i].IsOccupied);
            if (_dependentRack.slots[i].IsOccupied == false)
            {
                AddTileToSlot(letters[tilesToAddIndex], slots[i]);
                tilesToAddIndex++;
            }
        }
    }
Ejemplo n.º 4
0
 /// <summary>
 /// Convenience constructor to go straight from a button
 /// </summary>
 /// <param name="parentGrid">The parent grid for the node</param>
 /// <param name="button">The button to convert</param>
 public GridNode(LetterGrid parentGrid, LetterButton button)
     : this(parentGrid, button.SelectedLetter, button.IsRequired, button.Restriction)
 {
 }
 public void ClearSlot()
 {
     letterButton = null;
     _isOccupied  = false;
 }
 public void AddToSlot(LetterButton letterButton)
 {
     this.letterButton = letterButton;
     letterButton.transform.SetParent(this.transform, false);
     _isOccupied = true;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Remove a letter from the grid (i.e. the user has right-clicked and selected remove letter on a button)
        /// </summary>
        /// <param name="button">The button to be removed</param>
        public void RemoveLetter(LetterButton button)
        {
            if (!Options.IsAnagram)
            {
                throw new InvalidOperationException("Letters can only be removed in anagram mode!");
            }

            if (Options.AnagramLength-- == 0)
            {
                return;
            }

            bool found = false;
            int  x = 0, y = 0;

            for (; y < SizeY; y++)
            {
                for (x = 0; x < SizeX; x++)
                {
                    if (Buttons[y][x] == button)
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }

            if (!found)
            {
                throw new ArgumentException("Button was not found in grid!");
            }

            for (; x < SizeX; x++)
            {
                if (x == SizeX - 1)
                {
                    Buttons[y][x].SelectedLetter = Buttons[y + 1][0].SelectedLetter;
                    Buttons[y][x].IsRequired     = Buttons[y + 1][0].IsRequired;
                    Buttons[y][x].Restriction    = Buttons[y + 1][0].Restriction;
                    if (Buttons[y][x].IsAddLetter = Buttons[y + 1][0].IsAddLetter)
                    {
                        ParentWindow.RefreshPanel();
                        return;
                    }
                }
                else
                {
                    Buttons[y][x].SelectedLetter = Buttons[y][x + 1].SelectedLetter;
                    Buttons[y][x].IsRequired     = Buttons[y][x + 1].IsRequired;
                    Buttons[y][x].Restriction    = Buttons[y][x + 1].Restriction;
                    if (Buttons[y][x].IsAddLetter = Buttons[y][x + 1].IsAddLetter)
                    {
                        ParentWindow.RefreshPanel();
                        return;
                    }
                }
            }

            for (y++; y < SizeY; y++)
            {
                for (x = 0; x < SizeX; x++)
                {
                    if (x == SizeX - 1)
                    {
                        Buttons[y][x].SelectedLetter = Buttons[y + 1][0].SelectedLetter;
                        Buttons[y][x].IsRequired     = Buttons[y + 1][0].IsRequired;
                        Buttons[y][x].Restriction    = Buttons[y + 1][0].Restriction;
                        if (Buttons[y][x].IsAddLetter = Buttons[y + 1][0].IsAddLetter)
                        {
                            ParentWindow.RefreshPanel();
                            return;
                        }
                    }
                    else
                    {
                        Buttons[y][x].SelectedLetter = Buttons[y][x + 1].SelectedLetter;
                        Buttons[y][x].IsRequired     = Buttons[y][x + 1].IsRequired;
                        Buttons[y][x].Restriction    = Buttons[y][x + 1].Restriction;
                        if (Buttons[y][x].IsAddLetter = Buttons[y][x + 1].IsAddLetter)
                        {
                            ParentWindow.RefreshPanel();
                            return;
                        }
                    }
                }
            }
        }
 public void LetterButtonTapped(LetterButton letterButton)
 {
     Debug.Log("LetterButtonTapped: " + letterButton.name);
     RemoveLetterButton(letterButton);
     _dependentRack.AddLetterButtonToFirstEmptySlot(letterButton);
 }