/* * Diese Methode erzeugt 16 PictureBoxen samt Click-Event. * Desweiteren zerteilt sie das original Bild in 16 images für 16 PTs und die 16 PictureBoxen. */ private void splitImagesToPicBoxes() { if (picBoxWhole != null) { PuzzleBox.Controls.Remove(picBoxWhole); picBoxWhole.Dispose(); picBoxWhole = null; } if (picBoxes == null) { PT = new PuzzleTile[BOX_NUM]; picBoxes = new PictureBox[BOX_NUM]; } int numRow = 4; int numCol = 4; int unitX = PuzzleBox.Width / numRow; int unitY = PuzzleBox.Height / numCol; int[] indice = new int[BOX_NUM]; for (int i = 0; i < BOX_NUM; i++) { indice[i] = i; if (picBoxes[i] == null) { picBoxes[i] = new PictureBox(); picBoxes[i].BorderStyle = BorderStyle.Fixed3D; picBoxes[i].Click += new EventHandler(picBoxes_click); } picBoxes[i].Width = unitX; picBoxes[i].Height = unitY; PT[i] = new PuzzleTile(); PT[i].ID= i; PT[i].PuzzleTileImage = CreateBitmapImage(image,i, numRow, numCol, unitX, unitY); picBoxes[i].Image = PT[i].PuzzleTileImage; picBoxes[i].Location = new Point(unitX * (i % numCol), unitY * (i / numCol)); PuzzleBox.Controls.Add(picBoxes[i]); } }
/* * Diese Methode synchronisiert die PTs mit den Items. * Sowie die Images der PTs mit den Images der PictureBoxen. */ private void fitPTtoItems() { PuzzleTile dummyTile = PT[15]; PuzzleTile[] dummy = new PuzzleTile[BOX_NUM]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (game.items[i] == PT[j].ID) { dummy[i] = PT[j]; } } } PT = dummy; for (int i = 0; i<16; i++) { picBoxes[i].Image = PT[i].PuzzleTileImage; } }