示例#1
0
        /// <summary>
        /// Moves the Hero (player) based on direction and neighbours
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="direction"></param>
        public override void Move(Tile tile, Tile.Neighbours direction)
        {
            if (!(tile._HasNeighbours.ContainsKey(direction)))
            {
                // check if the requested move is posible, so borders work
                return;
            }
            else if (tile._HasNeighbours[direction].SpriteObject is null)
            {
                // Sets the new neighbour tile to  hero
                tile._HasNeighbours[direction].SpriteObject = tile.SpriteObject;

                // Sets the hero's last tile visited to null
                tile.SpriteObject = null;

                // Updates the  hero's Tile
                ObjectGameBox = tile._HasNeighbours[direction];
            }
            else if (tile._HasNeighbours[direction].SpriteObject is Enemy)
            {
                // Check if the requested move is enemy tile

                // Sets the enemy' being alive status to false
                tile.SpriteObject.CheckAlifeStatus = false;

                //set hero to death image
                SpriteImage = Properties.Resources.death_5;
                // Stop the movement
                return;
            }
            else if (tile._HasNeighbours[direction].SpriteObject != null)
            {
                tile._HasNeighbours[direction].SpriteObject.Move(tile, direction);
                return;
            }
            else
            {
                // an error as occured, this else is used to catch the error to prevent crashing the game
                Console.WriteLine("An error has occured while moving the hero");
                return;
            }
        }
示例#2
0
 /// <summary>
 /// This abstract move function is used by all child classes  
 ///  if the SpriteObject doesn't move this function can be empty
 /// </summary>
 /// <param name="tile"></param>
 /// <param name="direction"></param>
 public abstract void Move(Tile tile, Tile.Neighbours direction);
示例#3
0
        /// <summary>
        /// Calls the function hero move when the key is down
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Game_KeyDown(object sender, KeyEventArgs e)
        {
            // Makes a local variable to declare direcion
            Tile.Neighbours direction = Tile.Neighbours.B;

            // Switches the input to decide what to do with it
            // arrow key(left right up down) is used to delcare direction(North, South, West, East),
            //the keys are used in the _hasNeighbour dictonary
            switch (e.KeyCode)
            {
            case Keys.F12:
                // Resets the game and stops the event
                ResetGame();
                return;

            case Keys.P:
                // Pauzes or unpauzes the game and stops the event
                GamePause();
                return;

            case Keys.Left:
                //moving hero left of the screen
                direction = Tile.Neighbours.W;
                //sets hero img to the left
                _callHeroClass.SpriteImage = Properties.Resources.Nleft;
                break;

            case Keys.Right:
                //moving hero right of the screen
                direction = Tile.Neighbours.E;
                //sets hero img to the right
                _callHeroClass.SpriteImage = Properties.Resources.Nright;
                break;

            case Keys.Up:
                //moving hero to the top side of the screen
                direction = Tile.Neighbours.N;
                break;

            case Keys.Down:
                //moving hero to the down side of of the screen
                direction = Tile.Neighbours.S;
                break;

            default:
                return;
            }

            // Checks if the game is paused we return the keydown events so nothing happens
            if (Pause)
            {
                return;
            }
            else
            {
                //otherswise eachtime the key down is pressed highscore is added +1
                _highScore += 1;
                //setting the variable highscore to the labelhighscore
                lblHighScore.Text = _highScore.ToString();
            }

            // Calls the Hero's move function
            _callHeroClass.Move(_callHeroClass.ObjectGameBox, direction);
            // Draws the board on screen
            DrawBoardOnScreen();
            // Checks if the player has won the game or lost the game
            IsAnyoneAlive();
        }
示例#4
0
        /// <summary>
        /// Moves the box based on its neighbours
        /// </summary>
        /// <param name="tile"></param>
        /// <param name="direction"></param>
        public override void Move(Tile tile, Tile.Neighbours direction)
        {
            // Local gamebox for use in the loop
            Tile AnotherGameBoX = tile;

            // while the CheckAliveStatus is false we continue checking the neighbours and tiles
            while (CheckAlifeStatus == false)
            {
                if (!(AnotherGameBoX._HasNeighbours[direction]._HasNeighbours.ContainsKey(direction)))
                {
                    // Checks if the the tile after the first box exists
                    return;
                }

                if (!AnotherGameBoX._HasNeighbours[direction].SpriteObject.PushWall)
                {
                    // Prevents steel box pushing
                    return;
                }

                if (AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction].SpriteObject is null)
                {
                    // If the the last position in the row is a box it will patch up the last object movement

                    // Moves the box before the last one to the last position
                    AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction].SpriteObject = AnotherGameBoX._HasNeighbours[direction].SpriteObject;

                    // Moves the Hero to the next position
                    tile._HasNeighbours[direction].SpriteObject = tile.SpriteObject;

                    // Sets the Hero's origninal gamebox to null
                    tile.SpriteObject = null;

                    // Updates the Hero's gamebox
                    tile._HasNeighbours[direction].SpriteObject.ObjectGameBox = tile._HasNeighbours[direction];

                    // this ends the loop
                    break;
                }

                if (!AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction].SpriteObject.PushWall)
                {
                    // Prevents water box pushing
                    return;
                }

                else if (AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction].SpriteObject is Box)
                {
                    // If there is a box in the way it will update the GameBoxRecusie

                    // Checks if the move after the new box is possible,  otherwise it will stop the movement
                    if (!(AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction]._HasNeighbours.ContainsKey(direction)))
                    {
                        return;
                    }

                    // Moves the box to its new position
                    AnotherGameBoX._HasNeighbours[direction]._HasNeighbours[direction].SpriteObject = AnotherGameBoX._HasNeighbours[direction].SpriteObject;

                    // Updates the AnotherGameBoX to the next one
                    AnotherGameBoX = AnotherGameBoX._HasNeighbours[direction];
                }
                else
                {
                    // if an object is discoverd with no relation to box moving, it will stop the movement
                    return;
                }
            }
        }