0

This is what i have decided to start with a winForm & 1 button called btnCreate and I have 2 images 35px X 35px floor.bmp and wall.bmp

public partial class Form1 : Form
{
    int x;
    int y;
    int[] Row0 = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
    int[] Row1 = new int[10] { 1, 1, 1, 1, 0, 0, 1, 1, 0, 1 };
    int[] Row2 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row3 = new int[10] { 1, 1, 1, 1, 0, 1, 1, 1, 0, 1 };
    int[] Row4 = new int[10] { 1, 0, 0, 1, 0, 1, 0, 0, 0, 1 };
    int[] Row5 = new int[10] { 1, 0, 0, 1, 0, 0, 0, 1, 0, 1 };
    int[] Row6 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row7 = new int[10] { 1, 1, 1, 1, 0, 0, 1, 1, 0, 1 };
    int[] Row8 = new int[10] { 1, 1, 0, 0, 0, 0, 1, 1, 0, 1 };
    int[] Row9 = new int[10] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
    int[,] LevelA = new int[10,10];

    private void Form1_Load(object sender, EventArgs e)
    {
        for (x = 0; x < 10; x++)
        {
            //load all arrays 
            LevelA[0, x] = Row0[x];
            LevelA[1, x] = Row1[x];
            LevelA[2, x] = Row2[x];
            LevelA[3, x] = Row3[x];
            LevelA[4, x] = Row4[x];
            LevelA[5, x] = Row5[x];
            LevelA[6, x] = Row6[x];
            LevelA[7, x] = Row7[x];
            LevelA[8, x] = Row8[x];
            LevelA[9, x] = Row9[x];
        }
    }

    private void btnCreate_Click(object sender, EventArgs e)
    {
        for (int X = 0; X < 10; X++)
        {
            for (int Y = 0; Y < 10; Y++)
            {
                //the following is the idea of what I would like to accomplish
                //if (LevelA[Y,X] == 0)
                //{
                    //Bitmap myBmp = new Bitmap(Image.FromFile(@"C:\My Documents\floor2.bmp"));
                    //myBmp.Top == Y * 35;
                    //myBmp.left == X * 35;
                //}
            }
        }
    }
}

Would the CODE above work as I intend it too >? or would the end of the for-loop only display the last tile as it would keep replacing(destroying) the previous one with a new one? In witch case I would need to have 100 myBmp's for a 10 by 10 grid?

4

1 回答 1

0

Bitmap您可以通过创建对象来获取图像文件的位图。

 Bitmap bmp = new Bitmap(Image.FromFile(@"D:\MyImageFile.bmp"));

只要您掌握了Graphics实例,就可以将其放置或绘制在任何地方。你可以在这里找到一个简单的例子。

于 2013-03-04T06:54:16.187 回答