예제 #1
0
        /// <summary>
        /// Move the adventuerer around the map. This method makes sure the user cannot
        /// go off of the map.
        /// </summary>
        /// <param name="dir">Direction the adventurer is expected to move.</param>
        /// <returns></returns>
        public bool MoveAdventurer(Actor.Direction dir)
        {
            int maxRow = Cells.GetUpperBound(0);
            int maxCol = Cells.GetUpperBound(1);

            Adventurer.Move(dir);
            // move hero back if he has left the board
            if (Adventurer.PositionX < 0)
            {
                Adventurer.Move(Actor.Direction.Right);
            }
            if (Adventurer.PositionX > maxCol)
            {
                Adventurer.Move(Actor.Direction.Left);
            }
            if (Adventurer.PositionY < 0)
            {
                Adventurer.Move(Actor.Direction.Down);
            }
            if (Adventurer.PositionY > maxRow)
            {
                Adventurer.Move(Actor.Direction.Up);
            }
            CurrentLocation.HasBeenSeen = true;
            return(CurrentLocation.HasItem || CurrentLocation.HasMonster);
        }
예제 #2
0
        private void btnMove_Click(object sender, RoutedEventArgs e)
        {
            Button btn = (Button)sender;

            Actor.Direction dir       = (Actor.Direction)btn.Tag;
            bool            needToAct = Game.Map.MoveAdventurer(dir);

            if (needToAct)
            {
                Window wnd = null;
                if (Game.Map.CurrentLocation.HasItem)
                {
                    wnd = new frmItem();
                }
                if (Game.Map.CurrentLocation.Item is Door)
                {
                    Game.GameState = Game.State.Won;
                    wnd            = new frmGameOver();
                }
                else if (Game.Map.CurrentLocation.HasMonster)
                {
                    wnd = new frmMonster();
                }
                if (wnd != null)
                {
                    wnd.ShowDialog();
                }
            }
            DrawMap();
        }
예제 #3
0
        /// <summary>
        /// Moves the hero one cell in the specified direction, unless that movement would move him off the gameboard.
        /// </summary>
        /// <param name="direction">The direction the hero will move. Use Actor.Direction or Hero.Direction enums.</param>
        /// <returns>returns true if the hero needs to act (new cell has monster or item). return false if the cell is empty. </returns>
        public bool moveHero(Actor.Direction direction)
        {
            // mark old cell as discovered and visible, before hero leaves it.
            HeroLocation.IsVisible = true;

            int x = Hero.XPos;
            int y = Hero.YPos;

            if (direction == Actor.Direction.Up && y - 1 >= 0) // if told to go up, and hero is not at top of gameboard,
            {
                Hero.move(Actor.Direction.Up);                 // move hero up.
            }
            else if (direction == Actor.Direction.Down && y + 1 <= GameBoard.GetUpperBound(0))
            { // if told to go down, and hero is not at bottom of gameboard, move hero down.
                Hero.move(Actor.Direction.Down);
            }
            else if (direction == Actor.Direction.Left && x - 1 >= 0)
            { // if told to go left, and hero is not at left edge of gameboard, move hero left.
                Hero.move(Actor.Direction.Left);
            }
            else if (direction == Actor.Direction.Right && x + 1 <= GameBoard.GetUpperBound(1))
            { // if told to go right, and hero is not at right edge of gameboard, move hero right.
                Hero.move(Actor.Direction.Right);
            }
            //// hero has been moved. mark new cell as discovered and visible.
            //HeroLocation.IsVisible = true;

            // return true if hero needs to act (new location has monster or item). return false if the cell is empty.
            return(HeroLocation.HasItem || HeroLocation.HasMonster);
        }
예제 #4
0
파일: Map.cs 프로젝트: gautsaur/wanna-die
        /// <summary>
        /// Moves hero in the map
        /// </summary>
        /// <param name="heroDir">direction that hero moves</param>
        /// <returns>if Location has anything or not</returns>
        public bool MoveHero(Actor.Direction heroDir)
        {
            int Xaxis = Cells.GetLength(1);
            int Yaxis = Cells.GetLength(0);

            Adventurer.Move(heroDir);

            //if hero goes outside the map, it decrease that value of positions by 1
            if (Adventurer.PositionX < 0)
            {
                Adventurer.Move(Actor.Direction.Right);
            }
            if (Adventurer.PositionX > Xaxis)
            {
                Adventurer.Move(Actor.Direction.Left);
            }
            if (Adventurer.PositionY < 0)
            {
                Adventurer.Move(Actor.Direction.Down);
            }
            if (Adventurer.PositionY > Yaxis)
            {
                Adventurer.Move(Actor.Direction.Up);
            }
            CurrentLocation.HasBeenSeen = true;
            return(CurrentLocation.HasItem || CurrentLocation.HasMonster);
        }
