Ejemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        maze = new Maze (32, 32);
        maze.generate ();

        aTexture = maze.tiles;
    }
Ejemplo n.º 2
0
    public void generateNewStage(GameObject floorTile,
		                         GameObject wallBlock,
	                             GameObject coin,
	                             GameObject player,
	                             GameObject targetSprite,
	                             GameObject door,
		                         int difficulty,
	                             int maxDifficulty)
    {
        // Grab prefabs from function call
        _floorTile = floorTile;
        _wallBlock = wallBlock;
        _coin = coin;
        _player = player;
        _targetSprite = Instantiate(targetSprite);
        _door = door;
        // Determine size and num coins for this stage
        determineParamsBasedOnDifficulty(difficulty, maxDifficulty);
        // Create our maze
        _maze = new Maze(_size, difficulty, maxDifficulty);
        _maze.generateMap();
        // Allocate our arrays
        _coins = new GameObject[_numCoins];
        _components = new GameObject[(int)_size.x,(int)_size.y];
        // Instantiate our prefabs
        placeComponentsFromMap();
    }
Ejemplo n.º 3
0
	// Update is called once per frame
	void Update () 
	{
		if(mGen == null)
			mGen = FindObjectOfType<MazeGenerator>();
		else if(m == null && mGen != null)
		{
			m = mGen.currentMaze();
			if(m != null)
			{
				Texture2D t = new Texture2D((int)m.Dimensions().x, (int)m.Dimensions().y, TextureFormat.ARGB4444, false);
				for(int x=0; x<t.width; x++)
				{
					for(int y=0; y<t.height; y++)
					{
						if(m.GetCell(x,y).isWall)
							t.SetPixel(x,y,Color.black);
						else
							t.SetPixel(x,y,Color.white);
					}
				}
				t.anisoLevel = 0;
				t.filterMode = FilterMode.Point;
				t.Apply();
				im.sprite = Sprite.Create(t, new Rect(0,0,t.width,t.height), Vector2.one/2);
			}
		}
	}
Ejemplo n.º 4
0
	// Помещаем персонажа в центр лабиринта
	void Start() {
		var maze = GameObject.Find("Maze").GetComponent<Maze>();
		transform.position = new Vector2(maze.width / 2, maze.height / 2);
		dest = transform.position;

		mazeInstance = GameObject.Find("Maze").GetComponent<Maze>();
	}
 // Use this for initialization
 void Start()
 {
     enragedGrowl = GetComponent<AudioSource>();
     maze = GameObject.Find("Maze").GetComponent<Maze>();
     player = GameObject.Find("Player");
     Orientate(col, row);
 }
Ejemplo n.º 6
0
	IEnumerator afterFrame()
	{
		yield return true;
		online = true;
		m = GameObject.FindObjectOfType<MazeGenerator>().currentMaze();
		wantPos = randomPos();
	}
 public MazyPrototypeFactory(Maze maze, Wall wall, Room room, Door door)
 {
     _maze = maze;
     _wall = wall;
     _room = room;
     _door = door;
 }
Ejemplo n.º 8
0
    public static List<Cell> Neighbours(Maze maze, Point point)
    {
        List<Cell> neighbours = new List<Cell>();

        if (point.y > 1)
        {
            neighbours.Add(maze.Grid[point.x, point.y-1]);
        }

        if (point.y < maze.height-2)
        {
            neighbours.Add(maze.Grid[point.x, point.y+1]);
        }

        if (point.x > 1)
        {
            neighbours.Add(maze.Grid[point.x-1, point.y]);
        }

        if (point.x < maze.width-2)
        {
            neighbours.Add(maze.Grid[point.x+1, point.y]);
        }

        return neighbours;
    }
Ejemplo n.º 9
0
	void Update () 
	{
		if(mGen == null)
			mGen = FindObjectOfType<MazeGenerator>();
		else if(m == null)
		{
			m = mGen.currentMaze();
		}
		else if(pControl == null)
		{
			GameObject g = GameObject.FindGameObjectWithTag("MyPlayer");
			if(g != null)
				pControl = g.GetComponent<PlayerControl>();
		}
		else
		{
			pOffset = pixelOffset();
			cellDim = cellDimenstions();
			icon.rectTransform.sizeDelta = new Vector2(cellDimenstions().x, cellDimenstions().y);
			icon.transform.localEulerAngles = new Vector3(0,0,-pControl.transform.localEulerAngles.y + 90);
			Vector2 pPos = pControl.pos();
			float x = pixelOffset().x + (cellDimenstions().x*pPos.x) + (cellDimenstions().x/2);
			float y = pixelOffset().y + (cellDimenstions().y*pPos.y) + (cellDimenstions().x/2);
			Vector2 v = new Vector2(x,y);
			GetComponent<RectTransform>().anchoredPosition = v;
		}
	}
Ejemplo n.º 10
0
    // Use this for initialization
    void Start()
    {
        m_TileList = new List<Transform> ();
        for (int x = 0; x < 8; x++) {
            for (int y = 0; y < 12; y++) {
                int flag = m_MapConfigArray [x, y];
                var tileTF = Instantiate (tile, new Vector3 (y * 0.3f, -x * 0.3f, 0), Quaternion.identity) as Transform;
                if (flag == 1) {
                    tileTF.GetComponent<SpriteRenderer> ().color = Color.red;
                }
                m_TileList.Add (tileTF);
            }
        }

        Maze maze = new Maze(m_MapConfigArray);
        Point start = new Point(1, 1);
        Point end = new Point(1, 10);

        //		Transform startTile = m_TileList [1 * 12 + 1];
        //		startTile.GetComponent<SpriteRenderer> ().color = Color.black;
        //
        //		Transform endTile = m_TileList [6 * 12 + 10];
        //		endTile.GetComponent<SpriteRenderer> ().color = Color.black;

        var parent = maze.FindPath(start, end, false);

        while (parent != null)
        {
            Debug.Log(parent.X + ", " + parent.Y);
            Transform targetTile = m_TileList [parent.X * 12 + parent.Y];
            targetTile.GetComponent<SpriteRenderer> ().color = Color.green;

            parent = parent.ParentPoint;
        }
    }
 public MazePrototypeFactory(Maze maze, Room room, Door door, Wall wall)
 {
     this.prototypeMaze = maze;
     this.prototypeRoom = room;
     this.prototypeDoor = door;
     this.prototypeWall = wall;
 }
