private void btnOpen_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Chọn ảnh map"; ofd.Filter = "Image files (*.jpg, *.jpeg, *.jpe, *.jfif, *.png) | *.jpg; *.jpeg; *.jpe; *.jfif; *.png"; ofd.InitialDirectory = @"C:\Users\dell\Desktop\"; if (ofd.ShowDialog() == DialogResult.OK) { MyLogger.getInstance().logDebug("Open map ------------------------------------------"); String fileName = ofd.FileName.Split('.')[0]; Bitmap background = context.open(fileName); background.MakeTransparent(Color.FromArgb(255, 0, 255)); this.width_map = background.Width; this.height_map = background.Height; this.bmp_map = new Bitmap(background); int count_horizontal = this.width_map / 16; int count_vertical = this.height_map / 16; this.bmp_map = new Bitmap(background); Bitmap _bmp = CreateMapSquare(background); using (Graphics g = Graphics.FromImage(_bmp)) { for (int row = 0; row < count_vertical; row++) { for (int col = 0; col < count_horizontal; col++) { g.DrawLine(Pens.Red, new Point(col * 16, 0), new Point(col * 16, this.height_map)); } g.DrawLine(Pens.Red, new Point(0, row * 16), new Point(this.width_map, row * 16)); } } picMap.SizeMode = PictureBoxSizeMode.AutoSize; picMap.Image = _bmp; background = _bmp; RecObject recobj = new RecObject(); recobj.parse(fileName + "recs.txt"); this.recs.AddRange(recobj.Recs); EnemyObj enemyObj = new EnemyObj(); enemyObj.parse(fileName + "enemy.txt"); this.enemies.AddRange(enemyObj.Enemies); foreach (ObjGame obj in enemyObj.Enemies) { ObjDTO objDTO = new ObjDTO(obj, folderDefault + "enemy/" + obj.Name + ".png"); pushObjGame(obj.X, obj.Y, objDTO); } } }
public Enemy(String fileName) { objDefault = new EnemyObj(); objDefault.parse(fileName); this.X = objDefault.X; this.Y = objDefault.Y; this.Width = objDefault.Width; this.Height = objDefault.Height; this.Type = objDefault.Type; this.Name = objDefault.Name; }