예제 #5
0
        /// <summary>
        /// Moves Actor as long as it wont go off the GameMap. Returns true if the Hero enters a cell occupied by a Monster or Item
        /// </summary>
        public bool MoveHero(Actor.Direction dir)
        {
            if (dir == Actor.Direction.Up)
            {
                if (Adventurer.PositionY > 0)
                {
                    Adventurer.Move(Actor.Direction.Up);

                    Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true;
                }
            }

            if (dir == Actor.Direction.Down)
            {
                if (Adventurer.PositionY < 9)
                {
                    Adventurer.Move(Actor.Direction.Down);

                    Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true;
                }
            }

            if (dir == Actor.Direction.Left)
            {
                if (Adventurer.PositionX > 0)
                {
                    Adventurer.Move(Actor.Direction.Left);

                    Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true;
                }
            }

            if (dir == Actor.Direction.Right)
            {
                if (Adventurer.PositionX < 9)
                {
                    Adventurer.Move(Actor.Direction.Right);

                    Cells[Adventurer.PositionY, Adventurer.PositionX].HasBeenSeen = true;
                }
            }

            if (Cells[Adventurer.PositionY, Adventurer.PositionX].HasItem)
            {
                return(true);
            }

            if (Cells[Adventurer.PositionY, Adventurer.PositionX].HasMonster)
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
예제 #6
0
        /// <summary>
        /// Moves the actor in a direction without going off the board and returns true if that map cell has an item or a monster
        /// </summary>
        /// <param name="movement">direction the actor wants to move</param>
        /// <param name="actor">the actor that wants to move</param>
        /// <returns></returns>
        public bool Move(Actor.Direction movement, Actor actor)
        {
            int maxRow = _GameBoard.GetUpperBound(0);
            int maxCol = _GameBoard.GetUpperBound(1);

            // Move Left
            if (movement == Actor.Direction.Left)
            {
                if (actor.YCoordinate - 1 >= 0)
                {
                    actor.Move(Actor.Direction.Left);
                    _GameBoard[actor.XCoordinate, actor.YCoordinate + 1].IsDiscovered = true;
                }
            }
            // Move Right
            if (movement == Actor.Direction.Right)
            {
                if (actor.YCoordinate + 1 <= maxCol)
                {
                    actor.Move(Actor.Direction.Right);
                    _GameBoard[actor.XCoordinate, actor.YCoordinate - 1].IsDiscovered = true;
                }
            }
            // Move Up
            if (movement == Actor.Direction.Up)
            {
                if (actor.XCoordinate - 1 >= 0)
                {
                    actor.Move(Actor.Direction.Up);
                    _GameBoard[actor.XCoordinate + 1, actor.YCoordinate].IsDiscovered = true;
                }
            }
            // Move Down
            if (movement == Actor.Direction.Down)
            {
                if (actor.XCoordinate + 1 <= maxRow)
                {
                    actor.Move(Actor.Direction.Down);
                    _GameBoard[actor.XCoordinate - 1, actor.YCoordinate].IsDiscovered = true;
                }
            }
            // Checks if the new location requires the hero to act if the location contains a Item, Monster, DoorKey, or Door
            if (_GameBoard[actor.XCoordinate, actor.YCoordinate].Item != null ||
                _GameBoard[actor.XCoordinate, actor.YCoordinate].Monster != null ||
                _GameBoard[actor.XCoordinate, actor.YCoordinate].DoorKey != null ||
                _GameBoard[actor.XCoordinate, actor.YCoordinate].Door != null)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
예제 #7
0
파일: Map.cs 프로젝트: Bjcurty/C-Sharp
        public bool MoveHero(Actor.Direction dir)
        {
            Game.GameMap.Cells[Game.Adventurer.PositionX, Game.Adventurer.PositionY].HasBeenSeen = true;

            if (dir == Actor.Direction.Up)
            {
                if (Game.Adventurer.PositionY > 0)
                {
                    Game.Adventurer.Move(Actor.Direction.Up);
                }
            }

            if (dir == Actor.Direction.Down)
            {
                if (Game.Adventurer.PositionY < 10)
                {
                    Game.Adventurer.Move(Actor.Direction.Down);
                }
            }

            if (dir == Actor.Direction.Left)
            {
                if (Game.Adventurer.PositionX > 0)
                {
                    Game.Adventurer.Move(Actor.Direction.Left);
                }
            }

            if (dir == Actor.Direction.Right)
            {
                if (Game.Adventurer.PositionY < 8)
                {
                    Game.Adventurer.Move(Actor.Direction.Right);
                }
            }

            if ((Game.GameMap.Cells[Game.Adventurer.PositionX, Game.Adventurer.PositionY].HasBeenSeen && Game.GameMap.Cells[Game.Adventurer.PositionX, Game.Adventurer.PositionY].Monster != null) ||
                (Game.GameMap.Cells[Game.Adventurer.PositionX, Game.Adventurer.PositionY].HasBeenSeen && Game.GameMap.Cells[Game.Adventurer.PositionX, Game.Adventurer.PositionY].Item != null))
            {
                return(true);
            }

            else
            {
                return(false);
            }
        }
예제 #8
0
 /// <summary>
 /// Move the hero.
 /// </summary>
 /// <param name="dirToMove">Direction the hero will move.</param>
 public override void Move(Actor.Direction dirToMove)
 {
     base.Move(dirToMove);
 }