Ejemplo n.º 12
0
	// Update is called once per frame
	void Update () 
	{
		if(m == null)
		{
			m = gen.currentMaze();
			RandomPlacement();
		}

		if(!setup && PlayerControl)
		{
			gameObject.tag = "MyPlayer";
			SpriteObj.SetActive(false);
			CamHolder.SetActive(true);
		}
		bool up = Input.GetKeyDown(KeyCode.UpArrow);
		bool down = Input.GetKeyDown(KeyCode.DownArrow);
		bool left = Input.GetKeyDown(KeyCode.LeftArrow);
		bool right = Input.GetKeyDown(KeyCode.RightArrow);
		if(!PlayerControl)
			return;
		if(up || down || left || right)
		{
			CmdDoMovement(up, down, left, right);
		}
		CheckSeen();

			
		if(Input.GetKeyDown(KeyCode.Space))
		{
			StopCoroutine("LineShow");
			StartCoroutine("LineShow");
			CmdShoot();
		}
	}
Ejemplo n.º 13
0
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="maze">Maze handle</param>
		/// <param name="square">Square handle</param>
		public SquareForm(Maze maze, Square square)
		{
			InitializeComponent();


			SquareControlBox.Maze = maze;
			SquareControlBox.SetSquare(square);
		}
Ejemplo n.º 14
0
	public void NewMaze()
	{
		ClearOld();
		WallObjects = new List<GameObject>();
		cMaze = new Maze(Width, Height, 100-SparsePercent, MazeSeed);
		Cell[,] cells = cMaze.GetCells();
		MakeMaze(cells);
	}
Ejemplo n.º 15
0
        public override void render(Maze pmaze)
        {
            base.render(pmaze);

            statX.Text = pmaze.Width.ToString();
            statY.Text = pmaze.Height.ToString();
            statRendered.Text = DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss");
        }
Ejemplo n.º 16
0
 private IEnumerator BeginGame()
 {
     mazeInstance = Instantiate(mazePrefab) as Maze;
     yield return StartCoroutine (mazeInstance.Generate());
     playerInstance = Instantiate(playerPrefab) as Player;
     playerInstance.SetLocation(mazeInstance.GetCell(mazeInstance.RandomCoordinates));
     StartCoroutine(mazeInstance.Generate());
 }
        /// <summary>
        /// Generate a Maze
        /// </summary>
        /// <param name="width">Width of the maze</param>
        /// <param name="height">Height of the maze</param>
        /// <param name="innerMapType">The type which is used to store a map</param>
        /// <param name="seed">The seed that is used to generate a maze</param>
        /// <param name="pixelChangedCallback">When a pixel is changed you can define a callback here to for example draw the maze while its being generated, add null if you don't want this. Last 2 longs are for the current step and the total steps (can be used to calculate how far the maze is done being generated)</param>
        /// <returns>A maze</returns>
        public Maze Generate(int width, int height, InnerMapType innerMapType, int seed, Action<int, int, long, long> pixelChangedCallback)
        {
            var map = GoGenerate(new FastRandom(seed), width, height);

            InnerMap innerMap = new BooleanInnerMap(width, height, map);
            var maze = new Maze(innerMap);
            return maze;
        }
 public BotFactory(Maze maze, EngineSettings settings, WallGrid walls, BrainFactory brainFactory, EyeFactory eyeFactory)
 {
     _maze = maze;
     _settings = settings;
     _walls = walls;
     _brainFactory = brainFactory;
     _eyeFactory = eyeFactory;
 }
Ejemplo n.º 19
0
 private void BeginGame()
 {
     mazeInstance = Instantiate(mazePrefab) as Maze;
     //StartCoroutine(mazeInstance.Generate());
     mazeInstance.Generate();
     timeLimit = mazeInstance.difficulty *1.5f;
     timerText.color = new Color(0,1,213.0f/255.0f);
 }
Ejemplo n.º 20
0
 private static bool isValid(int x, int y, InnerMap map, Maze maze)
 {
     //Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);
     if (x > 0 && x < maze.Width - 1 && y > 0 && y < maze.Height - 1)
     {
         return !map[x, y];
     }
     return false;
 }
Ejemplo n.º 21
0
        public virtual void render(Maze pmaze)
        {
            if (pmaze == null)
                pmaze = lastKnownMaze;
            else
                lastKnownMaze = pmaze;

            this.maze = pmaze;
        }
Ejemplo n.º 22
0
 public MyMazeRobot()
     : base()
 {
     maze = new Maze();
     path = new Stack<Position>();
     currPos = new Position(700, 700);
     path.Push(new Position(-1, -1));
     path.Push(currPos);
 }
