Beispiel #1
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();
        }
Beispiel #2
0
        /// <summary>
        /// Displays either the monster, item, or game over form depending on what was encountered
        /// </summary>
        /// <remarks>
        /// Display an image using a BitmapImage: https://stackoverflow.com/questions/6503424/how-to-programmatically-set-the-image-source
        /// </remarks>
        private void DisplayForm()
        {
            // Gets the hero's position
            MapCell currentLocationOfHero = Game.Map.CurrentPositionOfHero(Game.Map.Adventurer);

            // Displays the item form when an item is found
            if (currentLocationOfHero.Item != null || currentLocationOfHero.DoorKey != null)
            {
                frmItem itemForm = new frmItem();
            } // Displays the monster form when encountering a monster
            else if (currentLocationOfHero.Monster != null)
            {
                frmMonster monsterForm = new frmMonster();
            } // Displays the game over form when encountering a door
            else if (currentLocationOfHero.Door != null)
            {
                if (Game.Map.Adventurer.HasKey)
                {
                    CurrentGameState(Game.GameState.Won);
                }
                frmGameOver gameOver = new frmGameOver();
            }
        }