Esempio n. 1
0
        private void CellBtn_Click(object sender, RoutedEventArgs e)
        {
            Cell cell = (Cell)((Button)sender).Tag;

            //SelectedNeedles.Reverse();

            //Search needles list to see if the selected cell a needle, if it is...
            if (Needles.Find(x => x.coord.CompareTo(cell.coord) == 1) != null)
            {
                if (SelectedNeedles.Count > 0)
                {
                    Cell lastSelected = SelectedNeedles.Last();
                    int  correctIndex = Needles.FindLastIndex(x => x.value.CompareTo(lastSelected.value) == 0);

                    //If repeats are valid then the next value CAN be the same as the last.
                    if (settings.allowRepeats && lastSelected.value.CompareTo(cell.value) == 0)
                    {
                        AddSelectedCell(cell);
                    }
                    //If the last value is less than the next
                    else if (lastSelected.value.CompareTo(cell.value) == -1)
                    {
                        //if the selected cell is greater than the previous but is higher than the correct value then we failed

                        if ((!settings.allowRepeats && cell.value.CompareTo(Needles[correctIndex + 1].value) == 1) ||
                            //Or if repeats are allowed, if the selected cell is higher than the correct cell value or if the selected...
                            //..value is correct but not all of the previous value has been selected then we have failed
                            (settings.allowRepeats && (cell.value.CompareTo(Needles[correctIndex + 1].value) == 1 ||
                                                       (cell.value.CompareTo(Needles[correctIndex + 1].value) == 0 &&
                                                        SelectedNeedles.FindAll(x => x.value == lastSelected.value).Count < Needles.FindAll(x => x.value == lastSelected.value).Count))))
                        {
                            MessageBox.Show("Failed");
                            Window.GetWindow(this).Close();
                            return;
                        }

                        AddSelectedCell(cell);
                    }
                    else
                    {
                        MessageBox.Show("FAILED");
                        Window.GetWindow(this).Close();

                        return;
                    }
                }
                else
                {
                    //If the selected cell is not the first index of the Needles list (sorted by ascending value order and by coordinates) then its not in numerical order.

                    if ((settings.allowRepeats && Needles.FindIndex(x => x.value == cell.value) != 0) ||
                        (!settings.allowRepeats && Needles.FindIndex(x => x.coord.CompareTo(cell.coord) == 1) != 0))
                    {
                        if (Needles.FindIndex(x => x.value == cell.value) != 0)
                        {
                            MessageBox.Show("Failed");
                            Window.GetWindow(this).Close();
                            return;
                        }
                    }

                    //Handle some of the difficult settings here. If you're playing above easy, the first selection will hide the rest.
                    if (settings.difficulty > GameSettings.Difficulty.EASY)
                    {
                        foreach (Cell c in Needles)
                        {
                            c.cellType = Cell.CellType.HAYSTACK;
                        }
                    }

                    AddSelectedCell(cell);
                }

                cell.num.IsEnabled = false;

                if (SelectedNeedles.Count == Needles.Count)
                {
                    MessageBox.Show("Winner winner chicken dinner!");
                    Window.GetWindow(this).Close();
                    return;
                }
            }
            else
            {
                MessageBox.Show("FAiled");
                Window.GetWindow(this).Close();

                return;
            }
        }