Ejemplo n.º 23
0
        public static Maze MakeMaze(int width, int height, int depth) {
            Maze maze = new Maze(width, height);

            DFSMazeGenerator.Instance.Generate(maze, depth);

            maze[random.Next(width), random.Next(height)].HasDown = true;

            return maze;
        }
	public MazeOptimization (Maze maze) {
		this.maze = maze;
		mazeComplexity = new MazeComplexity (maze.rooms);
		var doorsOptimization = new DoorsOptimization ();
		var doorsToBeRemoved = doorsOptimization.CalculateRemovableDoors (ref maze.cells);
		RemoveExtraDoors (doorsToBeRemoved);
		CreateDoorList ();
		PrintRoomsAndDoors ();	// For Testing Only
	}
Ejemplo n.º 25
0
    public static void GenerateDepthFirstWork(Maze maze)
    {
        // Set the start cell
        maze.grid[maze.genStart.x, maze.genStart.y].end = true;

        maze.deadends.Add(maze.grid[maze.genStart.x, maze.genStart.y]);

        // Start generation
        Maze.GenerateDepthFirstRecursive(maze, maze.grid[maze.genStart.x, maze.genStart.y]);
    }
Ejemplo n.º 26
0
	protected void Start()
	{
		// Get level object
		levelObj = GameObject.Find("Level");
		maze = levelObj.GetComponent<Maze>();
		levelGen = levelObj.GetComponent<LevelGen>();

		// Create fade texture (used for pause screen fade)
		fadeTexture = new Texture2D(1, 1);
	}
Ejemplo n.º 27
0
	private IEnumerator BeginGame () {
		Camera.main.clearFlags = CameraClearFlags.Skybox;
		Camera.main.rect = new Rect(0f, 0f, 1f, 1f);
		mazeInstance = Instantiate(mazePrefab) as Maze;
		yield return StartCoroutine(mazeInstance.Generate());
		playerInstance = Instantiate(playerPrefab) as Player;
		playerInstance.SetLocation(mazeInstance.GetCell(mazeInstance.RandomCoordinates));
		Camera.main.clearFlags = CameraClearFlags.Depth;
		Camera.main.rect = new Rect(0f, 0f, 0.5f, 0.5f);
	}
Ejemplo n.º 28
0
        /// <summary>
        /// Generate a Maze
        /// </summary>
        /// <param name="width">Width of the maze</param>
        /// <param name="height">Height of the maze</param>
        /// <param name="innerMapType">The type which is used to store a map</param>
        /// <param name="seed">The seed that is used to generate a maze</param>
        /// <param name="pixelChangedCallback">When a pixel is changed you can define a callback here to for example draw the maze while its being generated, add null if you don't want this. Last 2 longs are for the current step and the total steps (can be used to calculate how far the maze is done being generated)</param>
        /// <returns>A maze</returns>
        public Maze Generate(int width, int height, InnerMapType innerMapType, int seed, Action<int, int, long, long> pixelChangedCallback)
        {
            if (pixelChangedCallback == null)
            {
                pixelChangedCallback = (x, y, z, u) => { };
            }

            Maze maze = new Maze(width, height, innerMapType);
            GoGenerate(maze.InnerMap, maze, new Random(seed), pixelChangedCallback);
            return maze;
        }
Ejemplo n.º 29
0
    public void TestMazeGenerator()
    {
        Maze testMaze10x10 = new Maze(10, 10);
        testMaze10x10.print();

        Maze testMaze1x3 = new Maze(1, 3);
        testMaze1x3.print();

        Maze testMaze4x2 = new Maze(4, 2);
        testMaze4x2.print();
    }
Ejemplo n.º 30
0
        public GameplayScreen(int mazeSize)
        {
            maze = new Maze(mazeSize);
            playerPosition = maze.Cells[0, 0];

            TransitionOnTime  = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            pauseAction = new InputAction(
                new Buttons[] { Buttons.Start, Buttons.Back },
                new Keys[] { Keys.Escape },
                true);

            toggleShortestPathAction = new InputAction(
                new Buttons[] { Buttons.RightTrigger },
                new Keys[] { Keys.P },
                true);

            toggleBreadcrumbsAction = new InputAction(
                new Buttons[] { Buttons.LeftTrigger },
                new Keys[] { Keys.B },
                true);

            toggleScoreAction = new InputAction(
                new Buttons[] { Buttons.Y },
                new Keys[] { Keys.Y },
                true);

            playerMoveUpAction = new InputAction(
                new Buttons[] { Buttons.DPadUp, Buttons.LeftThumbstickUp },
                new Keys[] { Keys.Up, Keys.W },
                true);

            playerMoveDownAction = new InputAction(
                new Buttons[] { Buttons.DPadDown, Buttons.LeftThumbstickDown },
                new Keys[] { Keys.Down, Keys.S },
                true);

            playerMoveLeftAction = new InputAction(
                new Buttons[] { Buttons.DPadLeft, Buttons.LeftThumbstickLeft },
                new Keys[] { Keys.Left, Keys.A },
                true);

            playerMoveRightAction = new InputAction(
                new Buttons[] { Buttons.DPadRight, Buttons.LeftThumbstickRight },
                new Keys[] { Keys.Right, Keys.D },
                true);

            showHintAction = new InputAction(
                new Buttons[] { Buttons.X },
                new Keys[] { Keys.H },
                false);
        }
Ejemplo n.º 31
0
 public abstract MazeSolution Solve(Maze maze, CellPosition startCellPosition, CellPosition escapeCellPosition);
Ejemplo n.º 32
0
 public CellBase(int x, int y, Maze maze)
 {
     X    = x;
     Y    = y;
     Maze = maze;
 }
Ejemplo n.º 33
0
        /// <summary>
        /// Generates a maze.
        /// </summary>
        /// <param name=""></param>
        /// <param name="width"></param>
        /// <param name=""></param>
        /// <param name="height"></param>
        /// <returns></returns>
        private IGrid GenerateGridAsMaze(int width, int height)
        {
            var m_maze_size = new int[] { 0, 0 };

            m_maze_size[0] = width;
            m_maze_size[1] = height;

            if (width < 5 || height < 5)
            {
                return(null);
            }

            // The width and height must be greater than or equal to 5 or it won't work
            // The width and height must be odd or else we will have extra walls
            for (int a = 0; a < 2; a++)
            {
                if (m_maze_size[a] < 5)
                {
                    m_maze_size[a] = 5;
                }
                else if (m_maze_size[a] % 2 == 0)
                {
                    m_maze_size[a]--;
                }
            }

            Maze maze = new Maze();

            maze.Width  = m_maze_size[0];
            maze.Height = m_maze_size[1];

            InitializeMaze(maze);
            RandomPoint(maze, false);
            RandomPoint(maze, true);

            bool first_move = true;
            bool success    = true;

            while (dfs_queue.Count() > 1 - Convert.ToInt32(first_move))
            {
                if (!success)
                {
                    dfs_queue.Dequeue();

                    if (!first_move && dfs_queue.Count() > 2)
                    {
                        dfs_queue.Dequeue();
                    }
                    else
                    {
                        break;
                    }

                    success = true;
                }

                while (success)
                {
                    success = RandomMove(maze, first_move);

                    if (first_move)
                    {
                        first_move = false;
                    }
                }
            }

            Reset();

            return(maze);
        }
        public override void GenerateMaze(Maze maze)
        {
            iterations = 0;

            GenerateMaze(maze, 0, maze.width, 0, maze.height, rand.Next() % 2 == 0);
        }
Ejemplo n.º 35
0
 internal ClydeAIBehavior(GhostObject owner, PacmanObject target, Maze level)
     : base(owner, target, level, GhostType.Clyde)
 {
 }
Ejemplo n.º 36
0
        /// <summary>
        /// Static method to convert back to Maze game from the JSON format.
        /// </summary>
        /// <param name="str">
        /// The JSON of the MazeGame.
        /// </param>
        /// <returns>
        /// The MazeGame that we have created.
        /// </returns>
        public static MazeGame FromJSON(string str)
        {
            Maze maze = Maze.FromJSON(str);

            return(new MazeGame(maze.Name, maze));
        }
    public void regenerate(float x, float z, Vector3 v)
    {
        if (x == 112 && z == -97)
        {
            //cleanup or prep
            Destroy(tunnel);
            Destroy(beachStore);
            Destroy(mazeEntranceArea);

            //regen 1st
            Destroy(mazeInstanceBrick1.gameObject);
            mazeInstanceBrick1 = Instantiate(mazeBrick1) as Maze;
            mazeInstanceBrick1.setPosition(mazePos1);
            mazeInstanceBrick1.SetStartPoint(0, 1);
            mazeInstanceBrick1.SetEndPoint(20, 19);
            mazeInstanceBrick1.Generate(true, 2);

            //spawn reward: hammer
            v.x = 300;
            v.y = (v.y - 90) % 360;
            v.z = 90;
            createLoot <hammer>(new IntVector2(112, -97), hammerPrefab, v);
        }
        else if (x == 236 && z == -97)
        {
            //cleanup or prep
            brickMetalTransition.SetActive(true);

            //regend 2nd
            Destroy(mazeInstanceBrick2.gameObject);
            mazeInstanceBrick2 = Instantiate(mazeBrick2) as Maze;
            mazeInstanceBrick2.setPosition(mazePos2);
            mazeInstanceBrick2.SetStartPoint(0, 19);
            mazeInstanceBrick2.SetEndPoint(19, 0);
            mazeInstanceBrick2.Generate(true, 4);

            //spawn reward: double jump
            v.x = 0;
            v.y = (v.y - 90) % 360;
            v.z = 0;
            createLoot <boots>(new IntVector2(236, -97), bootsPrefab, v);
        }
        else if (x == 236 && z == -217)
        {
            //regen 3rd
            Destroy(mazeInstanceMetal.gameObject);
            mazeInstanceMetal = Instantiate(mazeMetal) as Maze;
            mazeInstanceMetal.setPosition(mazePos3);
            mazeInstanceMetal.SetStartPoint(19, 20);
            mazeInstanceMetal.SetEndPoint(0, 1);
            mazeInstanceMetal.Generate(true, 6);

            //spawn reward: potion
            //boots1
            v.x = 325;
            v.y = (v.y - 90) % 360;
            v.z = 0;
            createLoot <potion>(new IntVector2(236, -217), potionPrefab, v);
        }
        else
        {
            //regen 4th
            Destroy(mazeInstanceTron.gameObject);
            mazeInstanceTron = Instantiate(mazeTron) as Maze;
            mazeInstanceTron.setPosition(mazePos4);
            mazeInstanceTron.SetStartPoint(20, 1);
            mazeInstanceTron.SetEndPoint(1, 20);
            mazeInstanceTron.Generate(true, 8);

            //spawn reward: ??
        }
    }
