/// <summary>
 /// Checks if player can no longer win
 /// </summary>
 /// <param name="currentChest">Current chest</param>
 /// <param name="chestCost">Cost of opening chest</param>
 /// <param name="keysCost">Cost of buying keys</param>
 /// <returns>True if player can no longer win/false otherwise</returns>
 public bool IsPlayerDead(UniversalChest currentChest, int chestCost, int keysCost)
 {
     if (currentChest == null && chestCost > Gold)
     {
         return(true);
     }
     if (currentChest != null && currentChest.KeysRequired > Keys && keysCost > Gold)
     {
         return(true);
     }
     return(false);
 }
Exemple #2
0
        /// <summary>
        /// Execute a command written by a player
        /// </summary>
        /// <param name="command">command</param>
        private void ParseKeyword(string command)
        {
            switch (command)
            {
            case "find":
                if (!Player.CanFindNewChest(SearchForChestCost))
                {
                    Console.Write("You don't have enough gold, just concede!");
                }
                else
                {
                    Chest = Player.FindNewChest(SearchForChestCost);
                    Chest.PrintInfo();
                }
                break;

            case "open":
                if (Chest == null)
                {
                    Console.Write("You don't have any chest left to open, try 'find'.");
                }
                else if (!Player.CanOpenChest(Chest.KeysRequired))
                {
                    Console.Write("You don't have enough keys, just concede!");
                }
                else
                {
                    Player.OpenChest(Chest.KeysRequired, Chest.Gold);
                    Console.Write("You have gained {0} gold.\n", Chest.Gold);
                    Chest = null;
                    PrintPlayerInfo();
                }
                break;

            case "buy":
                if (!Player.CanBuyKeys(BuyNewKeysCost))
                {
                    Console.Write("Not enough gold.");
                }
                else
                {
                    Player.BuyKeys(NumberOfKeysToBuy, BuyNewKeysCost);
                    PrintPlayerInfo();
                }
                break;

            case "info":
                PrintPlayerInfo();
                break;

            case "win":
                if (Player.TryToWin(GoldNeededToWin))
                {
                    Console.Write("You won!");
                }
                else
                {
                    Console.Write("Not enough gold.");
                }
                break;

            default:
                Console.Write("Invalid command.");
                break;
            }
        }