Beispiel #1
0
        //postavi
        private void btnSetup_Click(object sender, EventArgs e)
        {
            //Resetiranje i crtanje novog labirinta
            timer1.Stop();
            netTK.Clear();
            LabirintPrim(Color.Black, Color.Red, netTK.PatchAt(0, 0));


            //Postavljanje Patcheva
            Random rnd = new Random();

            netTK.AddCustomPatchProperty("visited");

            start = netTK.PatchAt(rnd.Next(-50, 50), rnd.Next(-50, 50));
            start.SetColor(Color.White);
            start.CustomProperties["visited"] = true;

            end = netTK.PatchAt(rnd.Next(-50, 50), rnd.Next(-50, 50));
            end.SetColor(Color.Blue);

            //Stvaranje prvog robota
            Robot OG_Robot = new Robot();

            OG_Robot.SetPosition(start.Position);
            OG_Robot.SetColor(Color.Yellow);
            OG_Robot.gValue = 0;
            OG_Robot.hValue = netTK.Manhatten(start.Position, end.Position);
            OG_Robot.fValue = OG_Robot.hValue;
            netTK.InsertAgent(OG_Robot);

            //render i gledaj na start
            netTK.ViewCam.LookAtPatch(start);
            renderForm.renderCanvas.Invalidate();
        }
Beispiel #2
0
        private void LabirintPrim(Color floorColor, Color wallColor, Patch start)
        {
            foreach (Patch p in netTK.GetPatchesAsList())
            {
                p.SetColor(wallColor);
            }
            start.SetColor(floorColor);
            List <Patch> walls = start.Neighbours90WithColor(wallColor);
            Random       rnd   = new Random();

            while (walls.Count() != 0)
            {
                Patch wall = walls[rnd.Next(walls.Count)];

                if (wall.Neighbours90WithColor(floorColor).Count == 1)
                {
                    wall.SetColor(floorColor);
                    foreach (Patch p in wall.Neighbours90WithColor(wallColor))
                    {
                        walls.Add(p);
                    }
                }

                walls.Remove(wall);
            }
        }