예제 #1
0
        private void Grid_Touch(object sender, View.TouchEventArgs e)
        {
            e.Handled = true;

            var ev = e.Event;
            var id = ev.GetPointerId(0);

            try
            {
                var x = ev.GetX(id);
                var y = ev.GetY(id);

                GameCell gameCell = null;

                for (int i = 0; i < grid.ChildCount; i++)
                {
                    var child = grid.GetChildAt(i) as GameCell;
                    if (child == null)
                    {
                        continue;
                    }

                    if (IsPointInsideView(x, y, child))
                    {
                        gameCell = child;
                        break;
                    }
                }
                var cell = gameCell?.ViewModel;

                switch (e.Event.Action)
                {
                case MotionEventActions.Down:
                    if (cell == null)
                    {
                        return;
                    }

                    if (runner.TouchStart(cell))
                    {
                        selectedGameCell = gameCell;
                        selectedGameCell.HighlightColor = selectedGameCell.MarkerColor;
                    }
                    break;

                case MotionEventActions.Move:
                    if (cell == null)
                    {
                        return;
                    }

                    if (runner.TouchCell(cell) && selectedGameCell != null)
                    {
                        gameCell.HighlightColor = selectedGameCell.MarkerColor;
                    }
                    break;

                case MotionEventActions.Up:
                case MotionEventActions.Cancel:
                    bool cleared;
                    if (!runner.TouchFinish(cell, out cleared))
                    {
                        if (!cleared)
                        {
                            // TODO: TAP sound
                        }
                    }
                    if (cleared)
                    {
                        // TODO: Pop sound
                    }
                    if (!runner.IsGameOver)
                    {
                        undoButton.Visibility = ViewStates.Visible;
                    }
                    selectedGameCell = null;
                    break;

                default:
                    System.Diagnostics.Debug.WriteLine($"Touch: {cell}: {e.Event.Action}, {e.Event.ActionMasked}");
                    break;
                }
            }
            catch
            {
                // Can get odd exceptions with multiple touch
            }

            e.Handled = true;
        }
예제 #2
0
        void BuildGrid(int startDelay)
        {
            if (building)
            {
                return;
            }

            building = true;

            undoButton.Visibility = ViewStates.Gone;

            grid.RemoveAllViews();
            grid.ColumnCount = runner.Definition.Width;
            grid.RowCount    = runner.Definition.Height;

            var cellDelay    = 40;
            var entranceType = RandomManager.Next(3);
            var duration     = 1000;

            if (runner.Definition.Width <= 5)
            {
                duration  = 1500;
                cellDelay = 60;
            }

            if (!runner.Definition.GameSet.IsTraining)
            {
                Shuffle(colorPalette);
            }

            for (int x = 0; x < runner.Definition.Width; x++)
            {
                for (int y = 0; y < runner.Definition.Height; y++)
                {
                    var cell     = runner.Grid[x, y];
                    var cellView = new GameCell(this);

                    cellView.ColorPalette = colorPalette;
                    if (runner.Definition.GameSet.IsTraining)
                    {
                        cellView.Font = FontManager.IconFont;
                    }

                    cellView.ViewModel = cell;

                    cell.View         = cellView;
                    cellView.TextSize = textSize;

                    var layoutParams = new GridLayout.LayoutParams(
                        GridLayout.InvokeSpec(y, 1f),          // Row
                        GridLayout.InvokeSpec(x, 1f));         // Col
                    grid.AddView(cellView, layoutParams);

                    switch (entranceType)
                    {
                    case 1:     // Outside-in
                    {
                        int distanceX = Math.Min(x, runner.Definition.Width - 1 - x);
                        int distanceY = Math.Min(y, runner.Definition.Height - 1 - y);
                        cellView.CreateAnimator <BounceInUpAnimator>()
                        .SetStartDelay(startDelay + ((distanceX + distanceY) * cellDelay))
                        .SetDuration(duration)
                        .Animate();
                    }
                    break;

                    case 2:     // Inside-out
                    {
                        int distanceX = Math.Max(x, runner.Definition.Width - 1 - x);
                        int distanceY = Math.Max(y, runner.Definition.Height - 1 - y);
                        cellView.CreateAnimator <BounceInUpAnimator>()
                        .SetStartDelay(startDelay + ((distanceX + distanceY) * cellDelay))
                        .SetDuration(duration)
                        .Animate();
                    }
                    break;

                    default:            // Start Top Left
                        cellView.CreateAnimator <BounceInUpAnimator>()
                        .SetStartDelay(startDelay + ((x + y) * cellDelay))
                        .SetDuration(duration)
                        .Animate();
                        break;
                    }
                }
            }
            building = false;
        }