1. Trang chủ
  2. » Công Nghệ Thông Tin

Các mẫu thiết kế hướng ₫ối tượngbai 8 1

17 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Microsoft Word Bai 8 1 docx Trang 1 MÔN CÁC MẪU THIẾT KẾ HỚNG ỐI TỢNG Bài thực hành số 8 1 Viết chng trình son tho mê cung I Mục tiêu  Giúp SV làm quen cách viết chng trình có kh nng tng[.]

Trang MÔN : CÁC MẪU THIẾT KẾ HỚNG ỐI TỢNG Bài thực hành số 8.1 : Viết chng trình son tho mê cung I Mục tiêu :  Giúp SV làm quen cách viết chng trình có kh nng tng tác trực quan với ngời dùng Giúp SV nắm vững cấu trúc mê cung mà s ợc dùng thực hành 9.1 II Nội dung : Mê cung ma trận chiều gồm nhiều hàng cột Giao hàng cột cell Cell chứa phần tử xác ịnh mê cung Trong này, ta giới hn dùng loi cell : cell trống cell mà ngời chi i qua; cell tờng cell mà ngời chi i qua; cell iểm cell mà ngời chi i qua i qua, ngời chi s tng ợc iểm tích lũy Trong thực hành 9.1, ta s sử dụng thuật tốn tiến hóa ã viết thực hành 5.1 ể tìm ờng i tha mãn iều kiện : số bớc i xác ịnh, n nhiều iểm có Nội dung thực hành viết cng trình cho phép ngời dùng son tho mê cung ể có thễ dùng li thực hành 9.1 Chng trình gồm form chứa : - menu bar chứa menu pop-up Menu pop-up chứa option yếu : Load file mê cung Lu file mê cung - Panel chứa mê cung cần son tho, ể n gin ta qui ịnh kích thớc mê cung theo chuẩn 20 x 20 cell - Danh sách loi cell cần son : cell trống, cell iểm, cell tờng ể ngời dùng chọn thời iểm Form có dng nh sau : III Chuẩn ầu :  Nắm vững cách viết chng trình có kh nng tng tác trực quan với ngời dùng IV Qui trình xây dựng chng trình Dùng chng trình Paint ể son hình bitmap miêu t loi cell ợc dùng mê cung Chọn kích thớc 30x30 pixels Lu hình lên file bitmap th mục xác ịnh Nhớ vị trí th mục ể bớc sau dùng li file nh Chy VS Net, chọn menu File.New.Project ể hiển thị cửa sổ New Project Mở rộng mục Visual C# TreeView "Project Types", chọn mục Window, chọn icon "Windows Form Application" listbox "Templates" bên phi, thiết lập th mục chứa Project listbox "Location", nhập tên Project vào Trang textbox "Name:" (td BaiTH81), click button OK ể to Project theo thông số ã khai báo Form ầu tiên ứng dụng ã hiển thị cửa sổ thiết kế, việc thiết kế form trình lặp thao tác to mới/xóa/hiệu chỉnh thuộc tính/to hàm xử lý kiện cho ối tợng cần dùng form Do nội dung form ợc hiển thị ộng nên ta không thiết kế trực quan ợc, ó ta viết code ể hiển thị ộng form Vào cửa sổ son code cho form thêm on code sau vào hàm khởi ộng form : public Form1() { InitializeComponent(); //to ối tợng qun lý assembly System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); //to ối tợng Stream miêu t nh bitmap Stream myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.dot.bmp"); //to ối tợng nh bitmap cho cell dot dotbm = new Bitmap(myStream); //to ối tợng nh bitmap cho cell space myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.space.bmp"); spacebm = new Bitmap(myStream); //to ối tợng nh bitmap cho cell space myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.wall.bmp"); wallbm = new Bitmap(myStream); this.ClientSize = new Size(COLS * CSIZE+300,ROWS * CSIZE); this.MouseDown += new MouseEventHandler(Frm_MouseDown); //tiêu ề form this.Text = "Laby Builder"; //to mê cung laby = new Labyrinth(ROWS, COLS); //to Panel menu CreateCenterPanel(); CreateMenus(); }  Dời chuột ầu class Form1 thêm lệnh ịnh nghĩa sau : //ịnh nghĩa cần dùng private const long serialVersionUID = 1L; private const String SER_EXPORT_MENU = "Save labyrinth"; private const String SER_IMPORT_MENU = "Load labyrinth"; private const int ROWS = 20, COLS = 20; private const int CSIZE = 30; private Bitmap dotbm, spacebm, wallbm; //vùng chứa buttons Trang private Panel sidePanel; //mê cung cần hiển thị private Labyrinth laby; private LabyItem actionChoosed = LabyItem.WALL; // Pour les tests getSource dans le Menu Listener : les sources d'événements menu private MenuItem mi_export; private MenuItem mi_import; //vùng hiển thị mê cung private LabyPanel centerPanel; private int xl, yl; //hàm to menu private void CreateMenus() { //to option phục vụ thực tác vụ Export/Import mê cung mi_export = new MenuItem(SER_EXPORT_MENU, Export_Click); mi_import = new MenuItem(SER_IMPORT_MENU, Import_Click); MenuItem[] fmItems = new MenuItem[2]; fmItems[0] = mi_export; fmItems[1] = mi_import; //to menu File add vào menu bar; MenuItem fmenu = new MenuItem("File", fmItems); //to menu bar cho form MenuItem[] mbItems = new MenuItem[1]; mbItems[0] = fmenu; MainMenu mainMenu = new MainMenu(mbItems); this.Menu = mainMenu; } //tác vụ v mặt giao diện Button protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; int xl = ClientSize.Width - 260; int yl = 20; //xuất chuỗi hớng dẫn //to ối tợng font chữ cần dùng Font myFont = new Font("BKHelvetica", 10); //to biến miêu t chế ộ canh xuất chuỗi StringFormat format1 = new StringFormat(StringFormatFlags.NoClip); format1.Alignment = StringAlignment.Near; Brush brush = System.Drawing.Brushes.Black; //xuất chuỗi miêu t giờ/phút/giây g.DrawString("Click chọn mẫu cell cần dùng", myFont, brush, xl, yl, format1); yl += 20; g.DrawString("Rồi Click vào cell cần son", myFont, brush, xl, yl, format1); yl += 20; g.DrawString("ể son cell theo mẫu chọn.", myFont, brush, xl, yl, format1); Trang yl += 30; //to Button chức nng g.DrawImage(spacebm, xl, yl); g.DrawImage(dotbm, xl + CSIZE + 20, yl); g.DrawImage(wallbm, xl + * (CSIZE + 20), yl); //lu vị trí icon mẫu cell this.xl = xl; this.yl = yl; yl += 50; g.DrawString("Mẫu cell ang chọn:", myFont, brush, xl, yl, format1); yl += 25; Bitmap bm = null; switch (actionChoosed) { case LabyItem.NULL: bm = spacebm; break; case LabyItem.POINT: bm = dotbm; break; case LabyItem.WALL: bm = wallbm; break; } g.DrawImage(bm, xl, yl); } private void Frm_MouseDown(object sender, MouseEventArgs e) { //xác ịnh vị trí chuột hành //Point mousePos = Control.MousePosition; if (e.X < xl) return; if (e.Y < yl) return; if (e.Y > yl + CSIZE) return; //tính tọa ộ luận lý chuột ợc click int c = (e.X - xl) / (CSIZE + 20); if (c > 2) return; switch (c) { case 0: actionChoosed = LabyItem.NULL; break; case 1: actionChoosed = LabyItem.POINT; break; case 2: actionChoosed = LabyItem.WALL; break; } centerPanel.ActionSelected = actionChoosed; //v li panel mê cung // Refresh(); Rectangle rc = new Rectangle(); rc.Location = new Point(xl, 20); rc.Size = new Size(150, 500); Invalidate(rc); } //hàm xử lý option Export Trang private void Export_Click(object sender, EventArgs e) { exportMazeData(); } //hàm xử lý option Import private void Import_Click(object sender, EventArgs e) { chargerLabyrinthe(); } //hàm to Panel private void CreateCenterPanel() { centerPanel = new LabyPanel(laby); Controls.Add(centerPanel); } public static DialogResult InputBox(string title, string promptText, ref string value) { Form form = new Form(); Label label = new Label(); TextBox textBox = new TextBox(); Button buttonOk = new Button(); Button buttonCancel = new Button(); form.Text = title; label.Text = promptText; textBox.Text = value; buttonOk.Text = "OK"; buttonCancel.Text = "Cancel"; buttonOk.DialogResult = DialogResult.OK; buttonCancel.DialogResult = DialogResult.Cancel; label.SetBounds(9, 20, 372, 13); textBox.SetBounds(12, 36, 372, 20); buttonOk.SetBounds(228, 72, 75, 23); buttonCancel.SetBounds(309, 72, 75, 23); label.AutoSize = true; textBox.Anchor = textBox.Anchor | AnchorStyles.Right; buttonOk.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; form.ClientSize = new Size(396, 107); form.Controls.AddRange(new Control[] { label, textBox, buttonOk, buttonCancel }); form.ClientSize = new Size(Math.Max(300, label.Right + 10), form.ClientSize.Height); Trang form.FormBorderStyle = FormBorderStyle.FixedDialog; form.StartPosition = FormStartPosition.CenterScreen; form.MinimizeBox = false; form.MaximizeBox = false; form.AcceptButton = buttonOk; form.CancelButton = buttonCancel; DialogResult dialogResult = form.ShowDialog(); value = textBox.Text; return dialogResult; } //lu mê cung lên file public void exportMazeData() { //thiết lập chế ộ cập nhật centerPanel.modifLaby(); String fileName = null; InputBox("Nhập tên file : ", "Nhập tên file cần ghi", ref fileName); LabyrinthLoader.Save_Labyrinth(fileName, laby); } //np mê cung từ file public void chargerLabyrinthe() { //to form duyệt chọn file cần ọc OpenFileDialog dlg = new OpenFileDialog(); //hiển thị form duyệt chọn file cần ọc DialogResult ret = dlg.ShowDialog(); //kiểm tra ịnh ngời dùng, ngời dùng chọn OK ọc if (ret != DialogResult.OK) return; try { laby = LabyrinthLoader.Load_Labyrinth(dlg.FileName); } catch (IOException e) { MessageBox.Show("Không ọc ợc file " + dlg.FileName); return; } catch (LabyFaultEntourException e) { laby.EntourofWalls(); } catch (BeginCellNotNullException e) { laby.setContenuCase(1, 1, LabyItem.NULL); Trang } catch (Exception e) { MessageBox.Show("Lỗi cha xác ịnh."); return; } centerPanel.setLaby(laby); } //lu mê cung file public void sauverLabyrintheEnXML() { centerPanel.modifLaby(); LabyrinthLoader.chargerLabyrintheEnXML("maze_xml.txt", laby); }  Lu ý thêm lệnh using sau vào ầu file mã nguồn ặc t Form1 ể sử dụng file ợc to bớc : using BaiTH81.EditLaby; Dời chuột phần tử gốc Project cửa sổ “Solution Explorer”, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.New Folder ể to folder ặt tên cho folder EditLaby Trong th mục này, ta s chứa file mã nguồn ợc to thực hành Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class LabyErrorException.cs, chọn button Add ể máy to class ây class miêu t loi lỗi Exception mà chng trình s dùng Viết code cho class nh sau : namespace BaiTH81.EditLaby { class LabyErrorException : Exception { //chỉ số version private const long serialVersionUID = 1L; public LabyErrorException(String message) : base(message) { } } } Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class BeginCellNotNullException.cs, chọn button Add ể máy to class ây class miêu t loi lỗi Exception mà chng trình s dùng Viết code cho class nh sau : namespace BaiTH81.EditLaby { class BeginCellNotNullException : LabyErrorException { // số version Trang private const long serialVersionUID = 1L; public BeginCellNotNullException(String message) : base(message) { } } }  Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class LabyFaultEntourException.cs, chọn button Add ể máy to class ây class miêu t loi lỗi Exception mà chng trình s dùng Viết code cho class nh sau : namespace BaiTH81.EditLaby { class LabyFaultEntourException : LabyErrorException { // số version private const long serialVersionUID = 1L; public LabyFaultEntourException(String message) : base(message) { } } } Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class LabyItem.cs, chọn button Add ể máy to class Viết code cho kiểu liệt kê nh sau : namespace BaiTH81.EditLaby { enum LabyItem { ANY, //cell joker NULL, //cell trống POINT, //cell iểm WALL, //cell tờng không i qua ợc AGENT //cell chứa ngời i } public enum Direction { UP, DOWN, LEFT, RIGHT, STOP } } 10 Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class LabyPanel.cs, chọn button Add ể máy to class Viết code cho class nh sau : using System.Windows.Forms; using System.Drawing; using System.IO; Trang namespace BaiTH81.EditLaby { class LabyPanel : Panel { private const int ROWS = 20, COLS = 20; private const int CSIZE = 30; // Serializable trivia private const long serialVersionUID = 1L; //ma trận cell mê cung ang hiệu chỉnh private Labyrinth laby; private LabyItem[,] Cells; private int hcnt, ccnt; //loi cell ang chọn private LabyItem actionSelected = LabyItem.NULL; private Bitmap agentbm, dotbm, spacebm, wallbm; protected bool edit_enable = true; private MyPoint npos, opos = new MyPoint(1, 1); //hàm copy nội dung mê cung public void setLaby(Labyrinth laby) { this.laby = laby; hcnt = laby.Ysize(); ccnt = laby.Xsize(); Cells = new LabyItem[hcnt, ccnt]; npos = null; for (int h = 0; h < hcnt; h++) for (int c = 0; c < ccnt; c++) { Cells[h, c] = laby.getContenuCase(h, c); if (Cells[h, c] == LabyItem.AGENT) npos = new MyPoint(h, c); } //v vị trí agent Refresh(); /*v li vị trí củ agent mê cung Rectangle rc = new Rectangle(); rc.Location = new Point(opos.x * CSIZE, opos.y * CSIZE); rc.Size = new Size(CSIZE, CSIZE); Invalidate(rc); if (npos != null) { opos = npos; rc.Location = new Point(opos.x * CSIZE, opos.y * CSIZE); rc.Size = new Size(CSIZE, CSIZE); Invalidate(rc); //ngủ chờ 1s //Thread.Sleep(500); }*/ } Trang 10 //hàm cập nhật li mê cung public void modifLaby() { for (int h = 0; h < hcnt; h++) { for (int c = 0; c < ccnt; c++) { laby.setContenuCase(h, c, Cells[h, c]); } } } public LabyItem ActionSelected { set { actionSelected = value; } } //hàm khởi to public LabyPanel(Labyrinth laby) { this.MouseDown += new MouseEventHandler(Frm_MouseDown); //this.Paint += new PaintEventHandler(OnPaint); //to ối tợng qun lý assembly System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly(); //to ối tợng Stream miêu t nh bitmap Stream myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.dot.bmp"); //to ối tợng nh bitmap cho cell dot dotbm = new Bitmap(myStream); //to ối tợng nh bitmap cho cell space myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.space.bmp"); spacebm = new Bitmap(myStream); //to ối tợng nh bitmap cho cell space myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.wall.bmp"); wallbm = new Bitmap(myStream); //to ối tợng nh bitmap cho cell space myStream = myAssembly.GetManifestResourceStream("BaiTH91.Resources.agent.jpg"); agentbm = new Bitmap(myStream); setLaby(laby); this.ClientSize = new Size(ccnt * CSIZE, hcnt * CSIZE); // v li mê cung Refresh(); Trang 11 } //tác vụ v mặt giao diện Button protected override void OnPaint(PaintEventArgs e) { Graphics g = e.Graphics; int h, c; for (h = 0; h < hcnt; h++) for (c = 0; c < ccnt; c++) { Bitmap bm = null; switch (Cells[h, c]) { case LabyItem.NULL: bm = spacebm; break; case LabyItem.POINT: bm = dotbm; break; case LabyItem.WALL: bm = wallbm; break; case LabyItem.AGENT: bm = agentbm; break; } g.DrawImage(bm, c * CSIZE, h * CSIZE); } } private void Frm_MouseDown(object sender, MouseEventArgs e) { if (!edit_enable) return; //tính tọa ộ cell mà user vừa chọn int c = e.X / CSIZE; int h = e.Y / CSIZE; //thiết lập nội dung cho cell Cells[h, c] = actionSelected; //v li panel mê cung //v li panel mê cung Rectangle rc = new Rectangle(); rc.Location = new Point(c * CSIZE, h * CSIZE); rc.Size = new Size(CSIZE, CSIZE); Invalidate(rc); } } }  11 Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class Labyrinth.cs, chọn button Add ể máy to class Viết code cho class nh sau : namespace BaiTH81.EditLaby { [Serializable] Trang 12 class Labyrinth { //chỉ số version ể phục vụ việc ọc/ghi mê cung private const long serialVersionUID = 1L; //kích thớc mê cung int width, height; //ma trận cell mê cung private LabyItem[,] carte; //hàm khởi to mê cung cách ngẫu nhiên public Labyrinth(int width, int height) { this.width = width; this.height = height; carte = new LabyItem[width, height]; for (int h = 0; h < height; h++) { for (int c = 0; c < width; c++) carte[h, c] = LabyItem.WALL; /*{ if (i == || j == || i == width - || j == height - 1) carte[i,j] = LabyItem.MUR; else carte[i,j] = LabyItem.POINT; }*/ } } //hàm khởi to mê cung theo nội dung ã có private Labyrinth(LabyItem[,] copy) { carte = copy; height = copy.GetLength(0); width = copy.GetLength(1); } //hàm tr ộ rộng public int Xsize() { return width; } //hàm tr ộ cao public int Ysize() { return height; } Trang 13 //hàm tr cell p public LabyItem getContenuCase(MyPoint p) { return getContenuCase(p.y, p.x); } //hàm tr cell vị trí x,y public LabyItem getContenuCase(int y, int x) { return carte[y, x]; } //hàm thiết lập nội dung cell p public void setContenuCase(MyPoint p, LabyItem element) { setContenuCase(p.y, p.x, element); } //hàm thiết lập nội dung cell vị trí x,y public void setContenuCase(int y, int x, LabyItem element) { carte[y, x] = element; } //hàm tính số cell point public int getNbPoints() { int nbPoints = 0; int h, c; //lặp hàng for (h = 0; h < height; h++) { //lặp cột for (c = 0; c < width; c++) { if (carte[h, c] == LabyItem.POINT) nbPoints++; } } return nbPoints; } //hàm gii mã mê cung thành chuỗi vn bn public override String ToString() { return "Mê cung chứa " + getNbPoints() + " cell Point"; } Trang 14 //kiểm tra xem mê cung ợc tờng bao quanh hết không public bool isEntourofWalls() { //duyệt hàng for (int h = 0; h < height; h++) { if (carte[h, width - 1] != LabyItem.WALL) return false; if (carte[h, 0] != LabyItem.WALL) return false; } for (int c = 0; c < width; c++) { if (carte[0, c] != LabyItem.WALL) return false; if (carte[height - 1, c] != LabyItem.WALL) return false; } return true; } //hàm bao tờng khép kín cho mê cung public void EntourofWalls() { int h, c; for (h = 0; h < height; h++) { carte[h, width - 1] = LabyItem.WALL; carte[h, 0] = LabyItem.WALL; } for (c = 0; c < width; c++) { carte[0, c] = LabyItem.WALL; carte[height - 1, c] = LabyItem.WALL; } } //hàm nhân bn vơ tính ối tợng public Labyrinth clone() { LabyItem[,] copy = new LabyItem[height, width]; for (int h = 0; h < height; h++) for (int c = 0; c < width; c++) copy[h, c] = carte[h, c]; return new Labyrinth(copy); } } }  Trang 15 12 Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class Labyrinth.cs, chọn button Add ể máy to class Viết code cho class nh sau : using System.IO; using System.Runtime.Serialization; using System.Runtime.Serialization.Formatters.Binary; namespace BaiTH81.EditLaby { class LabyrinthLoader { //hàm ọc mê cung từ file nhị phân public static Labyrinth Load_Labyrinth(String fileName) { //ịnh nghĩa ối tợng FileStream miêu t file chứa liệu ã có FileStream fs = new FileStream(fileName, FileMode.Open); //to ối tợng BinaryFormatter phục vụ ọc ối tợng BinaryFormatter formatter = new BinaryFormatter(); //gọi tác vụ Deserialize ể ọc ối tợng từ file vào try { Labyrinth laby = (Labyrinth)formatter.Deserialize(fs); if (!laby.isEntourofWalls()) throw new LabyFaultEntourException("Thiếu tờng bao."); if (laby.getContenuCase(1, 1) == LabyItem.WALL) throw new BeginCellNotNullException("Tờng nằm vị trí xuất phát."); fs.Close(); return laby; } catch (InvalidCastException e) { throw new IOException( "File chứa nội dung không hợp lệ : phi mê cung ã ợc ghi trớc từ máy tính", e); } catch (TypeLoadException e) { throw new IOException( ".NET kiểu mê cung", e); } } //hàm ghi mê cung file nhị phân public static void Save_Labyrinth(String fileName, Labyrinth maze) { //ịnh nghĩa ối tợng FileStream miêu t file chứa kết qu FileStream fs = new FileStream(fileName, FileMode.Create); //to ối tợng BinaryFormatter phục vụ ghi ối tợng Trang 16 BinaryFormatter formatter = new BinaryFormatter(); //gọi tác vụ Serialize formatter ể ghi ối tợng lên file tng ứng formatter.Serialize(fs, maze); fs.Close(); } //hàm ọc mê cung từ file XML public static void chargerLabyrintheEnXML() { throw new Exception(); } //hàm ghi mê cung file XML public static void chargerLabyrintheEnXML(String fileName, Labyrinth maze) { // to ối tợng phục vụ ghi file vn bn StreamWriter writer = new StreamWriter(fileName, false, Encoding.Unicode); writer.WriteLine(""); for (int i = 0; i < maze.Xsize(); i++) { writer.Write(""); for (int j = 0; j < maze.Ysize(); j++) { writer.WriteLine(" " + maze.getContenuCase(i, j) + ""); } writer.WriteLine(""); } writer.WriteLine(""); writer.Close(); } } }  13 Dời chuột folder EditLaby, ấn phi chuột vào ể hiển thị menu lệnh, chọn chức nng Add.Class ể hiển thị cửa sổ “Add New Item”, chọn mục “Class”, hiệu chỉnh tên class MyPoint.cs, chọn button Add ể máy to class Viết code cho class nh sau : namespace BaiTH81.EditLaby { class MyPoint { public int x; public int y; public MyPoint(int y, int x) { this.x = x; this.y = y; Trang 17 } } } 14 Ấn phi chuột vào phần tử gốc Project cửa sổ Solution Explorer, chọn option Add.New Folder ể thêm folder với tên Resources, ta s dùng folder chứa file bitmap ợc dùng chng trình 15 Ấn phi chuột vào folder Resources, chọn option Existing Items, duyệt chọn file bitmap son bớc ể add chúng vào folder Resources 16 Chọn mục vừa add vào folder Resources ể hiển thị cửa sổ thuộc tính chúng, hiệu chỉnh li thuộc tính Build Action giá trị "Embedded Resource" 17 Dịch chy chng trình Nếu có lỗi sửa, hết lỗi chng trình s chy Hãy son thử mê cung theo sở thích lu lên file ể dùng li cho 9.1    

Ngày đăng: 09/04/2023, 06:14

Xem thêm: