public void FindSolution (Maze maze) { _solutionFound = false; _cycleFound = false; _visited.Clear(); _robot.Location = maze.StartRoom; Explore(null,maze.StartRoom); _solutionFound = _visited.Contains(maze.FinishRoom); _roomsConnected = _visited.Count; }
public Maze CreateMaze() { Maze aMaze = new Maze(); Room r1 = new Room(1); Room r2 = new Room(2); Door theDoor = new Door(r1, r2); aMaze.AddRoom(r1); aMaze.AddRoom(r2); r1.SetSide(Direction.North, new Wall()); r1.SetSide(Direction.East, theDoor); r1.SetSide(Direction.South, new Wall()); r1.SetSide(Direction.West, new Wall()); r2.SetSide(Direction.North, new Wall()); r2.SetSide(Direction.East, new Wall()); r2.SetSide(Direction.South, new Wall()); r2.SetSide(Direction.West, theDoor); return aMaze; }
/// <summary> /// Update the enemy location depending on AI logic and play sound effects /// </summary> /// <param name="gameTime">Snapshot of game timing state</param> /// <param name="maze">The maze the enemy is in</param> /// <param name="listener">The listener to enemy's footstep sound effect and music</param> /// <param name="music">The music that the enemy objec will be effecting depends on distance to the listener</param> public void Update(GameTime gameTime, Maze maze, AudioListener listener, SoundEffectInstance music) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Vector3 moveAmount = Vector3.Zero; // first we looking into future time so that enemy won't walk into walls moveAmount.Z += MOVE_SCALE * elapsedTime * PREVIEW_FRAMES; Vector3 newLocation = PreviewMove(moveAmount); willCollide = false; foreach (BoundingBox box in maze.GetBoundsForCell((int)newLocation.X, (int)newLocation.Z)) { if (box.Contains(newLocation) == ContainmentType.Contains) { willCollide = true; } } // if walking stright will collide with wall, try turning left if ( willCollide ) { // try turn left Direction = (Direction + 1) % 4; moveAmount = Vector3.Zero; moveAmount.Z += MOVE_SCALE * elapsedTime * PREVIEW_FRAMES; newLocation = PreviewMove(moveAmount); willCollide = false; foreach (BoundingBox box in maze.GetBoundsForCell((int)newLocation.X, (int)newLocation.Z)) { if (box.Contains(newLocation) == ContainmentType.Contains) { willCollide = true; } } } // if turn left fails, try opposite direction (turn right from original direction) if ( willCollide ) { // try turn right Direction = (Direction + 2) % 4; moveAmount = Vector3.Zero; moveAmount.Z += MOVE_SCALE * elapsedTime * PREVIEW_FRAMES; newLocation = PreviewMove(moveAmount); willCollide = false; foreach (BoundingBox box in maze.GetBoundsForCell((int)newLocation.X, (int)newLocation.Z)) { if (box.Contains(newLocation) == ContainmentType.Contains) { willCollide = true; } } } // if still going to collide, make a u-turn if ( willCollide ) { // try walk backward Direction = (Direction + 3) % 4; moveAmount = Vector3.Zero; moveAmount.Z += MOVE_SCALE * elapsedTime * PREVIEW_FRAMES; newLocation = PreviewMove(moveAmount); willCollide = false; foreach (BoundingBox box in maze.GetBoundsForCell((int)newLocation.X, (int)newLocation.Z)) { if (box.Contains(newLocation) == ContainmentType.Contains) { willCollide = true; } } } // Animate legs movement if (isLeftLegForward) { leftLegRotation -= LEG_ROTATION_SCALE; rightLegRotation += LEG_ROTATION_SCALE; } else { rightLegRotation -= LEG_ROTATION_SCALE; leftLegRotation += LEG_ROTATION_SCALE; } // reset move amount to just timing the elapsed time instead of a future time moveAmount = Vector3.Zero; moveAmount.Z += MOVE_SCALE * elapsedTime; newLocation = PreviewMove(moveAmount); Apply3DAudio(listener, newLocation, music); position = newLocation; }
/// <summary> /// Initialize game variables/objects /// </summary> protected override void Initialize() { // Setup window Window.Title = "MazeGame"; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; graphics.IsFullScreen = false; graphics.ApplyChanges(); SoundEffect.DistanceScale = 1; SoundEffect.DopplerScale = 0.1f; // initialise sound for camera wallCollisionAudio = Content.Load<SoundEffect>("Sounds/wallcollision_sound"); // Other variables to initialize maze = new Maze(GraphicsDevice); // Set default feature states fog = false; ambient = true; skyColor = Color.DeepSkyBlue; listener = new AudioListener(); base.Initialize(); }
public DrawContext (Maze m) { _maze = m; }
public void Traverse (Maze maze) { //RectangleF bounds = g.VisibleClipBounds; //Point a = new Point((int)bounds.Width/2, (int)bounds.Height/2); //DrawRoom(maze.AnchorRoom); }
private void SaveMaze (Maze m) { Stream f = File.Create(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)+@"\SavedMaze.dat"); BinaryFormatter serializer = new BinaryFormatter(); serializer.Serialize(f,m); }
public void Update(GameTime gameTime, Maze maze, AudioListener listener) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; wallCollisionElapsedTime += gameTime.ElapsedGameTime.Milliseconds; footStepElapsedTime += (float)gameTime.ElapsedGameTime.TotalMilliseconds; // Restrain movement to the maze width and height if (moveAmount.Z != 0 || moveAmount.X != 0) { Vector3 newLocation = PreviewMove(moveAmount); bool moveOk = true; if (newLocation.X < 0 || newLocation.X > Maze.MAZE_WIDTH) moveOk = false; if (newLocation.Z < 0 || newLocation.Z > Maze.MAZE_HEIGHT) moveOk = false; // Handle Collision based on bounding box if (collision) foreach (BoundingBox box in maze.GetBoundsForCell((int)newLocation.X, (int)newLocation.Z)) { if (box.Contains(newLocation) == ContainmentType.Contains) { moveOk = false; // check to play wall sounds if wallsound is true and there is a delap. dealys stops constant looping if (wallSound && wallCollisionElapsedTime > WALL_COLLISION_DELAY) { wallCollisionSound.Play(); wallSound = false; // reset elapsedTime to provide a delay wallCollisionElapsedTime = 0; } } else { // enable sounds again wallSound = true; } } // if no collision and ok to move the move and play footstep sound if (moveOk) { MoveForward(moveAmount); listener.Velocity = (newLocation - position) / elapsedTime; // Play footstep sounds if (footStepElapsedTime > FOOT_STEP_DELAY) { if (footsteps) leftFootstepSound.Play(); else rightFootstepSound.Play(); footsteps = !footsteps; footStepElapsedTime = 0; } } else { listener.Velocity = Vector3.Zero; } } else { listener.Velocity = Vector3.Zero; } listener.Position = Position; listener.Up = View.Up; listener.Forward = View.Forward; }
public void Traverse (Maze maze, IMapSiteAction action) { _action = action; Visit(maze.StartRoom); }
public void SetMazePointer(Maze maz) { mz = maz; }
private void MazeGame_Load(object sender, EventArgs e) { this.WindowState = FormWindowState.Maximized; //player = new Player(this.DisplayRectangle); maze = new Maze(this.DisplayRectangle); }