Advertisement
t0xicv4p0r

labirynthe game

Aug 26th, 2015
367
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 26.58 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <windows.h>
  5. #include <conio.h>
  6. #include "maps.h"
  7. #include <ctime>
  8.  
  9. using std::ofstream;
  10. using std::ifstream;
  11. using std::cout;
  12. using std::endl;
  13. using std::cin;
  14. using std::cerr;
  15. using std::string;
  16.  
  17. class infinite
  18. {
  19. public:
  20.     friend class maps;
  21.     infinite();
  22.     ~infinite();
  23.     void drawMap(char amap[20][50]);
  24.     void moves();
  25.     void gotoxy(int x, int y);
  26.     void moves(char map[20][50]);
  27.     void ask();
  28.     void checkClose();
  29.     void choose_level();
  30.     void level1_data();
  31.     void level2_data();
  32.     void level3_data();
  33.     void shop();
  34.     void sp(int choosecolor);
  35.     void stdcolor();
  36.     void reset();
  37.     void instructions();
  38.     void ClearScreen();
  39.     void cursor();
  40.     void choose_character();
  41.     int checkLevelUnlockedVar;
  42.  
  43. protected:
  44.     unsigned int gamespeed;
  45.     int gamerunning;
  46.     int health;
  47.     bool treasureopen;
  48.     bool dooropen;
  49.     bool passtreasure;
  50.     int coins;
  51.     int lastlevel;
  52.     int level;
  53.     bool speed_potion_bought;
  54.     bool health_potion_bought;
  55.     int howmanyhealth;
  56.     int howmanyspeed;
  57.     bool islevel3;
  58.     int i, j;///bomb
  59.     int a, b;///chance
  60.     int c, d;///finish line
  61.     int r, t;///shoot
  62.     int chance;
  63.     int speed_uses;
  64.     bool finishline_drew;
  65.     int s, z;
  66.     bool wallbreaker;
  67.     int howmanywallbreaker;
  68.     bool drawingPermission;
  69.  
  70. public:
  71.  
  72.     static const char p = 3;
  73.     static const char health8[8];
  74.     static const char health7[7];
  75.     static const char health6[6];
  76.     static const char health5[5];
  77.     static const char health4[4];
  78.     static const char health3[3];
  79.     static const char health2[2];
  80.     static const char health1[1];
  81.  
  82. };
  83. const char infinite::health8[8] = { p, p, p, p, p, p, p, p };
  84. const char infinite::health7[7] = { p, p, p, p, p, p, p };
  85. const char infinite::health6[6] = { p, p, p, p, p, p };
  86. const char infinite::health5[5] = { p, p, p, p, p };
  87. const char infinite::health4[4] = { p, p, p, p };
  88. const char infinite::health3[3] = { p, p, p };
  89. const char infinite::health2[2] = { p, p };
  90. const char infinite::health1[1] = { p };
  91.  
  92. void infinite::choose_level()
  93. {
  94.     system("cls");
  95.     system("color 1a");
  96.     cout << "\t\t\t\t\t CHOOSE YOUR LEVEL:" << endl;
  97.     cout << "\t\t\t\t\t                   LEVEL 1" << endl
  98.         << "\t\t\t\t\t                   LEVEL 2" << endl
  99.         << "\t\t\t\t\t                   LEVEL 3" << endl << endl << endl;
  100.  
  101.     cout << "\t\t\t\t\t                   press 9 to enter shop" << endl;
  102.     cout << "\t\t\t\t\t                   press 0 to close" << endl
  103.         << "\t\t\t\t\t                   press 10 to see how to play (recommended) \n";
  104.  
  105.     int choice;
  106.     cout << "\t\t\t\t\t                   ";
  107.     cin >> choice;
  108.  
  109.  
  110.     switch (choice)
  111.     {
  112.     case 1:
  113.         system("cls");
  114.         level = 1;
  115.         break;
  116.  
  117.     case 2:
  118.     {
  119.  
  120.               system("cls");
  121.               ifstream checkLevelUnlocked("clu.txt");
  122.               checkLevelUnlocked >> checkLevelUnlockedVar;
  123.  
  124.               if (checkLevelUnlockedVar >= 2)
  125.               {
  126.                   level = 2;
  127.               }
  128.               else
  129.               {
  130.                   cout << "Level Locked" << endl;
  131.               }
  132.  
  133.               break;
  134.     }
  135.  
  136.     case 3:
  137.         system("cls");
  138.         level = 3;
  139.         break;
  140.  
  141.     case 9:
  142.         system("cls");
  143.         shop();
  144.         break;
  145.  
  146.     case 0:
  147.         cout << "saving..." << endl;
  148.         Sleep(2000);
  149.         gamerunning = false;
  150.         break;
  151.  
  152.     case 10:
  153.         instructions();
  154.         break;
  155.     }
  156.  
  157. }
  158.  
  159. void infinite::checkClose()
  160. {
  161.     if (health == 0 || health < 0){
  162.  
  163.         gamerunning = false;
  164.         cout << endl << "you died ! " << endl;
  165.         system("pause");
  166.  
  167.     }
  168.     if (GetAsyncKeyState(VK_ESCAPE))
  169.     {
  170.         gotoxy(20, 26);
  171.         cout << "saving..." << endl;
  172.         Sleep(2000);
  173.         ofstream coinsSave_out;
  174.         coinsSave_out.open("coins.dat");
  175.  
  176.         coinsSave_out << coins;
  177.         coinsSave_out.close();
  178.         gamerunning = false;
  179.     }
  180.     if (GetAsyncKeyState(VK_SPACE) != 0)
  181.     {
  182.         cout << '\n' << "Game Paused" << endl;
  183.         system("pause");
  184.         system("cls");
  185.  
  186.     }
  187. }
  188.  
  189. void infinite::gotoxy(int x, int y)
  190. {
  191.     HANDLE h;
  192.     h = GetStdHandle(STD_OUTPUT_HANDLE);
  193.     COORD coord;
  194.  
  195.     coord.X = x;
  196.     coord.Y = y;
  197.  
  198.     SetConsoleCursorPosition(h, coord);
  199. }
  200. void infinite::drawMap(char amap[][50])
  201. {
  202.     ifstream coinsSave_in;
  203.     coinsSave_in.open("coins.dat");
  204.  
  205.     coinsSave_in >> coins;
  206.  
  207.     coinsSave_in.close();
  208.     cout << endl;
  209.  
  210.  
  211.     for (int y = 0; y<20; y++)
  212.     {
  213.         cout << amap[y] << endl;
  214.     }
  215.  
  216.     gotoxy(52, 5);
  217.     cout << "Press space to PAUSE" << endl;
  218.     gotoxy(52, 7);
  219.     cout << "Press ESC to quit" << endl;
  220.  
  221.     gotoxy(0, 23);
  222.     cout << "Health :  ";
  223.     switch (health)
  224.     {
  225.     case 1:
  226.  
  227.         for (int i = 0; i<1; i++)
  228.         {
  229.             cout << health1[i];
  230.         }
  231.         break;
  232.  
  233.     case 2:
  234.  
  235.         for (int i = 0; i<2; i++)
  236.             cout << health2[i];
  237.         break;
  238.  
  239.     case 3:
  240.  
  241.         for (int i = 0; i<3; i++)
  242.             cout << health3[i];
  243.         break;
  244.  
  245.     case 4:
  246.         for (int i = 0; i<4; i++)
  247.             cout << health4[i];
  248.         break;
  249.  
  250.     case 5:
  251.         for (int i = 0; i<5; i++){
  252.             cout << health5[i];
  253.         }
  254.  
  255.         break;
  256.  
  257.     case 6:
  258.         for (int i = 0; i<6; i++)
  259.             cout << health6[i];
  260.         break;
  261.  
  262.     case 7:
  263.         for (int i = 0; i<7; i++)
  264.             cout << health7[i];
  265.         break;
  266.  
  267.     case 8:
  268.         for (int i = 0; i<8; i++)
  269.             cout << health8[i];
  270.         break;
  271.     }
  272.  
  273. }
  274. void infinite::ask()
  275. {
  276.     gotoxy(30, 24);
  277.     cout << "2+2*4+2/2+2 = ";
  278.     int answer;
  279.     cin >> answer;
  280.  
  281.  
  282.  
  283.     cout << endl;
  284.  
  285.     if (answer == 13)
  286.     {
  287.         treasureopen = true;
  288.         gotoxy(30, 25);
  289.         cout << "correct answer ! i will open the door for you !!" << endl;
  290.         system("cls");
  291.         drawMap(maps::mem_amap);
  292.         system("color 1a");
  293.         _getch();
  294.     }
  295.     else if (answer != 13)
  296.     {
  297.         cout << "incorrect answer!" << endl
  298.             << "the door will stay locked and you will restart the level !" << endl;
  299.         gamerunning = false;
  300.     }
  301.  
  302.  
  303. }
  304. void infinite::shop()
  305. {
  306.     using std::cerr;
  307.     using std::ios;
  308.  
  309. shop:
  310.  
  311.     ifstream shop_coins;
  312.     shop_coins.open("coins.dat", ios::in);
  313.     shop_coins >> coins;
  314.     system("cls");
  315.     cout << "coins:" << coins << "." << endl;
  316.     cout << "\t\t\t SHOP :" << endl;
  317.     cout << "1)health potion  $50                 Use it with F2 key." << endl;
  318.     cout << "2) speed potion  $60                 Use it with F1 key." << endl;
  319.     cout << "3) wallbreaker   $200" << endl;
  320.     cout << "4) back" << endl;
  321.  
  322.     ifstream health_in("health.dat");
  323.     health_in >> howmanyhealth;
  324.  
  325.     ifstream speed_in("speed.dat");
  326.     speed_in >> howmanyspeed;
  327.  
  328.     ifstream wallbreaker_in("wallbreaker.dat");
  329.     wallbreaker_in >> howmanywallbreaker;
  330.  
  331.     cout << "\n\n you have " << howmanyhealth << " health potions" << endl;
  332.     cout << "\n you have " << howmanyspeed << " speed potions" << endl;
  333.     cout << "\n you have " << howmanywallbreaker << " wallbreakers" << endl;
  334.  
  335.     int shop_choice;
  336.     cout << " ";
  337.     cin >> shop_choice;
  338.  
  339.     switch (shop_choice)
  340.     {
  341.  
  342.     case 1:
  343.         if (coins <= 0)coins = 0;
  344.         if (coins > 50 || coins == 50){
  345.  
  346.             coins -= 50;
  347.             ofstream shop_coins_out;
  348.             shop_coins_out.open("coins.dat");
  349.             shop_coins_out << coins;
  350.             health_potion_bought = true;
  351.             howmanyhealth++;
  352.             ofstream shop_health_out;
  353.             shop_health_out.open("health.dat");
  354.             shop_health_out << howmanyhealth;
  355.             shop_health_out.close();
  356.         }
  357.         else
  358.         {
  359.             cout << "you don 't have enough money" << endl;
  360.         }
  361.         goto shop;
  362.         break;
  363.     }
  364.     if (shop_choice == 2)
  365.     {
  366.         if (coins <= 0) coins = 0;
  367.         if (coins >= 50){
  368.  
  369.             coins -= 50;
  370.             ofstream shop_coins_out;
  371.             shop_coins_out.open("coins.dat");
  372.             shop_coins_out << coins;
  373.             speed_potion_bought = true;
  374.             howmanyspeed++;
  375.             ofstream shop_speed_out;
  376.             shop_speed_out.open("speed.dat");
  377.             shop_speed_out << howmanyspeed;
  378.             shop_speed_out.close();
  379.             goto shop;
  380.         }
  381.         else
  382.         {
  383.             cerr << "you don 't have enough money" << endl;
  384.         }
  385.     }
  386.     if (shop_choice == 3)
  387.     {
  388.         if (coins <= 0)coins = 0;
  389.         if (coins > 200 || coins == 200){
  390.             coins -= 200;
  391.  
  392.             ofstream shop_coins_out("coins.dat");
  393.             shop_coins_out << coins;
  394.             shop_coins_out.close();
  395.             wallbreaker = true;
  396.             howmanywallbreaker++;
  397.             ofstream shop_wallbreaker_out("wallbreaker.dat");
  398.             shop_wallbreaker_out << howmanywallbreaker;
  399.             shop_wallbreaker_out.close();
  400.             goto shop;
  401.         }
  402.     }
  403.     if (shop_choice == 4)
  404.     {
  405.         choose_level();
  406.     }
  407. }
  408.  
  409. infinite::infinite()
  410. {
  411.     gamerunning = true;
  412.     reset();
  413.     choose_level();
  414.  
  415.     if (level == 1)
  416.         level1_data();
  417.  
  418.     if (level == 2)
  419.         level2_data();
  420.  
  421.     if (level == 3)
  422.         level3_data();
  423.  
  424. }
  425.  
  426. infinite::~infinite()
  427. {
  428.     cout << "BYE BYE !" << endl;
  429. }
  430.  
  431. void infinite::moves(char map[20][50])
  432. {
  433.  
  434.     for (int y = 0; y<20; y++)
  435.     {
  436.         for (int x = 0; x<50; x++)
  437.         {
  438.             switch (map[y][x])
  439.             {
  440.             case '#':
  441.  
  442.             {
  443.                 map[y][x] = char(219);
  444.  
  445.             }break;
  446.  
  447.             case 'X':
  448.             {
  449.                 map[y][x] = char(177);
  450.             }break;
  451.  
  452.             case 'M':
  453.                 map[y][x] = char(2);
  454.                 break;
  455.  
  456.             case '*':
  457.                 map[y][x] = char(15);
  458.                 break;
  459.  
  460.             case '@':
  461.                 map[y][x] = char(1);
  462.                 break;
  463.  
  464.             case '=':
  465.                 map[y][x] = char(4);
  466.                 break;
  467.  
  468.             case 'j':
  469.                 map[y][x] = char(255);///invisible, used to define "if region reached"
  470.                 break;
  471.  
  472.             case 'v':
  473.                 map[y][x] = char(234);///ohmique
  474.                 break;
  475.  
  476.             case char(1) :
  477.             {
  478.                              if (GetAsyncKeyState(VK_LSHIFT) != 0)
  479.                              if (drawingPermission)
  480.                              {
  481.                                  int u, o;
  482.                                  u = (y - 1);
  483.                                  o = x;
  484.                                  map[y][x] = char(1);
  485.                                  map[u][o] = char(176);
  486.                              }
  487.  
  488.                              if (health <= 3){ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_INTENSITY); }
  489.                              if (health > 3){ system("color 1a"); }
  490.                              if (islevel3)
  491.                              if (chance == 5){
  492.  
  493.                                  if (finishline_drew == false){
  494.  
  495.                                      srand(static_cast<unsigned int> (time(NULL)));
  496.  
  497.                                      c = rand() % 14 + 4;
  498.                                      d = rand() % 44 + 4;
  499.  
  500.                                      map[c + 1][d + 1] = '!';
  501.  
  502.  
  503.                                      if (map[c + 1][d + 1] == char(219)){ map[c + 1][d + 1] = ' '; map[c - 3][d - 2] = '!'; }///if random is on line
  504.  
  505.  
  506.                                      cout << "find the finish line fast  " << endl;
  507.                                      finishline_drew = true;
  508.                                  }
  509.  
  510.                              }
  511.  
  512.                              if (islevel3)
  513.                              {
  514.                                  srand(static_cast<unsigned int> (time(NULL)));
  515.                                  a = rand() % 14 + 4;
  516.                                  b = rand() % 44 + 4;
  517.  
  518.                                  i = rand() % 14 + 4;
  519.                                  j = rand() % 44 + 4;
  520.  
  521.                                  map[i][j] = char(15);///bomb
  522.                                  map[a][b] = char(6);///chance
  523.  
  524.                              }
  525.  
  526.  
  527.                              using std::cerr;
  528.  
  529.                              if (GetAsyncKeyState(VK_F2) != 0)///health
  530.                              {
  531.                                  ifstream shop_health_in;
  532.                                  shop_health_in.open("health.dat");
  533.                                  shop_health_in >> howmanyhealth;
  534.  
  535.                                  if (howmanyhealth > 0)
  536.                                  {
  537.                                      health_potion_bought = true;
  538.  
  539.                                      if (health_potion_bought == true && howmanyhealth > 0)
  540.                                      {
  541.                                          if (howmanyhealth == 0 || howmanyhealth < 0 || !health_potion_bought)
  542.                                          {
  543.                                              cerr << "you don 't have health potion anymore" << endl;
  544.                                          }
  545.                                          else if (howmanyhealth > 0 && health < 5)
  546.                                          {
  547.                                              if (health > 5)health = 5;
  548.                                              health += 1;
  549.                                              howmanyhealth--;
  550.                                              ofstream shop_health_out;
  551.                                              shop_health_out.open("health.dat");
  552.                                              shop_health_out << howmanyhealth;
  553.                                              shop_health_out.close();
  554.  
  555.  
  556.                                          }
  557.  
  558.                                          if (health >= 5)
  559.                                          {
  560.                                              cout << endl << endl;
  561.                                              health = 5;
  562.                                              cout << "your health is full" << endl;
  563.                                              system("cls");
  564.                                          }
  565.                                      }
  566.  
  567.  
  568.                                      else if (!health_potion_bought)
  569.                                          cerr << "you don 't have a health potion" << endl;
  570.                                      system("cls");
  571.                                  }
  572.                              }
  573.  
  574.                              if (GetAsyncKeyState(VK_F1) != 0)///speed
  575.  
  576.                              {
  577.                                  if (GetAsyncKeyState(VK_F1) != 0 && speed_uses == 2)
  578.                                  {
  579.                                      cout << "\n you can 't use speed potion anymore" << endl;
  580.                                  }
  581.                                  else if (speed_uses < 2){
  582.  
  583.                                      ifstream shop_speed_in;
  584.                                      shop_speed_in.open("speed.dat");
  585.                                      shop_speed_in >> howmanyspeed;
  586.  
  587.                                      if (howmanyspeed > 0)
  588.                                      {
  589.                                          speed_potion_bought = true;
  590.  
  591.                                          if (speed_potion_bought == false)
  592.                                          {
  593.                                              cout << "you don 't have a speed potion" << endl;
  594.                                          }
  595.                                          if (speed_potion_bought == true && howmanyspeed > 0)
  596.                                          {
  597.                                              gamespeed -= 50;
  598.                                              speed_uses++;
  599.                                              howmanyspeed--;
  600.                                              ofstream shop_speed_out;
  601.                                              shop_speed_out.open("speed.dat");
  602.                                              shop_speed_out << howmanyspeed;
  603.                                              shop_speed_out.close();
  604.                                          }
  605.                                      }
  606.                                  }
  607.                              }
  608.                              if (GetAsyncKeyState(VK_UP) != 0)
  609.                              {
  610.                                  int y2 = (y - 1);
  611.                                  switch (map[y2][x])
  612.                                  {
  613.  
  614.                                  case ' ':
  615.                                  {
  616.  
  617.                                         map[y][x] = ' ';
  618.                                         y -= 1;
  619.                                         map[y2][x] = char(1);
  620.                                  }break;
  621.  
  622.  
  623.                                  case '!':
  624.                                  {
  625.                                         system("pause");
  626.                                         gamerunning = false;
  627.  
  628.                                  }break;
  629.  
  630.                                  case char(15) :///bomb
  631.                                  {
  632.                                             if (islevel3){
  633.                                                 health = 0;
  634.  
  635.                                             }
  636.                                             health -= 2;
  637.                                             system("cls");
  638.                                             map[y][x] = ' ';
  639.                                             y -= 1;
  640.                                             map[y2][x] = char(1);
  641.                                  }break;
  642.  
  643.                                  case '^':
  644.                                  {
  645.                                              treasureopen = true;
  646.                                              map[y][x] = ' ';
  647.                                              y -= 1;
  648.                                              map[y2][x] = char(1);
  649.  
  650.                                  }break;
  651.  
  652.                                  case '-':
  653.                                  {
  654.                                              if (treasureopen == false)
  655.                                              {
  656.                                                  gotoxy(24, 16);
  657.                                                  cout << "go to the mage and answer his question" << endl;
  658.                                                  map[y][x] = ' ';
  659.                                                  map[y][x] = char(1);
  660.                                              }
  661.                                              else if (treasureopen == true)
  662.                                              {
  663.                                                  map[y][x] = ' ';
  664.                                                  int y3 = (y - 2);
  665.                                                  y -= 2;
  666.                                                  map[y3][x] = char(1);
  667.                                                  passtreasure = true;
  668.                                              }
  669.                                  }break;
  670.  
  671.                                  case char(4) :/// coins
  672.                                  {
  673.                                              coins += 5;
  674.                                              ofstream coins_out;
  675.                                              coins_out.open("coins.dat");
  676.                                              coins_out << coins;
  677.                                              map[y][x] = ' ';
  678.                                              y -= 1;
  679.                                              map[y2][x] = char(1);
  680.  
  681.                                  }break;
  682.  
  683.                                  case char(6) :///chance
  684.                                  {
  685.                                                    if (islevel3)
  686.                                                    {
  687.                                                        map[y][x] = ' ';
  688.                                                        y -= 1;
  689.                                                        chance++;
  690.                                                        map[y2][x] = char(1);
  691.                                                    }
  692.                                  }break;
  693.  
  694.                                  case char(177) : {///inside wall
  695.                                                       if (GetAsyncKeyState(VK_F6) != 0)///wallbreaker
  696.                                                       {
  697.                                                           ifstream shop_wallbreaker_out("wallbreaker.dat");
  698.                                                           shop_wallbreaker_out >> howmanywallbreaker;
  699.  
  700.                                                           if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
  701.                                                           {
  702.                                                               cerr << "you don 't have a wallbreaker" << endl;
  703.                                                           }
  704.  
  705.                                                           if (howmanywallbreaker > 0)
  706.                                                           {
  707.                                                               wallbreaker = true;
  708.  
  709.                                                               if (wallbreaker == true && howmanywallbreaker > 0)
  710.                                                               {
  711.  
  712.  
  713.  
  714.                                                                   map[y - 1][x] = ' ';
  715.                                                                   howmanywallbreaker--;
  716.                                                                   ofstream shop_wallbreaker_out("wallbreaker.dat");
  717.                                                                   shop_wallbreaker_out << howmanywallbreaker;
  718.                                                                   shop_wallbreaker_out.close();
  719.  
  720.                                                               }
  721.                                                           }
  722.                                                       }
  723.                                  }
  724.                                  }
  725.                              }
  726.                              if (GetAsyncKeyState(VK_DOWN) != 0)
  727.                              {
  728.                                  int y2 = (y + 1);
  729.                                  switch (map[y2][x])
  730.                                  {
  731.                                  case ' ':
  732.                                  {
  733.                                         map[y][x] = ' ';
  734.                                         y += 1;
  735.                                         map[y2][x] = char(1);
  736.                                  }break;
  737.  
  738.                                  case '!':
  739.                                  {
  740.  
  741.                                         system("pause");
  742.                                         gamerunning = false;
  743.  
  744.                                  }break;
  745.  
  746.                                  case char(15) :///bomb
  747.                                  {
  748.                                             if (islevel3)
  749.                                                 health = 0;
  750.  
  751.                                             health -= 2;
  752.                                             system("cls");
  753.                                             map[y][x] = ' ';
  754.                                             y += 1;
  755.                                             map[y2][x] = char(1);
  756.                                  }break;
  757.  
  758.                                  case char(4) :
  759.                                  {
  760.                                         coins += 5;
  761.                                         ofstream coins_out;
  762.                                         coins_out.open("coins.dat");
  763.                                         coins_out << coins;
  764.                                         map[y][x] = ' ';
  765.                                         y += 1;
  766.                                         map[y2][x] = char(1);
  767.                                  }break;
  768.  
  769.                                  case char(6) :
  770.                                  {
  771.                                             if (islevel3)
  772.                                             {
  773.                                                 map[y][x] = ' ';
  774.                                                 y += 1;
  775.                                                 chance++;
  776.                                                 map[y2][x] = char(1);
  777.                                             }
  778.                                  }break;
  779.  
  780.                                  case char(177) : {///inside wall
  781.                                                       if (GetAsyncKeyState(VK_F6) != 0)
  782.                                                       {
  783.                                                           ifstream shop_wallbreaker_out("wallbreaker.dat");
  784.                                                           shop_wallbreaker_out >> howmanywallbreaker;
  785.  
  786.                                                           if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
  787.                                                           {
  788.                                                               cerr << "you don 't have a wallbreaker" << endl;
  789.                                                           }
  790.  
  791.                                                           if (howmanywallbreaker > 0)
  792.                                                           {
  793.                                                               wallbreaker = true;
  794.  
  795.                                                               if (wallbreaker == true && howmanywallbreaker > 0)
  796.                                                               {
  797.  
  798.  
  799.  
  800.                                                                   map[y + 1][x] = ' ';
  801.                                                                   howmanywallbreaker--;
  802.                                                                   ofstream shop_wallbreaker_out("wallbreaker.dat");
  803.                                                                   shop_wallbreaker_out << howmanywallbreaker;
  804.                                                                   shop_wallbreaker_out.close();
  805.  
  806.                                                               }
  807.                                                           }
  808.                                                       }
  809.                                  }break;
  810.                                  }
  811.                              }
  812.  
  813.                              if (GetAsyncKeyState(VK_RIGHT) != 0)
  814.                              {
  815.                                  int x2 = (x + 1);
  816.                                  switch (map[y][x2])
  817.                                  {
  818.                                  case ' ':
  819.                                  {
  820.                                         map[y][x] = ' ';
  821.                                         x += 1;
  822.                                         map[y][x2] = char(1);
  823.                                  }break;
  824.  
  825.                                  case '!':
  826.                                  {
  827.  
  828.                                         system("pause");
  829.                                         gamerunning = false;
  830.  
  831.                                  }break;
  832.  
  833.                                  case char(15) :
  834.                                  {
  835.                                         if (islevel3)
  836.                                             health = 0;
  837.  
  838.                                         health -= 2;
  839.                                         system("cls");
  840.                                         map[y][x] = ' ';
  841.                                         x += 1;
  842.                                         map[y][x2] = char(1);
  843.                                  }break;
  844.  
  845.                                  case '|':
  846.                                  {
  847.                                              if (dooropen == false)
  848.                                              {
  849.                                                  map[y][x] = ' ';
  850.                                                  map[y][x] = char(1);
  851.  
  852.                                                  gotoxy(0, 22);
  853.                                                  cout << "find the key" << endl;
  854.                                              }
  855.                                              else if (dooropen == true)
  856.                                              {
  857.  
  858.  
  859.                                                  map[y][x] = ' ';
  860.                                                  int x3 = (x + 2);
  861.                                                  x += 1;
  862.                                                  map[y][x3] = char(1);
  863.                                              }break;
  864.  
  865.  
  866.                                  case '<':
  867.                                  {
  868.                                              dooropen = true;
  869.                                              map[y][x] = ' ';
  870.                                              x += 1;
  871.                                              map[y][x2] = char(1);
  872.                                  }break;
  873.  
  874.  
  875.                                  case char(4) :
  876.                                  {
  877.                                                   coins += 5;
  878.                                                   ofstream coins_out;
  879.                                                   coins_out.open("coins.dat");
  880.                                                   coins_out << coins;
  881.                                                   map[y][x] = ' ';
  882.                                                   x += 1;
  883.                                                   map[y][x2] = char(1);
  884.                                  }break;
  885.  
  886.                                  case char(6) :///chance
  887.                                  {
  888.                                                    if (islevel3)
  889.                                                    {
  890.                                                        map[y][x] = ' ';
  891.                                                        x += 1;
  892.                                                        chance++;
  893.                                                        map[y][x2] = char(1);
  894.                                                    }
  895.                                  }break;
  896.  
  897.                                  case char(177) : {///inside wall1
  898.                                                       if (GetAsyncKeyState(VK_F6) != 0)
  899.                                                       {
  900.                                                           ifstream shop_wallbreaker_out("wallbreaker.dat");
  901.                                                           shop_wallbreaker_out >> howmanywallbreaker;
  902.  
  903.                                                           if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
  904.                                                           {
  905.                                                               cerr << "you don 't have a wallbreaker" << endl;
  906.                                                           }
  907.  
  908.                                                           if (howmanywallbreaker > 0)
  909.                                                           {
  910.                                                               wallbreaker = true;
  911.  
  912.                                                               if (wallbreaker == true && howmanywallbreaker > 0)
  913.                                                               {
  914.  
  915.  
  916.  
  917.                                                                   map[y][x + 1] = ' ';
  918.                                                                   howmanywallbreaker--;
  919.                                                                   ofstream shop_wallbreaker_out("wallbreaker.dat");
  920.                                                                   shop_wallbreaker_out << howmanywallbreaker;
  921.                                                                   shop_wallbreaker_out.close();
  922.  
  923.                                                               }
  924.                                                           }
  925.                                                       }
  926.                                  }break;
  927.  
  928.                                  case char(255) :
  929.                                  {
  930.                                                     drawingPermission = true;
  931.                                                     map[y][x] = ' ';
  932.                                                     x += 1;
  933.                                                     map[y][x2] = char(1);
  934.  
  935.                                  }break;
  936.                                  }
  937.                                  }
  938.                              }
  939.                              if (GetAsyncKeyState(VK_LEFT))
  940.                              {
  941.                                  int x2 = (x - 1);
  942.                                  switch (map[y][x2])
  943.                                  {
  944.                                  case ' ':
  945.                                  {
  946.                                              map[y][x] = ' ';
  947.                                              x -= 1;
  948.                                              map[y][x2] = char(1);
  949.  
  950.                                  }
  951.                                      break;
  952.  
  953.                                  case '!':
  954.                                  {
  955.  
  956.                                              system("pause");
  957.                                              gamerunning = false;
  958.  
  959.                                  }break;
  960.  
  961.                                  case char(15) :
  962.                                  {
  963.                                                    if (islevel3)
  964.                                                        health = 0;
  965.  
  966.                                                    health -= 2;
  967.                                                    system("cls");
  968.                                                    map[y][x] = ' ';
  969.                                                    x -= 1;
  970.                                                    map[y][x2] = char(1);
  971.                                  }break;
  972.  
  973.                                  case '|':
  974.                                  {
  975.  
  976.                                              map[y][x] = ' ';
  977.                                              int x3 = (x - 2);
  978.                                              x -= 1;
  979.                                              map[y][x3] = char(1);
  980.  
  981.                                  }break;
  982.  
  983.                                  case ')':
  984.                                  {
  985.                                              if (treasureopen == false)
  986.                                              {
  987.                                                  map[y][x] = ' ';
  988.                                                  map[y][x] = char(1);
  989.  
  990.                                                  gotoxy(0, 21);
  991.                                                  cout << "find the second key" << endl;
  992.                                              }
  993.  
  994.                                              else if (treasureopen == true)
  995.                                              {
  996.                                                  map[y][x] = ' ';
  997.                                                  int x3 = (x - 3);
  998.                                                  x -= 3;
  999.                                                  map[y][x3] = char(1);
  1000.                                              }
  1001.                                  }break;
  1002.  
  1003.                                  case char(2) :
  1004.                                  {
  1005.                                                   ask();
  1006.                                  }break;
  1007.  
  1008.                                  case char(4) :
  1009.                                  {
  1010.                                                   coins += 5;
  1011.                                                   ofstream coins_out;
  1012.                                                   coins_out.open("coins.dat");
  1013.                                                   coins_out << coins;
  1014.                                                   coins_out.close();
  1015.                                                   map[y][x] = ' ';
  1016.                                                   x -= 1;
  1017.                                                   map[y][x2] = char(1);
  1018.                                  }break;
  1019.  
  1020.                                  case char(6) :
  1021.                                  {
  1022.                                                   if (islevel3)
  1023.                                                   {
  1024.                                                       map[y][x] = ' ';
  1025.                                                       x -= 1;
  1026.                                                       chance++;
  1027.                                                       map[y][x2] = char(1);
  1028.                                                   }
  1029.                                  }break;
  1030.  
  1031.                                  case char(177) : {///inside wall
  1032.                                                       if (GetAsyncKeyState(VK_F6) != 0)
  1033.                                                       {
  1034.                                                           ifstream shop_wallbreaker_out("wallbreaker.dat");
  1035.                                                           shop_wallbreaker_out >> howmanywallbreaker;
  1036.  
  1037.                                                           if (howmanywallbreaker == 0 || howmanywallbreaker < 0)
  1038.                                                           {
  1039.                                                               cerr << "you don 't have a wallbreaker" << endl;
  1040.                                                           }
  1041.  
  1042.                                                           if (howmanywallbreaker > 0)
  1043.                                                           {
  1044.                                                               wallbreaker = true;
  1045.  
  1046.                                                               if (wallbreaker == true && howmanywallbreaker > 0)
  1047.                                                               {
  1048.  
  1049.  
  1050.  
  1051.                                                                   map[y][x - 1] = ' ';
  1052.                                                                   howmanywallbreaker--;
  1053.                                                                   ofstream shop_wallbreaker_out("wallbreaker.dat");
  1054.                                                                   shop_wallbreaker_out << howmanywallbreaker;
  1055.                                                                   shop_wallbreaker_out.close();
  1056.  
  1057.                                                               }
  1058.                                                           }
  1059.                                                       }
  1060.                                  }break;
  1061.  
  1062.                                  }
  1063.                              }
  1064.  
  1065.             }
  1066.             }
  1067.         }
  1068.  
  1069.     }
  1070. }
  1071.  
  1072.  
  1073.  
  1074.  
  1075. void infinite::sp(int choosecolor)
  1076. {
  1077.     HANDLE h;
  1078.     h = GetStdHandle(STD_OUTPUT_HANDLE);
  1079.     SetConsoleTextAttribute(h, choosecolor);
  1080. }
  1081. void infinite::stdcolor()
  1082. {
  1083.     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
  1084. }
  1085. void infinite::reset()
  1086. {
  1087.     howmanywallbreaker = 0;
  1088.     wallbreaker = false;
  1089.     s = z = 10;
  1090.     finishline_drew = false;
  1091.     speed_uses = 0;
  1092.     islevel3 = false;
  1093.     chance = 0;
  1094.     howmanyhealth = 0;
  1095.     howmanyspeed = 0;
  1096.     health_potion_bought = false;
  1097.     speed_potion_bought = false;
  1098.     coins = 0;
  1099.     passtreasure = false;
  1100.     gamerunning = true;
  1101.     gamespeed = 50;
  1102.     health = 8;
  1103.     treasureopen = false;
  1104.     dooropen = false;
  1105. }
  1106. void infinite::level1_data()
  1107. {
  1108.     reset();
  1109.     while (gamerunning && level == 1)
  1110.     {
  1111.         cursor();
  1112.         cout << char(4) << " " << coins;
  1113.         cout << endl;
  1114.  
  1115.         drawMap(maps::mem_amap);
  1116.         moves(maps::mem_amap);
  1117.         checkClose();
  1118.         Sleep(gamespeed);
  1119.     }
  1120. }
  1121. void infinite::level2_data()
  1122. {
  1123.     reset();
  1124.     gamerunning = true;
  1125.     memcpy(maps::mem_amap, maps::map2, sizeof(maps::mem_amap));
  1126.     while (gamerunning && level == 2)
  1127.     {
  1128.  
  1129.  
  1130.         cursor();
  1131.         cout << char(4) << " " << coins;
  1132.         drawMap(maps::mem_amap);
  1133.         moves(maps::mem_amap);
  1134.         checkClose();
  1135.         Sleep(gamespeed);
  1136.     }
  1137. }
  1138. void infinite::instructions()
  1139. {
  1140.     system("cls");
  1141.     cout << "\t\t\t\t INSTRUCTIONS" << endl;
  1142.     cout << "\t\t\t\t ============ \n" << endl;
  1143.  
  1144.  
  1145.     system("color 1c");
  1146.  
  1147.     cout << " MOVES : UP - DOWN - LEFT - RIGHT Arrows \n" << endl
  1148.         << " THE  : " << char(15) << " is a BOMB , if you step on it, you will loose 2 hearts \n" << endl
  1149.         << " THE  : '!' is the finish line. You must reach it to pass the level \n" << endl
  1150.         << " THE  : " << char(2) << " is the mage. Answer his question and see what he will give you \n" << endl
  1151.         << " THE  : " << char(4) << " is a coin.each " << char(4) << " will give you 5 coins. collect coins and buy variety of potion from the shop \n" << endl
  1152.         << " THE  : '<' and '^' are keys. use them to open locked doors" << endl << endl << endl;
  1153.  
  1154.     system("pause");
  1155.  
  1156.     choose_level();
  1157.  
  1158. }
  1159. void infinite::level3_data()
  1160. {
  1161.     memcpy(maps::mem_amap, maps::map3, sizeof(maps::mem_amap));
  1162.     gamerunning = true;
  1163.  
  1164.     system("cls");
  1165.     gotoxy(25, 25);
  1166.     cout << "THIS IS A SPECIAL LEVEL, COLLECT 20 COINS TO GET THE FINISH LINE. DON 'T HIT A BOMB OR YOU WILL DIE DIRECTLY!";
  1167.     gotoxy(25, 26);
  1168.     cout << "THE MORE FAST YOU ARE, YOU HAVE MORE CHANCES TO WIN THIS LEVEL...";
  1169.     gotoxy(25, 28);
  1170.     _getch();
  1171.     system("cls");
  1172.  
  1173.     while (gamerunning && level == 3)
  1174.     {
  1175.         cursor();
  1176.         islevel3 = true;
  1177.         cout << char(6) << " " << chance;
  1178.         drawMap(maps::mem_amap);
  1179.         moves(maps::mem_amap);
  1180.         checkClose();
  1181.         Sleep(gamespeed);
  1182.     }
  1183. }
  1184. void infinite::ClearScreen()
  1185. {
  1186.     HANDLE                     hStdOut;
  1187.     CONSOLE_SCREEN_BUFFER_INFO csbi;
  1188.     DWORD                      count;
  1189.     DWORD                      cellCount;
  1190.     COORD                      homeCoords = { 0, 0 };
  1191.  
  1192.     hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  1193.     if (hStdOut == INVALID_HANDLE_VALUE) return;
  1194.  
  1195.     /* Get the number of cells in the current buffer */
  1196.     if (!GetConsoleScreenBufferInfo(hStdOut, &csbi)) return;
  1197.     cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  1198.  
  1199.     /* Fill the entire buffer with spaces */
  1200.     if (!FillConsoleOutputCharacter(
  1201.         hStdOut,
  1202.         (TCHAR) ' ',
  1203.         cellCount,
  1204.         homeCoords,
  1205.         &count
  1206.         )) return;
  1207.  
  1208.     /* Fill the entire buffer with the current colors and attributes */
  1209.     if (!FillConsoleOutputAttribute(
  1210.         hStdOut,
  1211.         csbi.wAttributes,
  1212.         cellCount,
  1213.         homeCoords,
  1214.         &count
  1215.         )) return;
  1216.  
  1217.     /* Move the cursor home */
  1218.     SetConsoleCursorPosition(hStdOut, homeCoords);
  1219. }
  1220. void infinite::cursor()
  1221. {
  1222.     HANDLE h;
  1223.     h = GetStdHandle(STD_OUTPUT_HANDLE);
  1224.     COORD coord;
  1225.  
  1226.     coord.X = 0;
  1227.     coord.Y = 0;
  1228.  
  1229.     SetConsoleCursorPosition(h, coord);
  1230. }
  1231. int main()
  1232. {
  1233.     system("color 1a");
  1234.     infinite *go;
  1235.     go = new infinite;
  1236.     go->choose_level();
  1237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement