hedgy134117

The Alphabet Farm SOURCE CODE

Apr 22nd, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 14.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <array>
  3. #include <string>
  4. using namespace std;
  5.  
  6. #pragma region VARIABLES
  7. // map size of 7*7
  8. string map[49] = {};
  9.  
  10. // seeds
  11. // buy price, quantity, selling price
  12. const double abcde[3] = { 7, 5, 3.5 };
  13. const double fghij[3] = { 15, 7, 5.36 };
  14. const double klmnop[3] = { 25, 7, 10.71 };
  15. const int qrstuvw[3] = { 40, 10, 14 };
  16. const int xyz[3] = { 100, 3, 50 };
  17.  
  18. // bag
  19. int myBag[5];
  20.  
  21. // upgradeActive or Not variables
  22. bool doubleSeeds = false;
  23. bool quadSeeds = false;
  24. bool infiniteSeeds = false;
  25.  
  26. // doubleSeeds
  27. bool doubleSeedPlanted = false;
  28. int quadSeedsPlanted = 1;
  29.  
  30. // other variables
  31. double money = 8; // DEFAULT: 8
  32. char choice;
  33. int shopChoice;
  34. int plantChoice;
  35. string seedInput;
  36. int days = 1;
  37. #pragma endregion
  38.  
  39. void createMyBag() {
  40.     // Start with ten abcde seeds
  41.     myBag[0] = abcde[1] + 5;
  42. }
  43.  
  44. void createSpaces() {
  45.    
  46.     for (int i = 0; i < 50; i = i + 1) {
  47.         map[i] = "#";
  48.     }
  49. }
  50.  
  51. void createBoard() {
  52.     // First Line
  53.     for (int i = 1; i < 8; i = i + 1) {
  54.         cout << map[i] << " | ";
  55.  
  56.     }
  57.     cout << "\n";
  58.  
  59.     // Dividers
  60.     for (int i = 1; i < 8; i = i + 1) {
  61.         if (i < 2) {
  62.             cout << "--+";
  63.         }
  64.         else if (i > 6) {
  65.             cout << "---";
  66.         }
  67.         else {
  68.             cout << "---+";
  69.         }
  70.     }
  71.     cout << "\n";
  72.  
  73.     // Second Line
  74.     for (int i = 8;  i < 15; i = i + 1) {
  75.         cout << map[i] << " | ";
  76.  
  77.     }
  78.     cout << "\n";
  79.  
  80.     // Dividers
  81.     for (int i = 8; i < 15; i = i + 1) {
  82.         if (i < 9) {
  83.             cout << "--+";
  84.         }
  85.         else if (i > 13) {
  86.             cout << "---";
  87.         }
  88.         else {
  89.             cout << "---+";
  90.         }
  91.     }
  92.     cout << "\n";
  93.  
  94.     // Third Line
  95.     for (int i = 15; i < 22; i = i + 1) {
  96.         cout << map[i] << " | ";
  97.        
  98.     }
  99.     cout << "\n";
  100.  
  101.     // Dividers
  102.     for (int i = 15; i < 22; i = i + 1) {
  103.         if (i < 16) {
  104.             cout << "--+";
  105.         }
  106.         else if (i > 20) {
  107.             cout << "---";
  108.         }
  109.         else {
  110.             cout << "---+";
  111.         }
  112.     }
  113.     cout << "\n";
  114.  
  115.     // Fourth Line
  116.     for (int i = 22; i < 29; i = i + 1) {
  117.         cout << map[i] << " | ";
  118.        
  119.     }
  120.     cout << "\n";
  121.  
  122.     // Dividers
  123.     for (int i = 22; i < 29; i = i + 1) {
  124.         if (i < 23) {
  125.             cout << "--+";
  126.         }
  127.         else if (i > 27) {
  128.             cout << "---";
  129.         }
  130.         else {
  131.             cout << "---+";
  132.         }
  133.     }
  134.     cout << "\n";
  135.  
  136.     // Fifth Line
  137.     for (int i = 29; i < 36; i = i + 1) {
  138.         cout << map[i] << " | ";
  139.        
  140.     }
  141.     cout << "\n";
  142.  
  143.     // Dividers
  144.     for (int i = 29; i < 36; i = i + 1) {
  145.         if (i < 30) {
  146.             cout << "--+";
  147.         }
  148.         else if (i > 34) {
  149.             cout << "---";
  150.         }
  151.         else {
  152.             cout << "---+";
  153.         }
  154.     }
  155.     cout << "\n";
  156.  
  157.     // Sixth Line
  158.     for (int i = 36; i < 43; i = i + 1) {
  159.         cout << map[i] << " | ";
  160.        
  161.     }
  162.     cout << "\n";
  163.  
  164.     // Dividers
  165.     for (int i = 36; i < 43; i = i + 1) {
  166.         if (i < 37) {
  167.             cout << "--+";
  168.         }
  169.         else if (i > 41) {
  170.             cout << "---";
  171.         }
  172.         else {
  173.             cout << "---+";
  174.         }
  175.     }
  176.     cout << "\n";
  177.  
  178.     // Seventh Line
  179.     for (int i = 43; i < 50; i = i + 1) {
  180.         cout << map[i] << " | ";
  181.        
  182.     }
  183.     cout << "\n";
  184.  
  185.     // Dividers
  186.     for (int i = 36; i < 43; i = i + 1) {
  187.         cout << "---";
  188.     }
  189.     // Lazy extra dividers
  190.     cout << "-----";
  191.     cout << "\n";
  192. }
  193.  
  194. void upgradeShop() {
  195.     // Leave
  196.     cout << "0. Leave upgrade shop" << endl;
  197.     // Double Seeds
  198.     cout << "1. Plant 2 seeds in 1 day ($10)" << endl;
  199.     // Quad Seeds
  200.     cout << "2. Plant 4 seeds in 1 day ($50)" << endl;
  201.     // Infinite Seeds
  202.     cout << "3. Plant all your seeds in 1 day ($250)" << endl;
  203.  
  204.     cin >> shopChoice;
  205.     // Activating upgrades
  206.     switch (shopChoice) {
  207.     case 1:
  208.         if (money >= 10) {
  209.             cout << "Purchase successful" << endl;
  210.             money = money - 10;
  211.             doubleSeeds = true;
  212.         }
  213.         else {
  214.             cout << "You don't have enough money!\n";
  215.         }
  216.         break;
  217.     case 2:
  218.         if (money >= 50) {
  219.             cout << "Purchase successful" << endl;
  220.             money = money - 50;
  221.             doubleSeeds = false;
  222.             quadSeeds = true;
  223.         }
  224.         else {
  225.             cout << "You don't have enough money!\n";
  226.         }
  227.         break;
  228.     case 3:
  229.         if (money >= 250) {
  230.             cout << "Purchase successful" << endl;
  231.             money = money - 250;
  232.             doubleSeeds = false;
  233.             quadSeeds = false;
  234.             infiniteSeeds = true;
  235.         }
  236.     }
  237. }
  238.  
  239. void seedShop() {
  240.     cout << "0. Leave the Seed Shop" << endl;
  241.     cout << "1. ABCDE Seeds; 7$ for 5" << endl;
  242.     cout << "2. FGHIJ Seeds; 15$ for 7" << endl;
  243.     cout << "3. KLMNOP Seeds; 25$ for 7" << endl;
  244.     cout << "4. QRSTUVW Seeds; 40$ for 10" << endl;
  245.     cout << "5. XYZ Seeds; 100$ for 3" << endl;
  246.  
  247.     cin >> shopChoice;
  248.  
  249.     switch (shopChoice) {
  250.     default:
  251.         break;
  252.     case 1:
  253.         if (money >= 7) {
  254.             cout << "Purchase successful." << endl;
  255.             money = money - 7;
  256.             myBag[0] = myBag[0] + 5;
  257.         }
  258.         else {
  259.             cout << "Purhcase unsuccessful, insufficient funds." << endl;
  260.         }
  261.         break;
  262.     case 2:
  263.         if (money >= 15) {
  264.             cout << "Purchase successful." << endl;
  265.             money = money - 15;
  266.             myBag[1] = myBag[1] + 7;
  267.         }
  268.         else {
  269.             cout << "Purchase unsuccessful, insufficient funds." << endl;
  270.         }
  271.         break;
  272.     case 3:
  273.         if (money >= 25) {
  274.             cout << "Purhcase successful." << endl;
  275.             money = money - 25;
  276.             myBag[2] = myBag[2] + 7;
  277.         }
  278.         else {
  279.             cout << "Purchase unsuccessful, insufficient funds." << endl;
  280.         }
  281.         break;
  282.     case 4:
  283.         if (money >= 40) {
  284.             cout << "Purchase successful." << endl;
  285.             money = money - 40;
  286.             myBag[3] = myBag[3] + 10;
  287.         }
  288.         else {
  289.             cout << "Purchase unsuccessful, insufficient funds." << endl;
  290.         }
  291.         break;
  292.     case 5:
  293.         if (money >= 100) {
  294.             cout << "Purchase successful, enjoy your overpriced seeds." << endl;
  295.             money = money - 100;
  296.             myBag[4] = myBag[4] + 3;
  297.         }
  298.         else {
  299.             cout << "Purchase unsuccesful, insufficient funds... makes sense, they are some pretty pricey seeds." << endl;
  300.         }
  301.     }
  302.  
  303.     cout << "(y/n) Continue browsing? ";
  304.     cin >> choice;
  305.     if (choice == 'y') {
  306.         seedShop();
  307.     }
  308. }
  309.  
  310. void plantSeeds() {
  311.     // Printing users seeds
  312.     cout << "\n";
  313.     cout << "Current Seeds: " << endl;
  314.     cout << "ABCDE Seeds: " << myBag[0] << endl;
  315.     cout << "FGHIJ Seeds: " << myBag[1] << endl;
  316.     cout << "KLMNOP Seeds: " << myBag[2] << endl;
  317.     cout << "QRSTUVW Seeds: " << myBag[3] << endl;
  318.     cout << "XYZ Seeds: " << myBag[4] << endl;
  319.     cout << "\n";
  320.  
  321.     // Input for seed choice
  322.     cout << "Which seed? (use the first letter, lowercase)" << endl;
  323.     cin >> seedInput;
  324.  
  325.     // ABCDE SEED
  326.     if (seedInput == "a") {
  327.         // Reset seedInput variable
  328.         seedInput = "#";
  329.         // Choosing where to place seeds
  330.         cout << "Where?" << endl;
  331.         cout << "(use a number)" << endl;
  332.         cin >> plantChoice;
  333.         cout << "\n";
  334.        
  335.         // If there is a seed there/not
  336.         if (map[plantChoice] == "A") {
  337.             cout << "You already have a plant there..." << endl;
  338.             plantSeeds();
  339.         }
  340.         else {
  341.             map[plantChoice] = "A";
  342.             cout << "Seed planted." << endl;
  343.             // Removing 1 seed from bag
  344.             myBag[0] = myBag[0] - 1;
  345.         }
  346.     }
  347.  
  348.     // FGHIJ SEED
  349.     if (seedInput == "f") {
  350.         // Reset seedInput variable
  351.         seedInput = "#";
  352.         // Choosing where to place seeds
  353.         cout << "Where?" << endl;
  354.         cout << "(use a number)" << endl;
  355.         cin >> plantChoice;
  356.         cout << "\n";
  357.  
  358.         // If there is a seed there/not
  359.         if (map[plantChoice] == "F") {
  360.             cout << "You already have a plant there..." << endl;
  361.             plantSeeds();
  362.         }
  363.         else {
  364.             map[plantChoice] = "F";
  365.             cout << "Seed planted." << endl;
  366.             // Removing 1 seed from bag
  367.             myBag[1] = myBag[1] - 1;
  368.         }
  369.     }
  370.  
  371.     // KLMNOP SEED
  372.     if (seedInput == "k") {
  373.         // Reset seedInput variable
  374.         seedInput = "#";
  375.         // Choosing where to place seeds
  376.         cout << "Where?" << endl;
  377.         cout << "(use a number)" << endl;
  378.         cin >> plantChoice;
  379.         cout << "\n";
  380.  
  381.         // If there is a seed there/not
  382.         if (map[plantChoice] == "K") {
  383.             cout << "You already have a plant there..." << endl;
  384.             plantSeeds();
  385.         }
  386.         else {
  387.             map[plantChoice] = "K";
  388.             cout << "Seed planted." << endl;
  389.             // Removing 1 seed from bag
  390.             myBag[2] = myBag[2] - 1;
  391.         }
  392.     }
  393.      
  394.     // QRSTUVW SEED
  395.     if (seedInput == "q") {
  396.         // Reset seedInput variable
  397.         seedInput = "#";
  398.         // Choosing where to place seeds
  399.         cout << "Where?" << endl;
  400.         cout << "(use a number)" << endl;
  401.         cin >> plantChoice;
  402.         cout << "\n";
  403.  
  404.         // If there is a seed there/not
  405.         if (map[plantChoice] == "Q") {
  406.             cout << "You already have a plant there..." << endl;
  407.             plantSeeds();
  408.         }
  409.         else {
  410.             map[plantChoice] = "Q";
  411.             cout << "Seed planted." << endl;
  412.             // Removing 1 seed from bag
  413.             myBag[3] = myBag[3] - 1;
  414.         }
  415.     }
  416.  
  417.     // XYZ SEED
  418.     if (seedInput == "x") {
  419.         // Reset seedInput variable
  420.         seedInput = "#";
  421.         // Choosing where to place seeds
  422.         cout << "Where?" << endl;
  423.         cout << "(use a number)" << endl;
  424.         cin >> plantChoice;
  425.         cout << "\n";
  426.  
  427.         // If there is a seed there/not
  428.         if (map[plantChoice] == "X") {
  429.             cout << "You already have a plant there..." << endl;
  430.             plantSeeds();
  431.         }
  432.         else {
  433.             map[plantChoice] = "X";
  434.             cout << "Seed planted." << endl;
  435.             // Removing 1 seed from bag
  436.             myBag[4] = myBag[4] - 1;
  437.         }
  438.     }
  439.  
  440.     // To plant more than one seed - Double Seeds
  441.     if (doubleSeeds && !doubleSeedPlanted) {
  442.         cout << "(y/n) Plant another seed? ";
  443.         cin >> choice;
  444.         switch (choice) {
  445.         case 'y':
  446.             doubleSeedPlanted = true;
  447.             plantSeeds();
  448.         }
  449.     }
  450.  
  451.     // To plant more than one seed - Quad Seeds
  452.     if (quadSeeds && (quadSeedsPlanted != 4)) {
  453.         cout << "(y/n) Plant another seed? ";
  454.         cin >> choice;
  455.         switch (choice) {
  456.         case 'y':
  457.             quadSeedsPlanted = quadSeedsPlanted + 1;
  458.             plantSeeds();
  459.         }
  460.     }
  461.  
  462.     // To plant more than one seed - Infinite Seeds
  463.     if (infiniteSeeds) {
  464.         cout << "(y/n) Plant another seed? ";
  465.         cin >> choice;
  466.         switch (choice) {
  467.         case 'y':
  468.             plantSeeds();
  469.         }
  470.     }
  471.  
  472.     // Resets double seeds
  473.     doubleSeedPlanted = false;
  474.  
  475.     // Resets quad seeds
  476.     quadSeedsPlanted = 1;
  477. }
  478.  
  479. void characterChoice() {
  480.     cout << "1. Plant seeds\n2. Buy upgrade\n3. Skip day\n4. Buy seeds ";
  481.     cin >> choice;
  482.  
  483.     switch (choice) {
  484.     case '1':
  485.         plantSeeds();
  486.        
  487.         break;
  488.     case '2':
  489.         system("cls");
  490.         upgradeShop();
  491.         break;
  492.     case '3':
  493.         cout << "You go off to bed early." << endl;
  494.         break;
  495.     case '4':
  496.         system("cls");
  497.         seedShop();
  498.     }
  499. }
  500.  
  501. void growingSeeds() {
  502.     // Allowing ABCDE seeds to grow
  503.     for (int grow = 0; grow < 50; grow = grow + 1) {
  504.  
  505.         // Stage 1 -> 2
  506.         if (map[grow] == "A") {
  507.             map[grow] = "B";
  508.         }
  509.         // Stage 2 -> 3
  510.         else if (map[grow] == "B") {
  511.             map[grow] = "C";
  512.         }
  513.         // Stage 3 -> 4
  514.         else if (map[grow] == "C") {
  515.             map[grow] = "D";
  516.         }
  517.         // Stage 4 -> 5
  518.         else if (map[grow] == "D") {
  519.             map[grow] = "E";
  520.         }
  521.         // Plant harvested, spot regrowing...
  522.         else if (map[grow] == "E") {
  523.             map[grow] = "*";
  524.             cout << "Plant harvested, " << abcde[2] << "$ will be added to balance." << endl;
  525.             money = money + abcde[2];
  526.         }
  527.         // Plant spot Regrown
  528.         else if (map[grow] == "*") {
  529.             map[grow] = "#";
  530.         }
  531.  
  532.     }
  533.     // Allowing FGHIJ seeds to grow
  534.     for (int grow = 0; grow < 50; grow = grow + 1) {
  535.  
  536.         // Stage 1 -> 2
  537.         if (map[grow] == "F") {
  538.             map[grow] = "G";
  539.         }
  540.         // Stage 2 -> 3
  541.         else if (map[grow] == "G") {
  542.             map[grow] = "H";
  543.         }
  544.         // Stage 3 -> 4
  545.         else if (map[grow] == "H") {
  546.             map[grow] = "I";
  547.         }
  548.         // Stage 4 -> 5
  549.         else if (map[grow] == "I") {
  550.             map[grow] = "J";
  551.         }
  552.         // Plant harvested, spot regrowing...
  553.         else if (map[grow] == "J") {
  554.             map[grow] = "*";
  555.             cout << "Plant harvested, " << fghij[2] << "$ will be added to balance." << endl;
  556.             money = money + fghij[2];
  557.         }
  558.         // Plant spot Regrown
  559.         else if (map[grow] == "*") {
  560.             map[grow] = "#";
  561.         }
  562.  
  563.     }
  564.     // Allowing KLMNOP seeds to grow
  565.     for (int grow = 0; grow < 50; grow = grow + 1) {
  566.  
  567.         // Stage 1 -> 2
  568.         if (map[grow] == "K") {
  569.             map[grow] = "L";
  570.         }
  571.         // Stage 2 -> 3
  572.         else if (map[grow] == "L") {
  573.             map[grow] = "M";
  574.         }
  575.         // Stage 3 -> 4
  576.         else if (map[grow] == "M") {
  577.             map[grow] = "N";
  578.         }
  579.         // Stage 4 -> 5
  580.         else if (map[grow] == "N") {
  581.             map[grow] = "O";
  582.         }
  583.         // Stage 5 -> 6
  584.         else if (map[grow] == "O") {
  585.             map[grow] = "P";
  586.         }
  587.         // Plant harvested, spot regrowing...
  588.         else if (map[grow] == "P") {
  589.             map[grow] = "*";
  590.             cout << "Plant harvested, " << klmnop[2] << "$ will be added to balance." << endl;
  591.             money = money + klmnop[2];
  592.         }
  593.         // Plant spot Regrown
  594.         else if (map[grow] == "*") {
  595.             map[grow] = "#";
  596.         }
  597.  
  598.     }
  599.     // Allowing QRSTUVW seeds to grow
  600.     for (int grow = 0; grow < 50; grow = grow + 1) {
  601.  
  602.         // Stage 1 -> 2
  603.         if (map[grow] == "Q") {
  604.             map[grow] = "R";
  605.         }
  606.         // Stage 2 -> 3
  607.         else if (map[grow] == "R") {
  608.             map[grow] = "S";
  609.         }
  610.         // Stage 3 -> 4
  611.         else if (map[grow] == "S") {
  612.             map[grow] = "T";
  613.         }
  614.         // Stage 4 -> 5
  615.         else if (map[grow] == "T") {
  616.             map[grow] = "U";
  617.         }
  618.         // Stage 5 -> 6
  619.         else if (map[grow] == "U") {
  620.             map[grow] = "V";
  621.         }
  622.         else if (map[grow] == "V") {
  623.             map[grow] = "W";
  624.         }
  625.         // Plant harvested, spot regrowing...
  626.         else if (map[grow] == "W") {
  627.             map[grow] = "*";
  628.             cout << "Plant harvested, " << qrstuvw[2] << "$ will be added to balance." << endl;
  629.             money = money + qrstuvw[2];
  630.         }
  631.         // Plant spot Regrown
  632.         else if (map[grow] == "*") {
  633.             map[grow] = "#";
  634.         }
  635.  
  636.     }
  637.     // Allowing XYZ seeds to grow
  638.     for (int grow = 0; grow < 50; grow = grow + 1) {
  639.  
  640.         // Stage 1 -> 2
  641.         if (map[grow] == "X") {
  642.             map[grow] = "Y";
  643.         }
  644.         // Stage 2 -> 3
  645.         else if (map[grow] == "Y") {
  646.             map[grow] = "Z";
  647.         }
  648.         // Plant harvested, spot regrowing...
  649.         else if (map[grow] == "Z") {
  650.             map[grow] = "*";
  651.             cout << "Plant harvested, " << xyz[2] << "$ will be added to balance." << endl;
  652.             money = money + xyz[2];
  653.         }
  654.         // Plant spot Regrown
  655.         else if (map[grow] == "*") {
  656.             map[grow] = "#";
  657.         }
  658.  
  659.     }
  660. }
  661.  
  662.  
  663. int main() {
  664.     // Create variables on startup
  665.     createSpaces();
  666.     createMyBag();
  667.     system("color 82");
  668.  
  669.     // Ready?
  670. #pragma region start
  671.     cout << "(y/n) READY PLAYER ONE ";
  672.     cin >> choice;
  673.     if (choice = 'y') {
  674.         cout << endl;
  675.     }
  676.     else {
  677.         return 0;
  678.     }
  679.     system("cls");
  680. #pragma endregion
  681.  
  682.     // Entire Game
  683.     for (days = 1; (days < 366) && (money > 0); days = days + 1) {
  684.         // Printing daily farm upkeep fine
  685.         if (days > 1) {
  686.             cout << "0.25$ removed from balance for farm upkeep" << endl;
  687.         }
  688.         // Print the Day
  689.         cout << "Day " << days << endl;
  690.         // Print the Money
  691.         cout << money << "$ total balance" << endl;
  692.         // Print the Board
  693.         createBoard();
  694.         // Grow Seeds
  695.         growingSeeds();
  696.         // Print character's Options
  697.         characterChoice();
  698.  
  699.         // Win state: Earn 1,000$
  700.         if (money >= 1000) {
  701.             system("cls");
  702.             cout << "(y/n) Congratulations! You have earned 1000$! Would you like to continue?" << endl;
  703.             cin >> choice;
  704.             if (choice == 'n') {
  705.                 return 0;
  706.             }
  707.         }
  708.  
  709.         // Daily farm upkeep fine
  710.         money = money - 0.25;
  711.  
  712.         // Press any key to continue
  713.         system("pause");
  714.         // Clear the console
  715.         system("cls");
  716.     }
  717.  
  718.     system("cls");
  719.     cout << "GAME OVER" << endl;
  720.     cout << "Total ending money: " << money << "$" << endl;
  721.     system("pause");
  722.     return 0;
  723. }
Advertisement
Add Comment
Please, Sign In to add comment