コード例 #1
0
ファイル: MapResize.cs プロジェクト: E1Elite/MapResize
        private void btnReadMap_Click(object sender, EventArgs e)
        {
            MapParser parser    = new MapParser();
            string    sizeValue = parser.GetMapSize(tbFilename.Text.Trim());

            tbCurrentSize.Text = "";
            if (!String.IsNullOrEmpty(sizeValue))
            {
                if (sizeValue.Contains("|"))
                {
                    int      width  = -1;
                    int      height = -1;
                    int      wNew   = -1;
                    int      hNew   = -1;
                    string[] parts  = sizeValue.Split('|');
                    if (parts.Length >= 2 && parts[0] != null && parts[1] != null)
                    {
                        int.TryParse(parts[0], out width);
                        int.TryParse(parts[1], out height);
                    }
                    sizeValue  = "Filename: " + Path.GetFileName(tbFilename.Text) + "\r\n";
                    sizeValue += "Current size: " + width + "x" + height + "\r\n";
                    wNew       = width + (int)numLeft.Value + (int)numRight.Value;
                    hNew       = height + (int)numTop.Value + (int)numBottom.Value;
                    sizeValue += "Expected new size: " + wNew + "x" + hNew + "\r\n";
                    if (wNew > 511 || hNew > 511)
                    {
                        sizeValue += "Max size limit of W or H is 511\r\n";
                    }
                    else if (wNew + hNew > 512)
                    {
                        sizeValue += "Max size game limit W+H=512\r\n";
                    }
                    if (wNew < 0 || hNew < 0)
                    {
                        sizeValue += "Map size in negative\r\n";
                    }
                    else if ((wNew * 2 - 1) * hNew < 780)
                    {
                        sizeValue += "Map size too small\r\n";
                    }
                }
                tbCurrentSize.Text += sizeValue;
            }
        }