void ClearSelected() { for (int i = 0; i < grid.ChildCount; i++) { var squareWidget = grid.GetChildAt(i) as SquareWidget; //if (squareWidget != null) // squareWidget.IsSelected = false; var highScore = GameData.Current.GetGameHighScore(squareWidget.GameDefinition as GameDefinition); squareWidget.ShowBackground = highScore == null; } }
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; }