Beispiel #1
0
        private void validateWord()
        {
            //add each character to selectedWord(StringBuilder)
            foreach (var buttonObj in selectedButtonList)
            {
                GridButton gridButton = (GridButton)buttonObj;
                selectedWord.Append(gridButton.Text);
                Console.WriteLine($"row: {gridButton.row}---- column: {gridButton.column}");
            }
            Console.WriteLine($"result: {selectedWord}");

            selectedButtonList.Clear();
            selectedWord.Clear();
        }
Beispiel #2
0
        //allows every element on correct axis.
        void AddButtonToList(object buttonObj)
        {
            //make sure next button/character is on the same axis.
            //check for result word in output.
            Console.WriteLine($"result: {selectedWord}");
            GridButton currentElement = (GridButton)buttonObj;
            int        rowDiff, columnDiff;

            //store 1st two element/button.
            if (selectedButtonList.Count < 2)
            {
                selectedButtonList.Add(buttonObj);
                Console.WriteLine("one");
            }

            //storing next element/button on drag.
            else if (selectedButtonList.Count == 2)
            {
                Console.WriteLine("two");
                GridButton firstElement  = (GridButton)selectedButtonList.First();
                GridButton secondElement = (GridButton)selectedButtonList.ElementAt(1);

                rowDiff    = Math.Abs(firstElement.row - secondElement.row);
                columnDiff = Math.Abs(firstElement.column - secondElement.column);

                //for elements at x-axis, y-axis and z-axis respectively.
                if (currentElement.row == firstElement.row)
                {
                    axis = 'x';
                    Console.WriteLine($"axis :{axis}");
                }
                else if (currentElement.column == firstElement.column)
                {
                    axis = 'y';
                    Console.WriteLine($"axis :{axis}");
                }
                else if (rowDiff == columnDiff)
                {
                    axis = 'z';
                    Console.WriteLine($"axis :{axis}");
                }
            }

            if (axis != 'a')
            {
                GridButton startElement = (GridButton)selectedButtonList.ElementAt(0);
                switch (axis)
                {
                case 'x':
                    Console.WriteLine("axisXX");
                    if (currentElement.row == startElement.row)
                    {
                        selectedButtonList.Add(buttonObj);
                    }
                    break;

                case 'y':
                    Console.WriteLine("axisYY");
                    if (currentElement.column == startElement.column)
                    {
                        selectedButtonList.Add(buttonObj);
                    }
                    break;

                case 'z':
                    Console.WriteLine("axisZZ");
                    rowDiff    = Math.Abs(startElement.row - currentElement.row);
                    columnDiff = Math.Abs(startElement.column - currentElement.column);

                    if (rowDiff == columnDiff)
                    {
                        selectedButtonList.Add(buttonObj);
                    }
                    break;

                default:
                    Console.WriteLine($"list: {selectedButtonList.Count}");
                    break;
                }
            }
            //if (selectedButtonList.Count == 2)
            //{
            //    GridButton firstElement = (GridButton)selectedButtonList.First();
            //    rowDiff = Math.Abs(currentButton.row - firstElement.row);
            //    columnDiff = Math.Abs(currentButton.column - firstElement.column);

            //    //for elements at x-axis, y-axis and z-axis respectively.
            //    if (currentButton.row == firstElement.row || currentButton.column == firstElement.column || rowDiff == columnDiff)
            //    {
            //        selectedButtonList.Add(buttonObj);
            //    }

            //    return;
            //}
        }