Пример #1
0
        public void SetGameDefinition(GameDefinition gameDefinition)
        {
            IsGameOver  = false;
            IsHighScore = false;
            Definition  = gameDefinition;
            SelectedCells.Clear();

            StartTime  = DateTime.Now;
            Grid       = new SquareDataViewModel[Definition.Width, Definition.Height];
            GridStates = new Stack <GridState>();
            Color      = Definition.GameSet.Color;

            for (int x = 0; x < Definition.Width; x++)
            {
                for (int y = 0; y < Definition.Height; y++)
                {
                    Grid[x, y] = new SquareDataViewModel
                    {
                        MarkerVisible = true,
                        //HighColor = Color,
                        //MedColor = "#ADD8E6",
                    };
                }
            }

            int index = 0;

            foreach (var gameLine in Definition.Lines)
            {
                int startX, startY;
                int endX, endY;

                index++;
                //if (string.IsNullOrWhiteSpace(gameLine.Key))
                //    gameLine.Key = index.ToString();

                Definition.GetStartXY(gameLine, out startX, out startY);
                Definition.GetEndXY(gameLine, out endX, out endY);

                var square = Grid[startX, startY];
                square.Fixed        = true;
                square.PaletteIndex = index;
                square.Text         = gameLine.Text;
                square.GameLine     = gameLine;

                square              = Grid[endX, endY];
                square.Fixed        = true;
                square.Text         = gameLine.Text;
                square.PaletteIndex = index;
                square.GameLine     = gameLine;
            }

            Level = string.Format("Level {0}", Definition.Index + 1);

            GetHighScore();
        }
Пример #2
0
        void FindRowByStringValue(string searchedValue)
        {
            if (string.IsNullOrWhiteSpace(searchedValue) || CurrentColumn == null)
            {
                return;
            }

            if (CurrentColumn is DataGridTextColumn)
            {
                string searchedText = searchedValue.ToLower();

                var col = CurrentColumn as DataGridTextColumn;

                string bindingPath = (col.Binding as Binding).Path.Path;

                foreach (var item in ItemsSource)
                {
                    // ќпредел¤ем тип источника и получаем искомое свойство
                    var type             = item.GetType();
                    var searchedProperty = type.GetProperty(bindingPath);
                    if (searchedProperty != null)
                    {
                        // ѕредставл¤ем как строку и сравниваем
                        string currentValue = searchedProperty.GetValue(item, null).ToString().ToLower();
                        if (currentValue.StartsWith(searchedText))
                        {
                            var cellInfo = new DataGridCellInfo(item, CurrentColumn);
                            SelectedCells.Clear();
                            SelectedCells.Add(cellInfo);
                            ScrollIntoView(item, CurrentColumn);
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        private void ClearSelectedShape()
        {
            if (SelectedLine == null)
            {
                return;
            }

            var allCells = Grid.Flatten().ToList();

            foreach (var square in allCells.Where(s => s.GameLine == SelectedLine))
            {
                square.TouchState    = TouchState.UnTouched;
                square.MarkerVisible = true;

                if (!square.Fixed)
                {
                    square.GameLine = null;
                }

                square.View.Update();
            }
            SelectedLine = null;
            SelectedCells.Clear();
        }
 public void ClearSelection()
 {
     SelectedCells.Clear();
 }
Пример #5
0
        public bool TouchFinish(SquareDataViewModel cell, out bool cleared)
        {
            int x, y;

            cleared = false;
            if (SelectedCells.Count == 0)
            {
                return(false);
            }

            var state = CreateGridState();

            if (cell == null)
            {
                var cellIndex = SelectedCells.Last();
                x    = cellIndex % Definition.Width;
                y    = cellIndex / Definition.Width;
                cell = Grid[x, y];
            }
            else
            {
                FindXY(cell, out x, out y);
            }

            Debug.WriteLine($"TouchFinish: {x}, {y}: {cell}");

            if (IsGameOver)
            {
                return(false);
            }
            if (SelectedLine == null)
            {
                return(false);
            }

            if (SelectedCells.Count >= 2)
            {
                int cellIndex     = Definition.GetCellIndex(x, y);
                int lastCellIndex = SelectedCells.Last();
                if (lastCellIndex == cellIndex)
                {
                    lastCellIndex = SelectedCells[SelectedCells.Count - 2];
                }

                if (!AreCellsNextToEachOther(lastCellIndex, cellIndex))
                {
                    ClearSelectedShape();
                    return(false);
                }
            }


            var allCells        = Grid.Flatten().ToList();
            var touchingCelling = allCells.Where(c => c.TouchState == TouchState.Touching);

            if (cell.Fixed &&                           // Start or end
                cell.GameLine == SelectedLine &&        // Same as beggining
                (touchingCelling.Count() > 1))          // Selected more than a single cell
            {
                foreach (var touchedCell in touchingCelling)
                {
                    touchedCell.TouchState    = TouchState.Touched;
                    touchedCell.MarkerVisible = false;
                }
                cell.TouchState    = TouchState.Touched;
                cell.MarkerVisible = false;

                SelectedLine = null;
                SelectedCells.Clear();

                UpdateAllCells();
                if (CheckComplete())
                {
                    return(false);
                }

                GridStates.Push(state);
                return(true);
            }

            ClearSelectedShape();
            return(false);
        }