Ejemplo n.º 1
0
 public Traveler()
 {
     location = new TravelerLocation();
 }
Ejemplo n.º 2
0
        public MazeCycleOutcome CycleMaze(int direction)
        {
            MazeCycleOutcome outcome = new MazeCycleOutcome();

            outcome.BumpedIntoWall   = false;
            outcome.GameOver         = false;
            outcome.FinalScore       = 0;
            outcome.PreviousLocation = new Location()
            {
                X = traveler.location.X, Y = traveler.location.Y
            };

            TravelerLocation new_location = new TravelerLocation();

            outcome.Moves = Moves++;
            //Calculate new location
            switch (direction)
            {
            case 0:
                if (traveler.location.Y <= 0)
                {
                    //OutOfBoundsOccurred();
                    BumpIntoWall           = true;
                    outcome.BumpedIntoWall = true;
                    return(outcome);
                }
                new_location.X = traveler.location.X;
                new_location.Y = traveler.location.Y - 1;
                break;

            case 1:
                if (traveler.location.X >= Width - 1)
                {
                    //OutOfBoundsOccurred();
                    BumpIntoWall           = true;
                    outcome.BumpedIntoWall = true;
                    return(outcome);
                }
                new_location.X = traveler.location.X + 1;
                new_location.Y = traveler.location.Y;
                break;

            case 2:
                if (traveler.location.Y >= Height - 1)
                {
                    //OutOfBoundsOccurred();
                    BumpIntoWall           = true;
                    outcome.BumpedIntoWall = true;
                    return(outcome);
                }
                new_location.X = traveler.location.X;
                new_location.Y = traveler.location.Y + 1;
                break;

            case 3:
                if (traveler.location.X <= 0)
                {
                    //OutOfBoundsOccurred();
                    BumpIntoWall           = true;
                    outcome.BumpedIntoWall = true;
                    return(outcome);
                }
                new_location.X = traveler.location.X - 1;
                new_location.Y = traveler.location.Y;
                break;

            default:
                throw new Exception("Not valid input");
            }


            //Is BumpedIntoWall?
            if (this.TheMazeGrid[new_location.X, new_location.Y])
            {
                BumpIntoWall           = true;
                outcome.BumpedIntoWall = true;
                outcome.FinalScore     = 0;
                outcome.GameOver       = false;
                //Play sound
                //SystemSounds.Hand.Play();
                return(outcome);
            }

            //New location is now current location
            //TravelerLocation old_location = traveler.location;
            OldLocation       = traveler.location;
            traveler.location = new_location;

            //Is GameOver?
            if (traveler.location.X == GoalLocation.X && traveler.location.Y == GoalLocation.Y)
            {
                outcome.GameOver = true;
                return(outcome);
            }

            return(outcome);
        }
Ejemplo n.º 3
0
 public virtual bool BumpedIntoObject(TravelerLocation location)
 {
     return(this.TheMazeGrid[location.X, location.Y]);
 }