Advertisement
Guest User

Functions.h

a guest
Dec 14th, 2014
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.51 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include <iostream>
  4. #include <Windows.h>
  5. #include <string>
  6. #include <cstdlib>
  7. #include <ctime>
  8. #include <vector>
  9. #include <string>
  10. #include <conio.h>
  11. #include <stdio.h>
  12.  
  13. using namespace std;
  14.  
  15. void BuyScreen(int& Damage, int& Gold, int& Health, int& Range);
  16. void CheckChoice(char& choice, int& Damage, int& Gold, int& Health, int& Range);
  17.  
  18. bool Win;
  19.  
  20. const int Zero = { 0x30 };
  21. const int One = { 0x31 };
  22. const int Two = { 0x32 };
  23. const int Three = { 0x33 };
  24.  
  25. const int B = { 0x42 };
  26.  
  27. const int W = { 0x57 };
  28. const int A = { 0x41 };
  29. const int S = { 0x53 };
  30. const int D = { 0x44 };
  31.  
  32. const int U = { 0x55 };
  33. const int H = { 0x48 };
  34. const int J = { 0x4A };
  35. const int K = { 0x4B };
  36.  
  37. const char Wall = '#';
  38. const char Ground = ' ';
  39. const char Goal = '?';
  40. const int Length = 20;
  41. const int Height = 20;
  42. char board[Height][Length] = { {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'}, //0
  43.                                {'#', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', '#'}, //1
  44.                                {'#', ' ', '#', ' ', '#', '#', '#', '#', ' ', '#', '#', '#', '#', ' ', '#', ' ', '#', '#', ' ', '#'}, //2
  45.                                {'#', ' ', '#', ' ', '#', ' ', ' ', ' ', ' ', '#', ' ', ' ', '#', ' ', '#', ' ', ' ', '#', ' ', '#'}, //3
  46.                                {'#', ' ', '#', ' ', '#', ' ', '#', '#', '#', '#', ' ', ' ', '#', ' ', '#', '#', '#', '#', ' ', '#'}, //4
  47.                                {'#', ' ', '#', '#', '#', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#'}, //5
  48.                                {'#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', '#', '#', '#', '#', ' ', '#', '#', '#', '#', '#', '#'}, //6
  49.                                {'#', ' ', '#', '#', '#', '#', '#', ' ', '#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', '#'}, //7
  50.                                {'#', ' ', '#', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', '#'}, //8
  51.                                {'#', ' ', '#', '#', '#', '#', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', '#'}, //9
  52.                                {'#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', ' ', ' ', '#'}, //10
  53.                                {'#', '#', '#', ' ', '#', '#', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#'}, //11
  54.                                {'#', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', '#', ' ', '#'}, //12
  55.                                {'#', ' ', '#', '#', '#', ' ', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#', ' ', '#'}, //13
  56.                                {'#', ' ', '#', ' ', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', '#', ' ', '#', ' ', '#'}, //14
  57.                                {'#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#', ' ', '#', ' ', '#'}, //15
  58.                                {'#', ' ', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#', ' ', ' ', '#', ' ', '#', ' ', '#', ' ', '#'}, //16
  59.                                {'#', ' ', '#', '#', '#', ' ', '#', ' ', '#', ' ', '#', '#', ' ', '#', '#', '#', ' ', '#', ' ', '#'}, //17
  60.                                {'#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '#', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '?', '#'}, //18
  61.                                {'#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'}};//19
  62. //                               0    1    2    3    4    5    6    7    8    9    10   11   12   13   14   15   16   17   18   19
  63.  
  64. void ShowBoard()
  65. {
  66.     for (int i = 0; i < Height; i++)
  67.     {
  68.         for (int j = 0; j < Length; j++)
  69.         {
  70.             cout << board[i][j];
  71.         }
  72.         cout << endl;
  73.     }
  74. }
  75.  
  76. void ClearScreen()
  77. {
  78.     HANDLE hStdOut;
  79.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  80.     DWORD count;
  81.     DWORD cellCount;
  82.     COORD homeCoords = { 0, 0 };
  83.  
  84.     hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  85.  
  86.     if (hStdOut == INVALID_HANDLE_VALUE)
  87.         return;
  88.  
  89.     /* Get the number of cells in the current buffer */
  90.     if (!GetConsoleScreenBufferInfo( hStdOut, &csbi ))
  91.         return;
  92.  
  93.     cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  94.  
  95.     /* Fill the entire buffer with spaces */
  96.     if (!FillConsoleOutputCharacter(hStdOut, (TCHAR) ' ', cellCount, homeCoords, &count))
  97.         return;
  98.  
  99.     /* Fill the entire buffer with the current colors and attributes */
  100.     if (!FillConsoleOutputAttribute(hStdOut, csbi.wAttributes, cellCount, homeCoords, &count))
  101.         return;
  102.  
  103.     /* Move the cursor home */
  104.     SetConsoleCursorPosition( hStdOut, homeCoords );
  105. }
  106.  
  107. void BuyScreen(int& Damage, int& Gold, int& Health, int& Range)
  108. {
  109.     bool Invalid = true;
  110.     bool Choosing;
  111.  
  112.     while (Invalid)
  113.     {
  114.         int hPotionCost = 5 * Health;
  115.         int damageUpCost = Damage * 1000;
  116.         int rangeUpCost = Range * 1500;
  117.         ClearScreen();
  118.         int BuyChoice;
  119.         cout << "You have " << Gold << " gold and " << Health << " health.\n\n";
  120.         cout << "What would you like to buy?\n";
  121.         cout << "\n0 - Healing Potion - " << hPotionCost << " Gold";
  122.         cout << "\n1 - Damage Up - " << damageUpCost << " Gold";
  123.         cout << "\n2 - Range Up - " << rangeUpCost << " Gold";
  124.         cout << "\n3 - Exit - 0 Gold\n\n";
  125.  
  126.         Choosing = true;
  127.  
  128.         Sleep(50);
  129.  
  130.         while (Choosing)
  131.         {
  132.             //Buy a healing potion
  133.            
  134.             if (GetAsyncKeyState(Zero))
  135.             {
  136.                 BuyChoice = 0;
  137.                 Choosing = false;
  138.             }
  139.  
  140.             //Damage Up
  141.            
  142.             if (GetAsyncKeyState(One))
  143.             {
  144.                 BuyChoice = 1;
  145.                 Choosing = false;
  146.             }
  147.        
  148.             //Range Up
  149.            
  150.             if (GetAsyncKeyState(Two))
  151.             {
  152.                 BuyChoice = 2;
  153.                 Choosing = false;
  154.             }
  155.  
  156.             //Exit
  157.            
  158.             if (GetAsyncKeyState(Three))
  159.             {
  160.                 BuyChoice = 3;
  161.                 Choosing = false;
  162.             }
  163.         }
  164.    
  165.         switch (BuyChoice)
  166.         {
  167.         case 0:
  168.             if (Gold < hPotionCost)
  169.             {
  170.                 cout << "\nYou don't have enough gold for that!\n";
  171.                 Invalid = true;
  172.                 system("PAUSE");
  173.  
  174.                 continue;
  175.             }
  176.  
  177.             else
  178.             {
  179.                 cout << "\nYou feel very refreshed!\n";
  180.                 Health += 10;
  181.                 Gold -= hPotionCost;
  182.                 system("PAUSE");
  183.                
  184.                 if (Health > 100)
  185.                     Health = 100;
  186.  
  187.                 break;
  188.             }
  189.  
  190.         case 1:
  191.             if (Gold < damageUpCost)
  192.             {
  193.                 cout << "\nYou don't have enough gold for that!\n";
  194.                 Invalid = true;
  195.                 system("PAUSE");
  196.  
  197.                 continue;
  198.             }
  199.  
  200.             else
  201.             {
  202.                 cout << "\nYour muscles grow!\n";
  203.                 Damage += 1;
  204.                 Gold -= damageUpCost;
  205.                 system("PAUSE");
  206.  
  207.                 break;
  208.             }
  209.  
  210.             case 2:
  211.             if (Gold < rangeUpCost)
  212.             {
  213.                 cout << "\nYou don't have enough gold for that!\n";
  214.                 Invalid = true;
  215.                 system("PAUSE");
  216.  
  217.                 continue;
  218.             }
  219.  
  220.             else
  221.             {
  222.                 cout << "\nYour arms are like warm rubber!\n";
  223.                 Range += 1;
  224.                 Gold -= rangeUpCost;
  225.                 system("PAUSE");
  226.  
  227.                 break;
  228.             }
  229.  
  230.         case 3:
  231.             cout << "\nVisit again soon!\n";
  232.             Invalid = false;
  233.             system("PAUSE");
  234.  
  235.             break;
  236.  
  237.         default:
  238.             cout << "\nInvalid Choice!\n";
  239.             system("PAUSE");
  240.             continue;
  241.         }
  242.     }
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement