public double GetValue(Path path) { if (path == null) throw new ArgumentNullException("path"); Value value = GetPacket(path) as Value; if (value == null) throw new InvalidOperationException(string.Format("Packet \"{0}\" does not have a valid value at path \"{1}\".", this, path)); return value; }
public Packet GetPacket(Path path) { if (path == null) throw new ArgumentNullException("path"); if (path.IsEmpty) return this; List list = GetPacket(path.Head) as List; int index = path.Tail; if (list == null || index < 0 || index >= list.Length) return new InvalidPacket(); return list[index]; }
public void PostReading() { byte[,]visit = new byte[Width, Height]; path_number = 0; paths = new List<Path>(); Path path; path_number++; path = new Path(path_number); path.Waypoints.Add(StartCell); visit[StartCell.tile_x, StartCell.tile_y] = path.id; DFS_Search(StartCell.tile_x, StartCell.tile_y, path, -1, visit); Random random = new Random(); for (int i = 0; i < Waves.Count;i++ ) { Waves[i].path_order = random.Next(Waves.Count); Waves[i].GrowRate = (i / Data.Wave.NUMBER_BETWEEN_GROW) * Data.Wave.BASE_GROW_RATE; } }
private void DFS_Search(int x, int y, Path path, int direct, byte[,] visit) { //Neu la cell cuoi if (EndCell.tile_x == x && EndCell.tile_y == y) { path.Waypoints.Add(new Cell(EndCell)); paths.Add(path); } int temp_x, temp_y; //int count = 0; //Du doan truoc bool is_turn_point = IsTurnPoint(x, y, direct); for (int i = 0; i < 4; i++) { //Chi xet cac huong khong nguoc voi huong da cho if (i + direct != 3) { temp_x = x + Direction.dx[i]; temp_y = y + Direction.dy[i]; if (InBound(temp_x,temp_y) && InteractiveMap[temp_y * Width + temp_x] == PATH ) { if (visit[temp_x, temp_y] <= path.id && path.IsPassedTurnpoint(temp_x,temp_y)){ return; } Path p; //count++; //if (count > 1) { path_number++; } if (is_turn_point) { path_number++; p = new Path(path_number, path); p.Turnpoints.Add(new Cell(x, y)); } else { p = path; } //Neu doi huong ma ko di thang if (direct != -1 && direct != i) { p.Waypoints.Add(new Cell(x, y)); } //Gan lai visit visit[temp_x,temp_y] = p.id; //Tiep tuc search voi o do DFS_Search(temp_x, temp_y, p, i, visit); } } } }
public abstract string GetName(Path path);
public Stream(XElement stream) { this.path = new Path(stream.Element(Path.XElementName)); this.Name = (string)stream.Element("Name"); this.entryData = new EntryData(stream.Element(EntryData.XElementName)); }
public Stream(Path path) : this(path, "Stream " + path) { }
public Stream(Path path, string name) { this.path = path; this.Name = name; this.entryData = new EntryData(); }
public Path(byte id, Path path) { this.id = id; Waypoints = new List<Cell>(path.Waypoints); Turnpoints = new List<Cell>(path.Turnpoints); }
static Stream ParseStream(Port port, string streamString) { string[] details = streamString.Split('='); switch (details.Length) { case 1: Path path = new Path(details[0]); string name = port.GetName(path); return name == null ? new Stream(path) : new Stream(path, name); case 2: return new Stream(new Path(details[0]), details[1]); default: throw new ArgumentException("streamString"); } }