Ejemplo n.º 38
0
        public MapBuilder Generate(int width, int height, Algorithms algorithm = Algorithms.AldousBroderAvoidLinks)
        {
            var maze = GetMaze(width, height, algorithm);

            Maze = maze;

            var builder = new MapBuilder(width, height);

            // find all horizontal paths
            for (var y = 0; y < height; y++)
            {
                var onPath    = false;
                var pathStart = 0;

                for (var x = 0; x < width; x++)
                {
                    var cell = maze[y, x];
                    if (cell.EasternBoundary || !cell.Links.Contains(cell.East))
                    {
                        // so no path to the right
                        if (onPath)
                        {
                            // we've reached the end
                            onPath = false;
                            Debug.WriteLine($"Easterly path from [{pathStart},{y}] to [{x},{y}]");
                            builder.AddPath(pathStart, y, Directions.East, x - pathStart + 1);
                        }
                    }
                    else
                    {
                        if (!onPath)
                        {
                            onPath    = true;
                            pathStart = x;
                        }
                    }
                }
            }

            // find all vertical paths
            for (var x = 0; x < width; x++)
            {
                var onPath    = false;
                var pathStart = 0;

                for (var y = 0; y < height; y++)
                {
                    var cell = maze[y, x];
                    if (cell.SouthernBoundary || !cell.Links.Contains(cell.South))
                    {
                        // so no path to the bottom
                        if (onPath)
                        {
                            // we've reached the end
                            onPath = false;
                            Debug.WriteLine($"Southerly path from [{x},{pathStart}] to [{x},{y}]");
                            builder.AddPath(x, pathStart, Directions.South, y - pathStart + 1);
                        }
                    }
                    else
                    {
                        if (!onPath)
                        {
                            onPath    = true;
                            pathStart = y;
                        }
                    }
                }
            }

            builder.AddStart(maze.LongestPath.First().Col, maze.LongestPath.First().Row);
            builder.AddEnd(maze.LongestPath.Last().Col, maze.LongestPath.Last().Row);

            return(builder);
        }
Ejemplo n.º 39
0
 public Part1()
 {
     favoriteNumberRepository = new FavoriteNumberRepository();
     maze = new Maze();
 }
Ejemplo n.º 40
0
        public static int Part2(List <string> input)
        {
            var maze = Maze.FromMap(input);

            return(maze.ShortestPath2("AA", "ZZ"));
        }
Ejemplo n.º 41
0
        public void VerifyNumberOfRooms(int n)
        {
            maze = new Maze(n);

            Assert.AreEqual(n, maze.getRoomCount());
        }
Ejemplo n.º 42
0
 private void BeginGame()
 {
     mazeInstance = Instantiate(mazePrefab) as Maze;
     StartCoroutine(mazeInstance.Generate());
 }
Ejemplo n.º 43
0
        public override void Paint(Level level)
        {
            var maze   = Maze.Generate(this);
            var wall   = Tiles.RandomSolid();
            var spikes = Rnd.Chance(30);

            if (Rnd.Chance())
            {
                var v = true;                 // Rnd.Chance();
                var k = Rnd.Int(1, 4);

                for (var i = 0; i < k; i++)
                {
                    var nmaze = new bool[maze.Length][];

                    for (var j = 0; j < maze.Length; j++)
                    {
                        nmaze[j] = new bool[maze[0].Length];
                    }

                    for (int x = 0; x < maze.Length; x++)
                    {
                        for (int y = 0; y < maze[0].Length; y++)
                        {
                            nmaze[x][y] = maze[x][y];
                        }
                    }

                    for (int x = 1; x < maze.Length - 1; x++)
                    {
                        for (int y = 1; y < maze[0].Length - 1; y++)
                        {
                            if (maze[x][y] == v)
                            {
                                var n = 0;

                                foreach (var d in MathUtils.Directions)
                                {
                                    var xx = x + (int)d.X;
                                    var yy = y + (int)d.Y;

                                    if (maze[xx][yy] == v)
                                    {
                                        n++;
                                    }
                                }

                                if (n < 2)
                                {
                                    nmaze[x][y] = !v;
                                }
                            }
                        }
                    }

                    maze = nmaze;
                }
            }

            for (int x = 1; x < maze.Length - 1; x++)
            {
                for (int y = 1; y < maze[0].Length - 1; y++)
                {
                    if (maze[x][y])
                    {
                        Painter.Set(level, x + Left, y + Top, wall);
                    }
                    else if (spikes && Rnd.Chance(20))
                    {
                        Painter.Set(level, x + Left, y + Top, Tile.SensingSpikeTmp);
                    }
                }
            }
        }
Ejemplo n.º 44
0
        public String Join(string gameName, string joinsID)
        {
            Maze maze = model.Join(gameName, joinsID);

            return(maze.ToJSON());
        }
