public void CreateTest(string name) { if (name == "Whistle") { Assert.True(new SuperFactory().Create(name) is WhistleFactory, "ok"); } if (name == "Wheel") { var fac = new SuperFactory().Create(name); Assert.True(fac is WheelFactory, "ok"); fac.Wheel("TaxiWheel").Wheel(); } if (name == "Is Null") { try { new SuperFactory().Create(name); } catch (Exception ex) { Assert.True(ex.Message == "fail", "创建失败"); } } }
private static void DFSDestroyWS(short x, short z, ref Node pathroot, Rectangle[] ignore = null) { Stack <Node[]> stack = new Stack <Node[]>(); stack.Push(new Node[] { pathroot = new Node(new Vector3(x, 0, z)), null }); while (stack.Count > 0) { Node[] data = stack.Pop(); int validwallcodes = SuperFactory.GetFactory <Wall>().AvailableTypes - 1; x = (short)data[0].Value.X; z = (short)data[0].Value.Z; if (visited[x, z]) { continue; } visited[x, z] = true; if (data[1] != null) // For first time { data[0].Neighbours.Add(data[1]); data[1].Neighbours.Add(data[0]); if (x == data[1].Value.X) // Vertically aligned cells { walls[0, x, Math.Max(z, (short)data[1].Value.Z)] = 0xFF; // Remove horizontal wall between them walls[1, x, z] = (byte)ran.Next(0, validwallcodes); // Randomize left wall type } else if (z == data[1].Value.Z) // Horizontally aligend cells { walls[1, Math.Max(x, (short)data[1].Value.X), z] = 0xFF; // Remove vertical wall between them walls[0, x, z] = (byte)ran.Next(0, validwallcodes); // Randomize top wall type } } short startdir = (short)ran.Next(0, 4); short sign = (short)(ran.Next(99) > 49 ? 1 : -1); for (short i = 0; i < 4; i++) { // +4 to compensate for counter clock wise rotation. %4 to stay in range short dir = (short)((4 + startdir + sign * i) % 4); short tx = (short)(x + (dir == 1 ? 1 : dir == 3 ? -1 : 0)); short tz = (short)(z + (dir == 2 ? 1 : dir == 0 ? -1 : 0)); // More overhead checking here means less memory usage if (tx >= 0 && tz >= 0 && tx < visited.GetLength(0) && tz < visited.GetLength(1) && // Check whether target is inside workarea !visited[tx, tz] && // Check if already visited (ignore == null || Array.TrueForAll(ignore, r => !r.Contains(tx, tz)))) // Finally, make sure it's not in an ignored area { stack.Push(new Node[] { new Node(new Vector3(tx, 0, tz)), data[0] }); } } } }