Ashanmaril

Bum Simulator update Nov 09, 2014

Nov 9th, 2014 (edited)
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.68 KB | None | 0 0
  1. //
  2. //  main.cpp
  3. //  Isaac Bum Simulator
  4. //
  5. //  Created by Hayden Lueck on 2014-11-06.
  6. //  Copyright (c) 2014 Hayden Lueck. All rights reserved.
  7. //
  8.  
  9. #include <iostream>
  10. #include <string>
  11. #include <vector>
  12.  
  13. class Isaac{
  14. public:
  15.     int getPennies() const{
  16.         return pennies;
  17.     }
  18.     void removePenny(){
  19.         pennies--;
  20.     }
  21.    
  22.     void addToInventory(const std::string & item){
  23.         this->item = item;
  24.     }
  25.     void printInventory() const{
  26.         std::cout << "Inventory:\n-------------------------\n" << item << std::endl << std::endl;
  27.     }
  28.    
  29.     void changeTrinket(const std::string & trk){
  30.         trinket = trk;
  31.     }
  32.     void printTrinket() const{
  33.         std::cout << "Held trinket: " << trinket << std::endl;
  34.         std::cout << std::endl;
  35.     }
  36.    
  37.     void addToConsumables(const std::string & cnsm){
  38.         consumables.push_back(cnsm);
  39.     }
  40.     void printConsumables() const{
  41.         std::cout << "Consumables gained:\n-------------------------\n";
  42.         for(int i = 0; i < consumables.size(); i++){
  43.             std::cout << "Item " << i + 1 << ": " << consumables[i] << std::endl;
  44.         }
  45.         std::cout << std::endl;
  46.     }
  47.    
  48. private:
  49.     int pennies = 15;
  50.     std::string item = "none";
  51.     std::string trinket = "none";
  52.     std::vector<std::string> consumables;
  53. };
  54.  
  55. class bumGuy{
  56. public:
  57.     void bum(Isaac & eyeSack)
  58.     {
  59.         std::string item, trinket, consumable;
  60.         char confirm;
  61.        
  62.         do
  63.         {
  64.             std::cout << "You have " << eyeSack.getPennies() << " pennies." << std::endl
  65.             << "Input 0 to give a penny, or any other character to quit: ";
  66.            
  67.             std::cin >> confirm;
  68.            
  69.             if(confirm == '0')
  70.             {
  71.                 eyeSack.removePenny();
  72.                
  73.                 int x = rand()%20;
  74.                 if(x >= 13){
  75.                     if(x == 19){
  76.                         item = items();
  77.                         std::cout << "You got " << item << "!";
  78.                         eyeSack.addToInventory(item);
  79.                         break;
  80.                     }
  81.                     else if(x <= 16){
  82.                         consumable = consumables();
  83.                         std::cout << "You got a " << consumable << "!";
  84.                         eyeSack.addToConsumables(consumable);
  85.                     }
  86.                     else{
  87.                         trinket = trinkets();
  88.                         std::cout << "You got " << trinket << "!";
  89.                         eyeSack.changeTrinket(trinket);
  90.                     }
  91.                 }
  92.                 else{
  93.                     std::cout << "You got nothing :(";
  94.                 }
  95.                 std::cout << std::endl;
  96.                
  97.                 if(eyeSack.getPennies() == 0){
  98.                     std::cout << "You're out of pennies!" << std::endl;
  99.                     break;
  100.                 }
  101.             }
  102.            
  103.         }while(confirm == '0');
  104.     }
  105.    
  106.     std::string consumables()
  107.     {
  108.         consumableList = {
  109.             "heart",
  110.             "bomb",
  111.             "key",
  112.             "soul heart" };
  113.        
  114.         int x = rand() % MAX_CONSUMABLES;
  115.        
  116.         if(x >= 0 && x < MAX_CONSUMABLES)
  117.         {
  118.             return consumableList[x];
  119.         }
  120.         else
  121.         {
  122.             return "error";
  123.         }
  124.     }
  125.    
  126.     std::string items(){
  127.         itemList = {
  128.             "Lemon Mishap",
  129.             "The Bible",
  130.             "My Little Unicorn",
  131.             "The D20",
  132.             "Bucket of Lard" };
  133.        
  134.         int x = rand() % MAX_ITEMS;
  135.        
  136.         if(x >= 0 && x < MAX_ITEMS)
  137.         {
  138.             return itemList[x];
  139.         }
  140.         else
  141.         {
  142.             return "error";
  143.         }
  144.        
  145.     }
  146.    
  147.     std::string trinkets()
  148.     {
  149.         trinketList = {
  150.             "Ace of Spades",
  151.             "Counterfeit Penny",
  152.             "Fish Head",
  153.             "Liberty Cap",
  154.             "A Missing Page" };
  155.        
  156.         int x = rand() % MAX_TRINKETS;
  157.        
  158.         if(x >= 0 && x < MAX_TRINKETS)
  159.         {
  160.             return trinketList[x];
  161.         }
  162.         else
  163.         {
  164.             return "error";
  165.         }
  166.        
  167.     }
  168. private:
  169.     const int MAX_TRINKETS = 5, MAX_ITEMS = 5, MAX_CONSUMABLES = 4;
  170.     std::vector<std::string> trinketList, itemList, consumableList;
  171.    
  172. };
  173.  
  174. int main() {
  175.    
  176.     srand(int(time(0)));
  177.     Isaac eyeSack;
  178.     bumGuy bum;
  179.    
  180.     bum.bum(eyeSack);
  181.    
  182.     std::cout << std::endl;
  183.    
  184.     eyeSack.printInventory();
  185.     eyeSack.printConsumables();
  186.     eyeSack.printTrinket();
  187.    
  188.     return 0;
  189. }
Add Comment
Please, Sign In to add comment