Ejemplo n.º 45
0
        private void GoGenerate(InnerMap map, Maze maze, Random r, Action <int, int, long, long> pixelChangedCallback)
        {
            long totSteps    = (((long)maze.Width - 1L) / 2L) * (((long)maze.Height - 1L) / 2L);
            long currentStep = 0;

            int x = 1;
            int y = 1;

            Stack <MazePoint> stackje = new Stack <MazePoint>();

            stackje.Push(new MazePoint(x, y));
            map[x, y] = true;
            pixelChangedCallback.Invoke(x, y, currentStep, totSteps);

            MazePoint[] targets = new MazePoint[4];

            //form.drawPixel(x, y, brushThisUses);
            while (stackje.Count != 0)
            {
                MazePoint cur = stackje.Peek();
                x = cur.X;
                y = cur.Y;

                int targetCount = 0;
                if (x - 2 > 0 && !map[x - 2, y])
                {
                    targets[targetCount].X = x - 2;
                    targets[targetCount].Y = y;
                    targetCount++;
                }
                if (x + 2 < maze.Width - 1 && !map[x + 2, y])
                {
                    targets[targetCount].X = x + 2;
                    targets[targetCount].Y = y;
                    targetCount++;
                }
                if (y - 2 > 0 && !map[x, y - 2])
                {
                    targets[targetCount].X = x;
                    targets[targetCount].Y = y - 2;
                    targetCount++;
                }
                if (y + 2 < maze.Height - 1 && !map[x, y + 2])
                {
                    targets[targetCount].X = x;
                    targets[targetCount].Y = y + 2;
                    targetCount++;
                }

                //Thread.Sleep(1000);

                if (targetCount > 0)
                {
                    var target = targets[r.Next(targetCount)];
                    stackje.Push(target);
                    map[target.X, target.Y] = true;

                    currentStep++;

                    if (target.X < x)
                    {
                        map[x - 1, y] = true;
                        pixelChangedCallback.Invoke(x - 1, y, currentStep, totSteps);
                        //form.drawPixel(x - 1, y, brushThisUses);
                    }
                    else if (target.X > x)
                    {
                        map[x + 1, y] = true;
                        pixelChangedCallback.Invoke(x + 1, y, currentStep, totSteps);
                        //form.drawPixel(x + 1, y, brushThisUses);
                    }
                    else if (target.Y < y)
                    {
                        map[x, y - 1] = true;
                        pixelChangedCallback.Invoke(x, y - 1, currentStep, totSteps);
                        //form.drawPixel(x, y - 1, brushThisUses);
                    }
                    else if (target.Y > y)
                    {
                        map[x, y + 1] = true;
                        pixelChangedCallback.Invoke(x, y + 1, currentStep, totSteps);
                        //form.drawPixel(x, y + 1, brushThisUses);
                    }
                    pixelChangedCallback.Invoke(target.X, target.Y, currentStep, totSteps);
                    //form.drawPixel(target.X, target.Y, brushThisUses);
                }
                else
                {
                    stackje.Pop();
                }
            }
        }
Ejemplo n.º 46
0
        public String Start(string name, int rows, int cols, string clientID)
        {
            Maze maze = model.StartGame(name, rows, cols, clientID);

            return(maze.ToJSON());
        }
        private void GenerateMaze(Maze maze, int x, int width, int y, int height, bool horizontal)
        {
            if (!Global.noDelay)
            {
                while (!Global.doStep)
                {
                }
            }
            Global.doStep = false;

            iterations++;

            current = new Rectangle(x * Global.squareSize, y * Global.squareSize, width * Global.squareSize, height * Global.squareSize);

            if (horizontal)   // Horizontal wall
            {
                if (width == 1 || height == 1)
                {
                    return;
                }
                else
                {
                    int half = height / 2;
                    for (int i = x; i < width + x; i++)
                    {
                        maze.mazeEdges.Add(new Edge((half - 1 + y) * maze.width + i, (half + y) * maze.width + i));
                    }

                    int  gap = rand.Next(1, width + 1) + x - 1;
                    Edge e   = maze.GetEdge((half - 1 + y) * maze.width + gap, (half + y) * maze.width + gap);
                    if (e != null)
                    {
                        maze.mazeEdges.Remove(e);
                    }

                    GenerateMaze(maze, x, width, y, half, !horizontal);
                    GenerateMaze(maze, x, width, half + y, height - half, !horizontal);
                }
            }
            else     // Vertical wall
            {
                if (height == 1 || width == 1)
                {
                    return;
                }
                else
                {
                    int half = width / 2;
                    for (int i = y; i < height + y; i++)
                    {
                        maze.mazeEdges.Add(new Edge((half - 1 + x) + maze.width * i, (half + x) + maze.width * i));
                    }

                    int  gap = rand.Next(1, height + 1) + y - 1;
                    Edge e   = maze.GetEdge((half - 1 + x) + maze.width * gap, (half + x) + maze.width * gap);
                    if (e != null)
                    {
                        maze.mazeEdges.Remove(e);
                    }

                    GenerateMaze(maze, x, half, y, height, !horizontal);
                    GenerateMaze(maze, half + x, width - half, y, height, !horizontal);
                }
            }
        }
Ejemplo n.º 48
0
 void Start()
 {
     maze = generator.GenerateMaze(5, 5);
     generator.DisplayMaze(maze);
 }
 public HuntAndKillGenerator(Maze maze) : base(maze)
 {
     _currentCell = _maze.Cells.RandomElement(_rand);
     _state       = State.Start;
 }
Ejemplo n.º 50
0
        public virtual void SolveMaze(Maze maze)
        {
            solving = true;

            initSolutions(maze);
        }
