public void Initialize(LabyrinthGenerator generator) { var dataSources = new List <string>() { "localhost", "192.168.2.101", "192.168.56.11", "192.168.56.13" }; Console.WriteLine(); Console.WriteLine("Select a MySQL database host:"); for (var i = 0; i < dataSources.Count; ++i) { Console.WriteLine(" {0}) {1}", i, dataSources[i]); } Console.Write("Enter your selection: "); var dataSourceIndexAsString = Console.ReadLine(); int dataSourceIndexAsInt; if (!int.TryParse(dataSourceIndexAsString, out dataSourceIndexAsInt) || dataSourceIndexAsInt < 0 || dataSourceIndexAsInt >= dataSources.Count) { throw new Exception("Unrecognized MySQL database host selection."); } Connect(string.Format("Database=labyrinth;Data Source={0};User Id=user;Password=tomtom7", dataSources[dataSourceIndexAsInt])); //CreateSchema(); InsertData(generator); }
public static Matrix Generate(int x, int y, float density) { LabyrinthGenerator generator = new LabyrinthGenerator(x, y); generator.Build(density); return generator.getMatrix(); }
public void InsertData(LabyrinthGenerator generator) { PreparedStatement statement = session.Prepare("INSERT INTO connections (level1, room1, level2, room2) VALUES (?, ?, ?, ?);"); foreach (var room1 in generator.connections.Keys) { foreach (var room2 in generator.connections[room1]) { /* * session.Execute(string.Format( * "INSERT INTO labyrinth.connections (level1, room1, level2, room2) VALUES ({0}, {1}, {2}, {3});", * room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); */ BoundStatement boundStatement = new BoundStatement(statement); session.Execute(boundStatement.Bind(room1.levelNumber, room1.roomNumber, room2.levelNumber, room2.roomNumber)); } } statement = session.Prepare("INSERT INTO books (level, room, name) VALUES (?, ?, ?);"); foreach (var room in generator.booksInRooms.Keys) { BoundStatement boundStatement = new BoundStatement(statement); session.Execute(boundStatement.Bind(room.levelNumber, room.roomNumber, generator.booksInRooms[room])); } Console.WriteLine("Cassandra: Data inserted."); }
void Start() { /*Vector3[] ring = CreateRing(); * * for(int i = 0; i < ring.Length; i++) * { * GameObject newGameObject = GameObject.CreatePrimitive(PrimitiveType.Cube); * newGameObject.transform.SetParent(transform); * newGameObject.transform.localPosition = ring[i]; * }*/ /*ring1 = mesh.AddArray(CreateRing(Vector3.zero)); * ring2 = mesh.AddArray(CreateRing(Vector3.forward)); * mesh.ConectRings(ring1, ring2);*/ GetComponent <MeshFilter>().sharedMesh = mesh.CreateMesh(); generatorInstance = LabyrinthGenerator.instance; scale = generatorInstance.scale; flower = Instantiate(flower); nextFlower = Instantiate(flower); positionInGrid = GridF.TransformPointToGrid(transform.position); GetSurroundings(); GetChains(); }
public void EndAndInitialPointAreDifferent(int width, int height) { var labyrinth = new LabyrinthGenerator(height, width); labyrinth.GenerateLabyrinth(); Assert.IsFalse(labyrinth.InitialPoint.Equals(labyrinth.EndPoint)); }
static void Main(string[] args) { try { // The third command-line parameter indicates how many extra connections should be added to the labyrinth // once it is a single blob. This will introduce cycles, which should make the labyrinth more challenging to navigate. var numberOfExtraConnections = 0; if (args.Length < 2 || args.Length > 3) { Console.WriteLine("Usage: Labyrinth.exe (NumberOfLevels) (NumberOfRoomsPerLevel) [NumberOfExtraConnections]"); return; } if (args.Length > 2) { numberOfExtraConnections = int.Parse(args[2]); } var storageType = GetStorageType(); var generator = new LabyrinthGenerator(int.Parse(args[0]), int.Parse(args[1]), numberOfExtraConnections); generator.Generate(); using (var client = CreateClient(storageType)) { generator.NavigateLabyrinth(client); } } catch (Exception ex) { Console.WriteLine("Caught {0}: {1}", ex.GetType().FullName, ex.Message); } }
public void StartGenerator_should(int width, int height, int expected) { var sampleLabyrinth = new LabyrinthGenerator(width, height); var example = new Cell(1, 1, CellTypes.Empty); Assert.AreEqual(expected, sampleLabyrinth.UnvisitedCells.Count); Assert.IsTrue(sampleLabyrinth.UnvisitedCells.Contains(example), "Sample start generator"); }
public void InsertData(LabyrinthGenerator generator) { //var batch = session.CreateBatch(); foreach (var room1x in generator.connections.Keys) { foreach (var room2x in generator.connections[room1x]) { var connectionEnt = new Connection() { id = Guid.NewGuid(), level1 = room1x.levelNumber, room1 = room1x.roomNumber, level2 = room2x.levelNumber, room2 = room2x.roomNumber }; //Console.WriteLine("InsertData: Adding the connection from ({0}, {1}) to ({2}, {3}).", // room1x.levelNumber, room1x.roomNumber, room2x.levelNumber, room2x.roomNumber); connectionTable.AddNew(connectionEnt); //batch.Append(connectionTable.Insert(connectionEnt)); //connectionTable.EnableQueryTracing(connectionEnt); } } labyrinthContext.SaveChanges(SaveChangesMode.Batch); //batch.Execute(); #if DEAD_CODE RowSet results = session.Execute("SELECT * FROM labyrinth_linq.\"Connection\";"); var verifiedRowCount = 0; foreach (var row in results.GetRows()) { Console.WriteLine("Verified insert: Connection from ({0}, {1}) to ({2}, {3}).", row.GetValue <int>("level1"), row.GetValue <int>("room1"), row.GetValue <int>("level2"), row.GetValue <int>("room2")); verifiedRowCount++; } Console.WriteLine("{0} rows verified as inserted.", verifiedRowCount); #endif foreach (var roomx in generator.booksInRooms.Keys) { var bookEnt = new Book() { id = Guid.NewGuid(), level = roomx.levelNumber, room = roomx.roomNumber, name = generator.booksInRooms[roomx] }; bookTable.AddNew(bookEnt); //bookTable.EnableQueryTracing(bookEnt); } labyrinthContext.SaveChanges(SaveChangesMode.Batch); Console.WriteLine("Cassandra Linq: Data inserted."); }
public void GetUnvisitedNeighbours_Should() { var labyrinth = new LabyrinthGenerator(7, 7); var neighboursMiddle = labyrinth.GetUnvisitedNeighbours(new Cell(3, 3, CellTypes.Empty)); var neighboursCorner = labyrinth.GetUnvisitedNeighbours(new Cell(1, 1, CellTypes.Empty)); Assert.AreEqual(4, neighboursMiddle.Length); Assert.AreEqual(2, neighboursCorner.Length); }
public MapController(int width, int height) { labyrinthGenerator = new LabyrinthGenerator(width, height); labyrinthGenerator.GenerateLabyrinth(); PlayerPosition = new Cell(InitialPoint.X, InitialPoint.Y, CellTypes.Player); Maze = labyrinthGenerator.ToArray(); IsEndReached = false; ExploreCells(); UpdateVisibleCells(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); LabyrinthGenerator labGen = (LabyrinthGenerator)target; if (GUILayout.Button("Generate Labyrinth")) { labGen.GenerateLabyrinthButton(); } }
void Awake() { instance = this; /* { * seed = seed.ToLower(); * int seedNumber = 0; * foreach (char character in seed) * { * seedNumber += character; * } * Random.InitState(seedNumber); * print(seedNumber); * } */ //if (mapTexture == null) seed = Game.seed; size = Game.size; GenerateTexture(); }
public void Initialize(LabyrinthGenerator generator_param) { generator = generator_param; }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); labyrinth = LabyrinthGenerator.GenerateLabyrinth(labyrinthName, this); SetContentView(Resource.Layout.Main); GridLayout layout = FindViewById <GridLayout>(Resource.Id.gridLayout1); LabyrinthViewGenerator.Generate(labyrinth, layout, this); heroImage = FindViewById <ImageView>(Resource.Id.imageView1); if (bundle != null) { time = bundle.GetInt("time"); iterator = bundle.GetInt("iterator"); heroImage.TranslationX = bundle.GetFloat("HeroPositionX"); var surfaceOrientation = WindowManager.DefaultDisplay.Rotation; if (surfaceOrientation == SurfaceOrientation.Rotation0 || surfaceOrientation == SurfaceOrientation.Rotation180) { heroImage.TranslationX += 350; } else { heroImage.TranslationX -= 350; } heroImage.TranslationY = bundle.GetFloat("HeroPositionY"); } else { var surfaceOrientation = WindowManager.DefaultDisplay.Rotation; if (surfaceOrientation == SurfaceOrientation.Rotation0 || surfaceOrientation == SurfaceOrientation.Rotation180) { heroImage.TranslationX = -460 + labyrinth.Start.XCoord * 150; } else { heroImage.TranslationX = -810 + labyrinth.Start.XCoord * 150; } heroImage.TranslationY = labyrinth.Start.YCoord * 150 + 40; } Hero hero = new Hero(labyrinth.Finish); hero.MoveToNextRoom(labyrinth.Start); List <Coordinates> journey = hero.journey; ValueAnimator animator = ValueAnimator.OfInt(0, 10); animator.SetDuration(1000 * journey.Count); animator.Update += (object sender, ValueAnimator.AnimatorUpdateEventArgs e) => { float shift = 15; if (iterator == journey.Count - 1) { return; } if (journey[iterator].X < journey[iterator + 1].X) { heroImage.TranslationX += shift; } if (journey[iterator].X > journey[iterator + 1].X) { heroImage.TranslationX -= shift; } if (journey[iterator].Y < journey[iterator + 1].Y) { heroImage.TranslationY += shift; } if (journey[iterator].Y > journey[iterator + 1].Y) { heroImage.TranslationY -= shift; } if (time++ > 8) { iterator++; time = 0; } }; animator.Start(); }
// Use this for initialization void Start() { gen = new LabyrinthGenerator(); gen.GenerateGrid(); }
public void Initialize(LabyrinthGenerator generator) { Connect("192.168.56.10"); CreateSchema(); InsertData(generator); }
public void Initialize(LabyrinthGenerator generator) { Connect(@"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL)));User Id=c##labyrinth;Password=tomtom7;"); //CreateSchema(); InsertData(generator); }
/// <summary> /// Generate new labyrinth level. You could set coordinate starting point of labyrinth /// </summary> /// <param name="startingPointX"></param> /// <param name="startingPointY"></param> /// <param name="labyrinthWidth"></param> /// <param name="labyrinthHeight"></param> public void GenerateLabyrinth(int startingPointX = 0, int startingPointY = 0, int?labyrinthWidth = null, int?labyrinthHeight = null) { //Remove element of old labyrinth ElementsOfLabyrinth?.ForEach(Destroy); ElementsOfLabyrinth = new List <GameObject>(); Walls = new List <GameObject>(); GrowingWallDone = false; Width = labyrinthWidth ?? Width; Height = labyrinthHeight ?? Height; Width++; Height++; DepthOfCurrentLevel++; LevelCountText.text = (DepthOfCurrentLevel).ToString(); var labyrinthGenerator = new LabyrinthGenerator(Width, Height); LabyrinthLevel = labyrinthGenerator.GenerateLevel(startingPointX, startingPointY, DepthOfCurrentLevel); var wallCells = new List <BaseCellObject>(); foreach (var cell in LabyrinthLevel.AllCells()) { GameObject cellGameObject = null; var dropHeight = 0f; if (cell is Wall) { cellGameObject = Instantiate(WallTemplate); Walls.Add(cellGameObject); wallCells.Add(cell); } else if (cell is Goldmine) { cellGameObject = GenerateGoldmine(); Walls.Add(cellGameObject); wallCells.Add(cell); } else if (cell is Coin) { cellGameObject = GenerateCoin(); dropHeight = (cell.X + cell.Y) * 0.2f; } else if (cell is StairsDown) { cellGameObject = GenerateDown(); dropHeight = (cell.X + cell.Y) * 0.2f; Hero.GetComponent <HeroMovement>().StairsDown = cellGameObject; } if (cellGameObject != null) { cellGameObject.transform.position = new Vector3(cell.X, dropHeight, cell.Y); ElementsOfLabyrinth.Add(cellGameObject); } } var heroPosition = Hero.transform.position; wallCells .OrderBy(cell => Vector3.Distance(new Vector3(cell.X, 0, cell.Y), heroPosition)).ToList() .ForEach(cell => new Task(() => GrowWall(cell, heroPosition)).Start()); GenerateBorder(); }
public void InsertData(LabyrinthGenerator generator) { DeleteAllConnections(); DeleteAllBooks(); Console.WriteLine("SQL Server: Inserting new connections."); foreach (var room1 in generator.connections.Keys) { foreach (var room2 in generator.connections[room1]) { var cmd = new SqlCommand("INSERT INTO dbo.connections (level1, room1, level2, room2) VALUES (@level1, @room1, @level2, @room2);", connection); SqlParameter Level1In = cmd.Parameters.Add("@level1", SqlDbType.Int); Level1In.Direction = ParameterDirection.Input; Level1In.Value = room1.levelNumber; SqlParameter Room1In = cmd.Parameters.Add("@room1", SqlDbType.Int); Room1In.Direction = ParameterDirection.Input; Room1In.Value = room1.roomNumber; SqlParameter Level2In = cmd.Parameters.Add("@level2", SqlDbType.Int); Level2In.Direction = ParameterDirection.Input; Level2In.Value = room2.levelNumber; SqlParameter Room2In = cmd.Parameters.Add("@room2", SqlDbType.Int); Room2In.Direction = ParameterDirection.Input; Room2In.Value = room2.roomNumber; cmd.ExecuteNonQuery(); } } Console.WriteLine("SQL Server: Inserting new books."); foreach (var room in generator.booksInRooms.Keys) { // ThAW: Note to self: Use SqlParameters when using text parameters. var cmd = new SqlCommand("INSERT INTO dbo.books (level_, room, name) VALUES (@level_, @room, @name);", connection); SqlParameter LevelIn = cmd.Parameters.Add("@level_", SqlDbType.Int); LevelIn.Direction = ParameterDirection.Input; LevelIn.Value = room.levelNumber; SqlParameter RoomIn = cmd.Parameters.Add("@room", SqlDbType.Int); RoomIn.Direction = ParameterDirection.Input; RoomIn.Value = room.roomNumber; SqlParameter NameIn = cmd.Parameters.Add("@name", SqlDbType.Text); NameIn.Direction = ParameterDirection.Input; NameIn.Value = generator.booksInRooms[room]; cmd.ExecuteNonQuery(); } Console.WriteLine("SQL Server: Data inserted."); }
public void Initialize(LabyrinthGenerator generator) { Connect(@"Persist Security Info=False;Integrated Security=SSPI;database=labyrinth;server=(local)\INSTANCENAME;Network Library=DBMSSOCN"); // TCP/IP //CreateSchema(); InsertData(generator); }
public void InsertData(LabyrinthGenerator generator) { DeleteAllConnections(); DeleteAllBooks(); Console.WriteLine("Oracle: Inserting new connections."); foreach (var room1 in generator.connections.Keys) { foreach (var room2 in generator.connections[room1]) { var cmd = new OracleCommand("INSERT INTO c##labyrinth.connections (level1, room1, level2, room2) VALUES (:level1, :room1, :level2, :room2)", connection); cmd.BindByName = true; // See http://www.codeproject.com/Articles/208176/Gotcha-sharp1161-Using-Named-Parameters-with-Oracl OracleParameter Level1In = cmd.Parameters.Add(":level1", OracleDbType.Int32); Level1In.Direction = ParameterDirection.Input; Level1In.Value = room1.levelNumber; OracleParameter Room1In = cmd.Parameters.Add(":room1", OracleDbType.Int32); Room1In.Direction = ParameterDirection.Input; Room1In.Value = room1.roomNumber; OracleParameter Level2In = cmd.Parameters.Add(":level2", OracleDbType.Int32); Level2In.Direction = ParameterDirection.Input; Level2In.Value = room2.levelNumber; OracleParameter Room2In = cmd.Parameters.Add(":room2", OracleDbType.Int32); Room2In.Direction = ParameterDirection.Input; Room2In.Value = room2.roomNumber; cmd.ExecuteNonQuery(); } } Console.WriteLine("Oracle: Inserting new books."); foreach (var room in generator.booksInRooms.Keys) { // ThAW: Note to self: Use SqlParameters when using text parameters. var cmd = new OracleCommand("INSERT INTO c##labyrinth.books (level_, room, name_) VALUES (:level_, :room, :name_)", connection); cmd.BindByName = true; OracleParameter LevelIn = cmd.Parameters.Add(":level_", OracleDbType.Int32); LevelIn.Direction = ParameterDirection.Input; LevelIn.Value = room.levelNumber; OracleParameter RoomIn = cmd.Parameters.Add(":room", OracleDbType.Int32); RoomIn.Direction = ParameterDirection.Input; RoomIn.Value = room.roomNumber; OracleParameter NameIn = cmd.Parameters.Add(":name_", OracleDbType.Varchar2); NameIn.Direction = ParameterDirection.Input; NameIn.Value = generator.booksInRooms[room]; cmd.ExecuteNonQuery(); } Console.WriteLine("Oracle: Data inserted."); }