private void button3_Click(object sender, EventArgs e) { if (pawn != null && finish != null) { map.setMazeDesign(mazebound); map.lookforchar(); Node mulai = new Node(); mulai.node = new Point(pawn.posx, pawn.posy); Node selesai = new Node(); selesai.node = new Point(finish.posx, finish.posy); AStar a = new AStar(mulai, selesai); if (a.AlgoritmaAStar(map.mazeDesign, map.mapheight, map.mapwidth)) { MessageBox.Show("Mencari petunjuk...."); //drawNodePencarian(a); a.testOutput(); drawNodeJalur(a); MessageBox.Show("Alhamdulillah,... Akhirnya aku menemukan jalan keluar T-T!!!"); pawn = letakkanPawn(pawn, pawn_x, pawn_y, 's'); finish = letakkanPawn(finish, finish_x, finish_y, 'f'); } else { MessageBox.Show("Astagfirullah,... Yang buat maze kejam, aku gak dikasih jalan keluar T-T", "Peringatan!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } else { MessageBox.Show("Hayoo, lupa input start sama finish ya?", "Peringatan!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } //map.lookforchar(); }
private MainChar letakkanPawn(MainChar comp, NumericUpDown numx, NumericUpDown numy, char sign) { comp = hapusPawn(comp); comp = new MainChar(); comp.posx = (int)numx.Value; comp.posy = (int)numy.Value; for (int i = 0; i < map.mapheight; i++) { for (int j = 0; j < map.mapwidth; j++) { if (i == comp.posx && j == comp.posy) { mazebound[i, j].BackColor = Color.White; if (sign == 's') { mazebound[i, j].BackgroundImage = Properties.Resources.Image1; mazebound[i, j].BackColor = Color.Transparent; } else if (sign == 'f') { mazebound[i, j].BackgroundImage = Properties.Resources.Image31; mazebound[i, j].BackColor = Color.Yellow; } } } } return(comp); }
private MainChar hapusPawn(MainChar comp) { if (comp != null) { for (int i = 0; i < map.mapheight; i++) { for (int j = 0; j < map.mapwidth; j++) { if (i == comp.posx && j == comp.posy) { mazebound[i, j].BackColor = Color.White; mazebound[i, j].BackgroundImage = null; } } } } return(comp); }
private void loadButton_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Map Files (.map)|*.map"; openFileDialog1.FilterIndex = 1; openFileDialog1.Multiselect = false; DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog. if (result == DialogResult.OK) // Test result. { loadname.Text = openFileDialog1.FileName; SaveandLoad sv = new SaveandLoad(); map = sv.Deserialize(openFileDialog1.FileName); if (map != null) { pawn_x.Value = map.pawn.posx; pawn_y.Value = map.pawn.posy; finish_x.Value = map.finish.posx; finish_y.Value = map.finish.posy; width.Value = map.mapwidth; height.Value = map.mapheight; pawn = map.pawn; finish = map.finish; //mazebound = new PictureBox[map.mapheight, map.mapwidth]; this.pawn = map.pawn; this.finish = map.finish; reset(); this.Refresh(); mazebound = new PictureBox[map.mapheight, map.mapwidth]; getBlankMazeInterface(); enablePawn(groupBox2, pawn_x, pawn_y, width, height); enablePawn(groupBox4, finish_x, finish_y, width, height); } else { MessageBox.Show("Maaf, terjadi kesalahan!"); } } Console.WriteLine(result); // <-- For debugging use. }
private void button2_Click(object sender, EventArgs e) { pawn = letakkanPawn(pawn, pawn_x, pawn_y, 's'); }