コード例 #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();
        }
コード例 #2
0
 /// <summary>
 /// Handles the current game state
 /// </summary>
 /// <param name="gameState"></param>
 public void CurrentGameState(Game.GameState gameState)
 {
     Game.TheGameState = gameState;
     if (gameState == Game.GameState.Lost)
     {
         frmGameOver gameOver = new frmGameOver();
     }
 }
コード例 #3
0
        private void btnAttack_Click(object sender, RoutedEventArgs e)
        {
            Game.Map.Adventurer.DamageMe(Game.Map.CurrentLocation.Monster.AttackValue);
            bool   fight = Game.Map.Adventurer + Game.Map.CurrentLocation.Monster;
            Window wnd   = null;

            if (Game.Map.Adventurer.IsAlive == false)
            {
                Game.GameState = Game.State.Lost;
                wnd            = new frmGameOver();
                wnd.Show();
                this.Close();
            }
            else if (Game.Map.CurrentLocation.Monster.IsAlive == false)
            {
                Game.Map.Cells[Game.Map.Adventurer.PositionY, Game.Map.Adventurer.PositionX].Monster = null;
                this.Close();
            }
            else
            {
                FighterUpdate();
            }
        }
コード例 #4
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();
            }
        }