public virtual bool Attack(IMonsterable monster)
        {
            if (!monster.Defend(Strength))
            {
                Score += Strength;
                return(true);
            }

            return(false);
        }
 public static void EndOfRoundStats(UserPlayer user, AIPlayer computer, IMonsterable monster)
 {
     Console.WriteLine();
     Console.WriteLine("~~~~END OF ROUND STATISTICS~~~~");
     Console.WriteLine();
     Console.WriteLine("Your health: " + user.Health + " HP");
     Console.WriteLine("Your score: " + user.Score + " points");
     Console.WriteLine("Opponent's health: " + computer.Health + " HP");
     Console.WriteLine("Opponent's score: " + computer.Score + " points");
     Console.WriteLine("Monster's health: " + monster.Health + " HP");
 }
Beispiel #3
0
 public override bool Attack(IMonsterable monster)
 {
     Console.WriteLine();
     Console.WriteLine("Your opponent is attacking the monster");
     try
     {
         if (base.Attack(monster))
         {
             Console.WriteLine("Your opponent hit the monster! " + Strength + " points to them!");
             monster.PrintMonsterHealth();
             return(true);
         }
     }
     catch (MonsterDiedException)
     {
         throw new AIKilled();
     }
     Console.WriteLine("Your opponent misses the monster");
     return(false);
 }
Beispiel #4
0
 public override bool Attack(IMonsterable monster)
 {
     Console.WriteLine();
     Console.WriteLine("You are attacking the monster");
     try
     {
         if (base.Attack(monster))
         {
             Console.WriteLine("You hit the monster! He loses " + Strength + " HP");
             Console.WriteLine("You have been awarded " + Strength + " points");
             return(true);
         }
         Console.WriteLine("The monster deflects your shot and sustains no damage");
     }
     catch (MonsterDiedException)
     {
         throw new UserKilled();
     }
     return(false);
 }
Beispiel #5
0
        public static bool PlayGame()
        {
            int        delayConstant  = 0; // 1000 (1 sec) default, reduce for testing purposes
            UserPlayer userPlayer     = new UserPlayer();
            AIPlayer   computerPlayer = new AIPlayer();

            Console.WriteLine();
            Console.WriteLine("Ready to start? [y/n]");
            string userInput = Console.ReadLine();

            if (userInput.Equals("y"))
            {
                try
                {
                    IMonsterable m = MonsterGenerator.GenerateMonster();
                    while (userPlayer.Health > 0 && computerPlayer.Health > 0 && m.Health > 0)
                    {
                        userPlayer.UserPicksTypeOfCard();
                        Thread.Sleep(delayConstant);
                        computerPlayer.AIPicksTypeOfCard();
                        Thread.Sleep(delayConstant);
                        m.PickPlayerToAttack(userPlayer, computerPlayer);

                        Thread.Sleep(delayConstant);
                        userPlayer.Attack(m);
                        Thread.Sleep(delayConstant);
                        computerPlayer.Attack(m);
                        Thread.Sleep(delayConstant);

                        Menus.EndOfRoundStats(userPlayer, computerPlayer, m);
                    }
                }
                catch (UserDiedException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("You lose!");
                    return(false);
                }
                catch (AIDiedException e)
                {
                    Console.WriteLine(e.Message);
                    Console.WriteLine("You win!");
                    return(true);
                }
                catch (UserKilled)
                {
                    Console.WriteLine("You killed the monster! You win!");
                    return(true);
                }
                catch (AIKilled)
                {
                    Console.WriteLine("Your opponent killed the monster! You lose!");
                    return(false);
                }
                catch (Exception)
                {
                    Console.WriteLine("An unhandled exception occurred");
                    Thread.Sleep(delayConstant);
                    CardDealer.ResetDealer();
                    PlayGame();
                }
            }
            else
            {
                Console.WriteLine("Sorry, this is not a game for quitters! ¯|_(ツ)_|¯");
                CardDealer.ResetDealer();
                PlayGame();
            }
            Console.ReadLine();
            return(false);
        }