/// <summary> /// assign 0 type /// </summary> public void TileConfigration() { TileConfig tc = images[0]; tile.Image = tc.Image; tile.TileCategory = tc.Category; tile.TileType = tc.TileType; tile.Click -= PictureBox_Click; tile.BorderStyle = BorderStyle.None; //tile.BackColor = Color.Beige; }
/// <summary> /// function to create the level load the images /// </summary> public void GetImage() { //declaring local variables x = 50; y = 50; VGAP = 100; //the dictionary of images //assign type &catogery to the tile images[0] = new TileConfig() { Image = null , TileType = "none" , Category = "none" }; images[1] = new TileConfig() { Image = Properties.Resources.wall2 , TileType = "wall" , Category = "wall" }; images[2] = new TileConfig() { Image = Properties.Resources.doorBlue , TileType = "door" , Category = "blue" }; images[3] = new TileConfig() { Image = Properties.Resources.doorYellow , TileType = "door" , Category = "yellow" }; images[4] = new TileConfig() { Image = Properties.Resources.doorRed , TileType = "door" , Category = "red" }; images[5] = new TileConfig() { Image = Properties.Resources.doorGreen , TileType = "door" , Category = "green" }; images[6] = new TileConfig() { Image = Properties.Resources.boxesGreen , TileType = "box" , Category = "green" }; images[7] = new TileConfig() { Image = Properties.Resources.boxesYellow , TileType = "box" , Category = "yellow" }; images[8] = new TileConfig() { Image = Properties.Resources.boxesBlue , TileType = "box" , Category = "blue" }; images[9] = new TileConfig() { Image = Properties.Resources.boxesRed , TileType = "box" , Category = "red" }; try {//create the grid load the image pictureBoxMatrix = new TilePlay[colNumber, rowsNumber]; try { for (int i = 0; i < colNumber; i++) { for (int j = 0; j < rowsNumber; j++) { var config = images[int.Parse(lines[counter])]; TilePlay myTile = new TilePlay(); myTile.Location = new Point(i * x + VGAP, j * x + y); myTile.Image = config.Image; myTile.TileType = config.TileType; myTile.TileCategory = config.Category; myTile.Row = j; myTile.Col = i; myTile.Click += PictureBox_Click; //check the number of boxes if (myTile.TileType == "box") { boxCounter++; } pictureBoxMatrix[i, j] = myTile; this.Controls.Add(pictureBoxMatrix[i, j]); counter++; } } MessageBox.Show("The level created successfully"); //disable load menu loadGameToolStripMenuItem.Enabled = false; //enable the navigation buttons this.btnUp.Enabled = true; this.btnRight.Enabled = true; this.btnleft.Enabled = true; this.btnDown.Enabled = true; } catch (Exception ex) { MessageBox.Show("Error in creating the grid " + ex.Message); } } catch (FormatException ex) { //when input is not number MessageBox.Show("Invalid format: " + ex.Message); } catch (Exception ex) { MessageBox.Show("Invalid Entries " + ex.Message); } }