/// <summary>
 /// Checks if there is anything in the current map call and displays the correct window if there is anything present.
 /// </summary>
 private void CheckMapCell()
 {
     // Show game over dialog if current position has a door.
     if (Game.Map.GetCurrentPosition().HasItem&& Game.Map.GetCurrentPosition().Item.GetType() == typeof(Door))
     {
         frmGameOver frmGameOver = new frmGameOver();
         frmGameOver.ShowDialog();
         // Show item dialog if current position has an item.
     }
     else if (Game.Map.GetCurrentPosition().HasItem)
     {
         frmItem frmItem = new frmItem();
         frmItem.ShowDialog();
         // Show monster dialog if current position has a monster.
     }
     else if (Game.Map.GetCurrentPosition().HasMonster)
     {
         monsterEncounter = new MediaPlayer();
         // Music retrieved from: https://soundimage.org/
         monsterEncounter.Open(new Uri(@"assets/MonsterEncounter.wav", UriKind.Relative));
         monsterEncounter.Play();
         frmMonster frmMonster = new frmMonster();
         frmMonster.ShowDialog();
     }
 }
예제 #2
0
        /// <summary>
        /// Button that allows player to run away from monster instead of fighting.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRunAway_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
            hero.IsRunningAway = true;
            bool heroIsAlive = hero + monster;

            // Game is lost if hero dies when trying to run away.
            if (heroIsAlive != true)
            {
                Game.GameState = Game.GameStates.Lost;
                this.Close();
                frmGameOver frmGameOver = new frmGameOver();
                frmGameOver.ShowDialog();
            }
            else
            {
                // hero takes some damage becaue of slower speed.
                frmRunAway frmRunAway = new frmRunAway();
                frmRunAway.ShowDialog();
                hero.IsRunningAway = false;
                this.Close();
            }
        }
예제 #3
0
        /// <summary>
        /// Uses overloaded + operator to make the monster and the hero fight.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAttack_Click(object sender, RoutedEventArgs e)
        {
            bool heroIsAlive = hero + monster;

            tbHero.Text    = hero.Name + "\r\n" + hero.CurrentHitPoints + "/" + hero.MaxHitPoints;
            tbMonster.Text = monster.Name + "\r\n" + monster.CurrentHitPoints + "/" + monster.MaxHitPoints;
            hitSound       = new MediaPlayer();
            // Sound retrieved from: https://soundimage.org/
            hitSound.Open(new Uri(@"assets/KnifeStab.wav", UriKind.Relative));
            hitSound.Play();
            if (heroIsAlive != true)
            {
                Game.GameState = Game.GameStates.Lost;
                this.Close();
                frmGameOver frmGameOver = new frmGameOver();
                frmGameOver.ShowDialog();
            }
            else if (monster.IsAlive != true)
            {
                Game.Map.GameBoard[hero.PositionY, hero.PositionX].Monster = null;
                this.Close();
            }
        }