private void TileTouched(object sender, View.TouchEventArgs e) { // Check if the touch has finished if (e.Event.Action == MotionEventActions.Up) { TextTileView view = (TextTileView)sender; // Calculate the distance between the touched tile and the empty spot double yDiff = (view.PositionX - emptySpot.X); double xDiff = (view.PositionY - emptySpot.Y); // If they're adjacent, move the tile if ((Math.Abs(xDiff) == 1 && yDiff == 0) || (xDiff == 0 && Math.Abs(yDiff) == 1)) { int emptyX = emptySpot.X; int emptyY = emptySpot.Y; int textPosX = view.PositionX; int textPosY = view.PositionY; view.LayoutParameters = GetTileLayoutParams(emptyX, emptyY); emptySpot.X = textPosX; emptySpot.Y = textPosY; view.PositionX = emptyX; view.PositionY = emptyY; int tmp = board[textPosX][textPosY]; board[textPosX][textPosY] = board[emptyX][emptyY]; board[emptyX][emptyY] = tmp; NumberOfMoves++; if (CheckCorrect()) // player won! { bool newHighScore = false; // update high score in shared settings if (NumberOfMoves < highScore || highScore == 0) { highScore = NumberOfMoves; editor.PutInt(highscoreString, highScore); editor.Apply(); newHighScore = true; } var fragmentTrans = FragmentManager.BeginTransaction(); fragmentTrans.AddToBackStack(null); var gameOverDialog = GameOverDialogFragment.NewInstance(gridSize, NumberOfMoves, highScore, userName, newHighScore); gameOverDialog.RestartGameEvent += Reset; gameOverDialog.ExitGameEvent += OnExitGame; gameOverDialog.Cancelable = false; gameOverDialog.Show(fragmentTrans, "GameOverDialog"); } ResetSolver(); movesTextView.Text = string.Format("Moves: {0}", NumberOfMoves.ToString()); if (effects_enabled) { audioManager.PlaySoundEffect(SoundEffect.KeyClick); } } } }
public static GameOverDialogFragment NewInstance(int gridSize, int score, int highscore, string userName, bool newHighScore) { GameOverDialogFragment dialogFragment = new GameOverDialogFragment(); Bundle args = new Bundle(); args.PutInt("GridSize", gridSize); args.PutInt("Score", score); args.PutInt("HighScore", highscore); args.PutString("UserName", userName); args.PutBoolean("NewHighScore", newHighScore); dialogFragment.Arguments = args; return(dialogFragment); }