Ejemplo n.º 51
0
        /// <summary>
        /// Select a random direction based on our options, append it to the current path, and move there
        /// </summary>
        /// <param name="first_move"></param>
        /// <returns></returns>
        private bool RandomMove(Maze maze, bool first_move)
        {
            int random_neighbor;
            List <List <int> > unvisited_neighbors = new List <List <int> >();

            for (int direction = 0; direction < 4; direction++)
            {
                int[] possible_pmd = new int[] { 0, 0 };

                if (direction == UP)
                {
                    possible_pmd[1] = -1;
                }
                else if (direction == DOWN)
                {
                    possible_pmd[1] = 1;
                }
                else if (direction == LEFT)
                {
                    possible_pmd[0] = -1;
                }
                else
                {
                    possible_pmd[0] = 1;
                }

                if (dfs_queue.LastOrDefault()[0] + possible_pmd[0] * 2 > 0 &&
                    dfs_queue.LastOrDefault()[0] + possible_pmd[0] * 2 < maze.Width - 1 &&
                    dfs_queue.LastOrDefault()[1] + possible_pmd[1] * 2 > 0 &&
                    dfs_queue.LastOrDefault()[1] + possible_pmd[1] * 2 < maze.Height - 1)
                {
                    var column = dfs_queue.LastOrDefault()[1] + possible_pmd[1] * 2;
                    var line   = dfs_queue.LastOrDefault()[0] + possible_pmd[0] * 2;

                    var cell = maze.Cells.ElementAt(column).ElementAt(line)[1];

                    if (!cell)
                    {
                        List <int> possible_move_delta = new List <int>(possible_pmd);

                        unvisited_neighbors.Add(possible_move_delta);
                    }
                }
            }

            if (unvisited_neighbors.Count() > 0)
            {
                random_neighbor = random.Next() % unvisited_neighbors.Count;

                for (int a = 0; a < Convert.ToInt32(!first_move) + 1; a++)
                {
                    List <int> new_location = new List <int>();

                    new_location.Add(dfs_queue.LastOrDefault()[0] + unvisited_neighbors[random_neighbor][0]);
                    new_location.Add(dfs_queue.LastOrDefault()[1] + unvisited_neighbors[random_neighbor][1]);

                    dfs_queue.Enqueue(new_location);

                    maze.Cells[dfs_queue.LastOrDefault()[1]][dfs_queue.LastOrDefault()[0]][0] = false;
                    maze.Cells[dfs_queue.LastOrDefault()[1]][dfs_queue.LastOrDefault()[0]][1] = true;
                }

                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 52
0
 /*
  * The SinglePlayerGame constructor.
  * Inherited by the Game abstract class.
  */
 public SinglePlayerGame(string name, Maze maze) : base(name, maze)
 {
     // Sets the ready property to true, since there's no need to wait for players.
     this.ready = true;
 }
Ejemplo n.º 53
0
        static void Main(string[] args)
        {
            Program       app            = new Program();
            List <string> inputFiles     = new List <string>();
            string        mazeChoices    = string.Empty;
            int           mazeFileNumber = int.MaxValue;
            Maze          mazeToSolve    = new Maze();

            //Load sample data
            inputFiles.Add(appPath + @"\App_Data\input.txt");
            inputFiles.Add(appPath + @"\App_Data\large_input.txt");
            inputFiles.Add(appPath + @"\App_Data\medium_input.txt");
            inputFiles.Add(appPath + @"\App_Data\small.txt");
            inputFiles.Add(appPath + @"\App_Data\sparse_medium.txt");

            //Configure console window to properly display larger samples outputs
            //May still not display properly on small displays
            Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
            ShowWindow(ThisConsole, MAXIMIZE);
            Console.BufferHeight = Int16.MaxValue - 1;


            //Generate maze options
            for (int i = 0; i < inputFiles.Count; i++)
            {
                mazeChoices += $"{i}: {inputFiles[i]}" + Environment.NewLine;
            }

            //Ask the user to pick a maze to solve
            Console.WriteLine(
                Environment.NewLine + "Hi!"
                + Environment.NewLine + "The following mazes are available to solve:" + Environment.NewLine
                + Environment.NewLine + mazeChoices
                + Environment.NewLine + "Please enter the number of the maze you'd like to solve..."
                );

            if (int.TryParse(Console.ReadLine(), out mazeFileNumber))
            {
                if (mazeFileNumber < inputFiles.Count)
                {
                    //Try to solve selected maze
                    mazeToSolve = MazeFile.Parse(inputFiles[mazeFileNumber]);
                    Console.WriteLine(Environment.NewLine + $"Attempting to solve {mazeToSolve.Label} with the following layout:");
                    Console.WriteLine(Environment.NewLine + mazeToSolve.GetLayoutString());

                    MazeSolver solver   = new MazeSolver(mazeToSolve);
                    Maze       solution = solver.Solve();

                    if (solution.IsSolved)
                    {
                        Console.WriteLine(Environment.NewLine + "Maze solved:");
                        solution.PrettyPrint();
                    }
                    else
                    {
                        Console.WriteLine(Environment.NewLine + "Maze not solveable.");
                    }

                    Console.WriteLine(Environment.NewLine + "Press any key to exit...");
                    Console.ReadLine();
                }
                else
                {
                    Console.WriteLine(Environment.NewLine + $"{mazeFileNumber} is not a valid option.");
                    Console.WriteLine(Environment.NewLine + "Press any key to exit...");
                    Console.ReadLine();
                    return;
                }
            }
            else
            {
                Console.WriteLine(Environment.NewLine + "Invalid input.");
                Console.WriteLine(Environment.NewLine + "Press any key to exit...");
                Console.ReadLine();
                return;
            }
        }
Ejemplo n.º 54
0
 public void AddMaze(string name, Maze maze)
 {
     mazes.Add(name, maze);
 }
Ejemplo n.º 55
0
 public void SolveMaze(Maze maze, string name)
 {
     RunOfSolution(maze, name);
 }
    void placePlayerAtMazeStart(Maze <gridCell> maze, float offset, GameObject player)
    {
        int randRow = rng.Next(0, maze.cols - 1);

        player.transform.position = new Vector3(0 - offset, randRow * sizeOfCells - offset - (sizeOfCells / 2), 0);
    }
Ejemplo n.º 57
0
 public Maybe <GraphMove> Run(Maze maze)
 {
     return(maze.ShortestPathToEndpoint.Value.Select(path => new GraphMove(fromNode: path[0], toNode: path[1])));
 }
    public void mapMazeToWallObjects(Maze <gridCell> maze)
    {
        float      xSize    = sizeOfCells;
        float      ySize    = sizeOfCells / 5;
        float      cellSize = sizeOfCells;
        GameObject wall     = new GameObject("wall");

        wall.AddComponent <SpriteRenderer>();
        SpriteRenderer renderer = wall.GetComponent <SpriteRenderer>();

        renderer.sprite           = Resources.Load <Sprite>("Wall");
        renderer.color            = Color.black;
        renderer.sortingOrder     = 1;
        wall.transform.localScale = new Vector3(xSize, ySize, 1);
        // wall.AddComponent<Rigidbody2D>();
        wall.AddComponent <BoxCollider2D>();
        //  Rigidbody2D rigidBody = wall.GetComponent<Rigidbody2D>();
        BoxCollider2D collider = wall.GetComponent <BoxCollider2D>();
        // rigidBody.mass = 1000000f;
        //  rigidBody.gravityScale = 0f;
        float offset = 4;

        Physics2D.IgnoreCollision(collider, collider);
        wall.AddComponent <StormWall>();
        for (int row = 0; row < maze.rows; row++)
        {
            for (int col = 0; col < maze.cols; col++)
            {
                if (maze.cellMatrix[row, col].northWall)
                {
                    Vector3 topLeftPosition = new Vector3(col * cellSize - offset, row * cellSize - offset, 0);
                    wall.transform.position = topLeftPosition;
                    Quaternion rot = Quaternion.Euler(0, 0, 0);
                    wall.transform.rotation = rot;
                    Instantiate(wall);
                }
                if (maze.cellMatrix[row, col].eastWall)
                {
                    Vector3 topLeftPosition = new Vector3(col * cellSize - offset + (cellSize / 2), row * cellSize - offset - (cellSize / 2), 0);
                    wall.transform.position = topLeftPosition;
                    Quaternion rot = Quaternion.Euler(0, 0, 90);
                    wall.transform.rotation = rot;
                    Instantiate(wall);
                }
                if (maze.cellMatrix[row, col].southWall && row == 0)
                {
                    Vector3 topLeftPosition = new Vector3(col * cellSize - offset, (row - 1) * cellSize - offset, 0);
                    wall.transform.position = topLeftPosition;
                    Quaternion rot = Quaternion.Euler(0, 0, 0);
                    wall.transform.rotation = rot;
                    Instantiate(wall);
                }
                if (maze.cellMatrix[row, col].westWall && col == 0)
                {
                    Vector3 topLeftPosition = new Vector3(col * cellSize - offset - (cellSize / 2), row * cellSize - offset - (cellSize / 2), 0);
                    wall.transform.position = topLeftPosition;
                    Quaternion rot = Quaternion.Euler(0, 0, 90);
                    wall.transform.rotation = rot;
                    Instantiate(wall);
                }
            }
        }
    }
Ejemplo n.º 59
0
 private void BeginGame()
 {
     this.MazeInstance = GameObject.Instantiate(this.MazePrefab) as Maze;
     StartCoroutine(this.MazeInstance.Generate(this.PlayerPrefab, 1));
 }
Ejemplo n.º 60
0
    // Update is called once per frame
    void Update()
    {
        if (m == null)
        {
            m = gen.currentMaze();
            RandomPlacement();
        }
        if (isLocalPlayer)
        {
            if (!setup)
            {
                gameObject.tag = "MyPlayer";
                SpriteObj.SetActive(false);
                CamHolder.SetActive(true);
            }

#if UNITY_ANDROID
            if (Input.touches.Length > 0)
            {
                Touch t = Input.GetTouch(0);
                if (t.phase == TouchPhase.Began)
                {
                    //save began touch 2d point
                    firstPressPos = new Vector2(t.position.x, t.position.y);
                }

                if (t.phase == TouchPhase.Ended)
                {
                    //save ended touch 2d point
                    secondPressPos = new Vector2(t.position.x, t.position.y);

                    //create vector from the two points
                    currentSwipe = new Vector3(secondPressPos.x - firstPressPos.x, secondPressPos.y - firstPressPos.y);

                    //normalize the 2d vector
                    currentSwipe.Normalize();

                    //swipe upwards
                    if (currentSwipe.y > 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                    {
                        //Debug.Log("up swipe");
                        CmdDoMovement(true, false, false, false);
                    }
                    //swipe down
                    if (currentSwipe.y < 0 && currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                    {
                        //Debug.Log("down swipe");
                        CmdDoMovement(false, true, false, false);
                    }
                    //swipe left
                    if (currentSwipe.x < 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                    {
                        //Debug.Log("left swipe");
                        CmdDoMovement(false, false, true, false);
                    }
                    //swipe right
                    if (currentSwipe.x > 0 && currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                    {
                        //Debug.Log("right swipe");
                        CmdDoMovement(false, false, false, true);
                    }
                }
                CheckSeen();
            }
#endif


            bool up    = Input.GetKeyDown(KeyCode.UpArrow);
            bool down  = Input.GetKeyDown(KeyCode.DownArrow);
            bool left  = Input.GetKeyDown(KeyCode.LeftArrow);
            bool right = Input.GetKeyDown(KeyCode.RightArrow);
            if (up || down || left || right)
            {
                Debug.Log("Move Command");
                CmdDoMovement(up, down, left, right);
            }
            CheckSeen();
        }
        else
        {
            if (!setup)
            {
                gameObject.tag = "OtherPlayer";
                SpriteObj.SetActive(true);
            }
        }

        if (isLocalPlayer && Input.GetKeyDown(KeyCode.Space))       // || Input.GetKeyDown(KeyCode.Mouse0))
        {
            CmdShoot();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            GameObject   obj = GameObject.Find("NetworkManager");
            NetworkLogic log = obj.GetComponent <NetworkLogic>();
            log.StopHost();
            log.StopClient();
            SceneManager.LoadScene(0);
        }
    }