private void FillInGroupBox(Map map) { CurrentMap = map; CurrentMap.SetPackMan(); this.GroupBox.Controls.Add(map.Pacman); Level level = Level.Low; if (SelectLevelCb.SelectedItem != null) { Enum.TryParse(SelectLevelCb.SelectedItem.ToString(), out level); } Enemy enemyAI1 = new Enemy(map.Pacman, EnemyType.Chasing, new Point(540, 300), level); GroupBox.Controls.Add(enemyAI1); Enemy enemyAI2 = new Enemy(map.Pacman, EnemyType.Chasing, new Point(140, 300), level); GroupBox.Controls.Add(enemyAI2); Enemy enemyRandom = new Enemy(map.Pacman, EnemyType.Scatter, new Point(140, 300), level); GroupBox.Controls.Add(enemyRandom); Enemy enemyRandom2 = new Enemy(map.Pacman, EnemyType.Scatter, new Point(540, 500), level); GroupBox.Controls.Add(enemyRandom2); this.GroupBox.Controls.Add(new Block(20, 20, map.Entrance) { BackColor = Color.DarkGray }); this.GroupBox.Controls.Add(new Block(20, 20, map.Exit) { BackColor = Color.Green }); foreach (var block in map.Blocks) { this.GroupBox.Controls.Add(block); } foreach (var dot in map.Dots) { this.GroupBox.Controls.Add(dot); } }
public static void AddNewDot(string line, Map map, ref int pos) { string[] dots = line.Split(','); if (dots.Count() == 2) { int x = Convert.ToInt32(dots[0]); int y = Convert.ToInt32(dots[1]); map.Dots[pos] = (new Dots() { Location = Controls.Dots.Loc(x, y) }); pos++; } }
public static void AddNewBlock(string line, Map map, ref int pos) { string[] dots = line.Split(','); if (dots.Count() == 4) { int width = Convert.ToInt32(dots[0]); int height = Convert.ToInt32(dots[1]); int x = Convert.ToInt32(dots[2]); int y = Convert.ToInt32(dots[3]); if (pos < 4) { map.Blocks[pos] = (new Block(width, height, new Point(x, y))); } map.Blocks[pos] = (Block.SetBlockProp(width, height, x, y)); pos++; } }
void pack_Pacman_Messages(object sender, string messages) { MessageBox.Show(messages); CurrentMap = null; MapsList.LoadMaps(); }
private void LoadMapElements() { if (selectMapMenuItem.SelectedItem==null) { CurrentMap = MapsList.GetMaps[0]; FillInGroupBox(CurrentMap); return; } foreach (var map in MapsList.GetMaps) { if (string.Equals(selectMapMenuItem.SelectedItem, map.Name)) { FillInGroupBox(map); } } }
private static Map AddNewMap(string file) { Map map = new Map { Name = file.Split('\\').Last() }; try { using (StreamReader reader = new StreamReader(file)) { // to set array position int positionBlock = 0; int positionDot = 0; string line; bool isBlocks = true; var In = reader.ReadLine(); var Out = reader.ReadLine(); if (!string.IsNullOrWhiteSpace(In) && !string.IsNullOrWhiteSpace(Out) && In.Contains("#") && Out.Contains("#")) { In = In.Replace('#', ' '); Out = Out.Replace('#', ' '); string[] inp = In.Split(','); string[] outp = Out.Split(','); map.Entrance.X = Convert.ToInt32(inp[0]) * Step; map.Entrance.Y = Convert.ToInt32(inp[1]) * Step; map.Exit.X = Convert.ToInt32(outp[0]) * Step; map.Exit.Y = Convert.ToInt32(outp[1]) * Step; } while ((line = reader.ReadLine()) != null) { if (line.Contains('-')) { isBlocks = false; continue; } if (isBlocks) { AddNewBlock(line, map, ref positionBlock); } else { AddNewDot(line, map, ref positionDot); } } return map; } } catch (Exception) { return map; //throw; } return null; }
public static void Add(Map map) { _maps.Add(map); }