Пример #1
0
        public Form1()
        {
            InitializeComponent();

            listofPcbRows = new List <List <PictureBox> >();
            tpState       = new TilePlacingState();
            levelWidth    = 48;
            levelHeight   = 9;

            //create PictureBoxes for map and add to list in a loop

            /*(i am using x and y here instead of i and j because i will be using these attributes
             * for PictureBox placement as well, and it makes it a little bit clearer for both math and list placement)
             */
            for (int y = 0; y < levelHeight; y++)
            {
                //add a new "row" of PictureBoxs to the list
                listofPcbRows.Add(new List <PictureBox>());

                for (int x = 0; x < levelWidth; x++)
                {
                    PictureBox pcb = new PictureBox();
                    pcb.Size      = new Size(25, 25);
                    pcb.Location  = new Point(25 * x, 200 + 25 * y);
                    pcb.Name      = "n"; //initialize to n, meaning nothing in the cell
                    pcb.BackColor = Color.Gray;
                    pcb.Padding   = new Padding(3, 3, 3, 3);
                    //there has to be a "placeholder" image that is just plain white, that combined with the padding makes the grid visible
                    pcb.Image = LevelEditor.Properties.Resources.blank;

                    //need to tell the form that the PictureBoxes EXIST so it can actually put them in
                    this.Controls.Add(pcb);

                    //this hooks up the PictureBox click to the event handler
                    //pcb.MouseDown += PictureBoxHandler;
                    pcb.MouseDown  += PictureBoxMouseDownHandler;
                    pcb.MouseEnter += PictureBoxMouseDownHandler;

                    //add the PictureBox to the "row" in the list
                    listofPcbRows[y].Add(pcb);
                }
            }

            void PictureBoxMouseDownHandler(object sender, EventArgs e) //event handler for PictureBox click
            {
                PictureBox b = (PictureBox)sender;                      //cast sender to PictureBox object

                //if(mouse) { }


                switch (tpState)
                {
                case TilePlacingState.wood:
                    b.Image = LevelEditor.Properties.Resources.woodtexture;
                    b.Name  = "w";
                    break;

                case TilePlacingState.stone:
                    b.Image = LevelEditor.Properties.Resources.stonetexture;
                    b.Name  = "s";

                    break;

                case TilePlacingState.water:
                    b.Image = LevelEditor.Properties.Resources.watertexture;
                    b.Name  = "a";    //wood already has w

                    break;

                case TilePlacingState.grass:
                    b.Image = LevelEditor.Properties.Resources.grasstexture;
                    b.Name  = "g";

                    break;

                case TilePlacingState.nothing:
                    b.Image = LevelEditor.Properties.Resources.blank;
                    b.Name  = "n";


                    break;
                }
            }
        }
Пример #2
0
 private void btnNothing_Click(object sender, EventArgs e)
 {
     tpState         = TilePlacingState.nothing;
     lblPlacing.Text = "Placing: Nothing";
 }
Пример #3
0
 private void btnGrass_Click(object sender, EventArgs e)
 {
     tpState         = TilePlacingState.grass;
     lblPlacing.Text = "Placing: Grass";
 }
Пример #4
0
 private void btnWater_Click(object sender, EventArgs e)
 {
     tpState         = TilePlacingState.water;
     lblPlacing.Text = "Placing: Water";
 }
Пример #5
0
 private void btnStone_Click(object sender, EventArgs e)
 {
     tpState         = TilePlacingState.stone;
     lblPlacing.Text = "Placing: Stone";
 }
Пример #6
0
 private void btnWood_Click(object sender, EventArgs e)
 {
     tpState         = TilePlacingState.wood;
     lblPlacing.Text = "Placing: Wood";
 }