private void PictureBoxClick(object sender, EventArgs e) { PictureBox pic = (PictureBox)sender; int idx = (int)pic.Tag; //if it near zero, if (IsNearZeroPeice(idx)) { //it will swap location with zero _puzzleGame.Matrix[idx].SwapLocation(_puzzleGame.Matrix[0]); //Update change UpdatePictureBoxLocation(); //Set start time if (!timer.Enabled) { timer.Enabled = true; _timeCount = 0; } //Check to win if (_puzzleGame.IsWin(_puzzleGame.CustomMatrix(PEICE_SIZE, LOCATION, LOCATION))) { MessageBox.Show("You win!"); timer.Enabled = false; _puzzleGame.CreateMatrix(PEICE_SIZE, LOCATION, LOCATION); } } }
public FormView() { InitializeComponent(); _puzzleGame = new PuzzleGame { Name = "OriginalGame" }; _puzzleGame.CreateMatrix(PEICE_SIZE, LOCATION, LOCATION); UpdatePictureBoxLocation(); SetTagForPicturesbox(); }