Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.77 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <conio.h>
  4. #include <windows.h>
  5. #include "enemy.h"
  6. #include "fight.h"
  7. #include "game.h"
  8. #include <random>
  9. #include <cstdlib>
  10. #include <ctime>
  11. #include <cstdio>
  12. using namespace std;
  13. game::game()
  14. {
  15.     //ctor
  16.  
  17. }
  18.  
  19. void game::mainSys(){
  20.     system("color f0");
  21.      char map[10][25];
  22.  
  23.  
  24.  
  25.  
  26.     fight f;
  27.     char ploc;
  28.     int steps = 0;
  29.     int score = 0;
  30.     int points = 0;
  31.     bool isDone = false;
  32.     bool key = false;
  33.     int speed = 0;
  34.  
  35.     switch(level){
  36.     case 0:{
  37.     char map[10][25] = { "#W/A/S/D############",
  38.                          "#@             PLAY#",
  39.                          "#            #######",
  40.                          "#              INST#",
  41.                          "#            #######",
  42.                          "#              CRED#",
  43.                          "#            #######",
  44.                          "#              QUIT#",
  45.                          "####################"};
  46.         }break;
  47.         case 1:{
  48.      char map[10][25] = {"####################",
  49.                          "#@     99   # #   9#",
  50.                          "#### #   2 9# # 2  #",
  51.                          "#  # ##### ## 2  9 #",
  52.                          "#9   999      ######",
  53.                          "#9 ####### ##2     #",
  54.                          "#9 #2      #    99 #",
  55.                          "#k ####  # ### #####",
  56.                          "# 2   9  # 9     2!#",
  57.                          "####################"};
  58.         }break;
  59.         case 2:{
  60.      char map[10][25] = {"loominaty#",
  61.                          "        #2#",
  62.                          "       #2 2#",
  63.                          "      #     #",
  64.                          "     #   9   #",
  65.                          "    #  99k99  #",
  66.                          "   #2    9     #",
  67.                          "  #       2     #",
  68.                          " #@             !#",
  69.                          "###################"};
  70.         }break;
  71.         case 3:
  72.             {
  73.      char map[10][25] = {" ##################",
  74.                          "#99             29k#",
  75.                          "#9       2        9#",
  76.                          "#    ##      ##  2 #",
  77.                          "#    ##     2##    #",
  78.                          "# 2      !         #",
  79.                          "# ################ #",
  80.                          "#9@ ############  9#",
  81.                          "#99       2      99#",
  82.                          " ##################"};
  83.             }break;
  84.         case 4:{
  85.     char map[10][25] = { "####################",
  86.                          "#@          9     2#",
  87.                          "################## #",
  88.                          "###! 2           # #",
  89.                          "################ # #",
  90.                          "################ #2#",
  91.                          "#               2# #",
  92.                          "# ################k#",
  93.                          "#2        9       2#",
  94.                          "####################"};
  95.         }break;
  96.         case 5:{
  97.     char map[10][25] = { "####################",
  98.                          "#@       2      !###",
  99.                          "#  ############## k#",
  100.                          "#    ########## 2  #",
  101.                          "#   92######## 9   #",
  102.                          "#     ########  2  #",
  103.                          "# 2  ##########    #",
  104.                          "#  ##############  #",
  105.                          "#     2   9      2 #",
  106.                          "####################"};
  107.             }break;
  108.         case 6:{
  109.     char map[10][25] = { "####################",
  110.                          "##@              2 #",
  111.                          "#!#  2  ## 2 ####  #",
  112.                          "#  #    #2# ########",
  113.                          "##  ##### # #####  #",
  114.                          "###  9       ###   #",
  115.                          "####  2 ##     9  2#",
  116.                          "##### #####  2 #   #",
  117.                          "###############k   #",
  118.                          "####################"};
  119.             }break;
  120.         case 7:{
  121.     char map[10][25] = { "####################",
  122.                          "#####  2   2   #####",
  123.                          "#######      #######",
  124.                          "######2 #  #  ######",
  125.                          "#####  ## 2##  #####",
  126.                          "####  ###  ###  ####",
  127.                          "###  ####  #### 2###",
  128.                          "##  ##### 2#####  ##",
  129.                          "#@9######k9######9!#",
  130.                          "####################"};
  131.             }break;
  132.         case 8:{
  133.     char map[10][25] = { "####################",
  134.                          "#99999999##99999999#",
  135.                          "#999999##@ ##999999#",
  136.                          "#9999##2    2##9999#",
  137.                          "#99##!    2   k##99#",
  138.                          "#9999## 2 2  ##9999#",
  139.                          "#999999##  ##999999#",
  140.                          "#99999999##99999999#",
  141.                          "####################"};
  142.             }break;
  143.         case 9:{
  144.     char map[10][25] = { "####################",
  145.                          "#         2     2 !#",
  146.                          "# ##  ## ##        #",
  147.                          "# ##@ ## ##  # ##  #",
  148.                          "# ######  2    ### #",
  149.                          "# ###### ##    ### #",
  150.                          "# ##k ## ##  # ##  #",
  151.                          "# ## 2## ##     2  #",
  152.                          "#         2        #",
  153.                          "####################"};
  154.             }break;
  155.         case 10:{
  156.     char map[10][25] = { "####################",
  157.                          "#                  #",
  158.                          "#     THANKS       #",
  159.                          "#     FOR@         #",
  160.                          "#     PLAYING!     #",
  161.                          "#                  #",
  162.                          "#                  #",
  163.                          "#                  #",
  164.                          "#                  #",
  165.                          "####################"};
  166.             }break;
  167.     case 11:{
  168.         system("cls");
  169.         cout << "aha... So you discovered the secret level. Good Job" << endl;
  170.         system("pause");
  171.     char map[10][25] = { "####################",
  172.                          "#2#@k999999999999#2#",
  173.                          "###99999999999999###",
  174.                          "#999999999999999999#",
  175.                          "#999999999999999999#",
  176.                          "#999999999999999999#",
  177.                          "#999999999999999999#",
  178.                          "###99999999999999###",
  179.                          "#2#9999999999999!#2#",
  180.                          "####################"};
  181.  
  182.     }break;
  183.     case 12:
  184.         {
  185.             cout << "YOU WIN!!!!!!!!!!!!!" << endl;
  186.             Sleep(2000);
  187.             system("pause");
  188.             *lvl = 1;
  189.             mainSys();
  190.         }break;
  191. }
  192.     while(isDone == false){
  193.             Sleep(50);
  194.         cout << string(100,'\n');
  195.  
  196.         for(int y = 0; y <10; y++){
  197.             cout << map[y] << endl;
  198.         }
  199.         for(int y = 0; y < 10; y++){
  200.             for(int x = 0; x < 25; x++){
  201.                 char level = map[y][x];
  202.                 switch(level){
  203.                 case '@':{
  204.                    map[y][x] = 1;}
  205.                    break;
  206.                 case '#':
  207.                    {map[y][x] = 219;}
  208.                     break;
  209.                 case '!':
  210.                    {if(key==true){map[y][x] = 3;}}
  211.                    break;
  212.                 case '2':
  213.                     {map[y][x] = 2;
  214.                 case 2:
  215.                     int movems = movement();
  216.                     switch(movems){
  217.                         case 1:{
  218.                             Sleep(speed + 200);
  219.                         int y2=y-1;
  220.                         switch(map[y2][x]){
  221.                         case ' ':
  222.                             {
  223.                                 map[y][x] = ' ';
  224.                                 y-=1;
  225.                                 map[y2][x] = 2;
  226.                             }break;
  227.                         case 1:{
  228.                         f.war();
  229.                         map[y][x] = ' ';
  230.                         points++;
  231.                         score+=10;
  232.                         }
  233.                         }
  234.                     }
  235.                     break;
  236.                         case 2:{
  237.                             Sleep(speed);
  238.                         int y2=y+1;
  239.                         switch(map[y2][x]){
  240.                         case ' ':
  241.                             {
  242.                                 map[y][x] = ' ';
  243.                                 y+=1;
  244.                                 map[y2][x] = 2;
  245.                             }break;
  246.                         case 1:{
  247.                         f.war();
  248.                         map[y][x] = ' ';
  249.                         points++;
  250.                         score+=10;
  251.                         }
  252.                         }
  253.                     }break;
  254.                         case 3:{
  255.                             Sleep(speed + 200);
  256.                         int x2=x-1;
  257.                         switch(map[y][x2]){
  258.                         case ' ':
  259.                             {
  260.                                 map[y][x] = ' ';
  261.                                 x-=1;
  262.                                 map[y][x2] = 2;
  263.                             }break;
  264.                         case 1:{
  265.                         f.war();
  266.                         map[y][x] = ' ';
  267.                         points++;
  268.                         score+=10;
  269.                         }
  270.                         }
  271.                     }break;
  272.                         case 4:{
  273.                             Sleep(speed + 200);
  274.                         int x2=x+1;
  275.                         switch(map[y][x2]){
  276.                         case ' ':
  277.                             {
  278.                                 map[y][x] = ' ';
  279.                                 x+=1;
  280.                                 map[y][x2] = 2;
  281.                             }break;
  282.                         case 1:{
  283.                         f.war();
  284.                         map[y][x] = ' ';
  285.                         points++;
  286.                         score+=10;
  287.                         }
  288.                         }
  289.                     }break;
  290.                     }
  291.                     }
  292.                     break;
  293.                 case '9':
  294.                     {map[y][x] = 4;}
  295.                 }
  296.  
  297.                     switch(level){
  298.                 case 1:{
  299.  
  300.                     char input;
  301.  
  302.                     if(GetAsyncKeyState('D') != 0){
  303.                         input = 'd';
  304.                     }
  305.                     if(GetAsyncKeyState('A') != 0){
  306.                         input = 'a';
  307.                     }
  308.                     if(GetAsyncKeyState('W') !=0){
  309.                         input = 'w';
  310.                     }
  311.                     if(GetAsyncKeyState('S') != 0){
  312.                         input = 's';
  313.                     }
  314.                     switch(input){
  315.                     case 'w':
  316.                     case 'W':
  317.                         input = NULL;
  318.                         Sleep(speed);
  319.                         {int y2 = y-1;
  320.                         switch(map[y2][x]){
  321.                         break;
  322.                         case 2:{
  323.                             map[y2][x] = ' ';
  324.                             f.war();
  325.                             points++;
  326.                             score+=10;}
  327.                             break;
  328.                             case 4:
  329.                                 score+=5;
  330.                         case ' ':
  331.                             steps++;
  332.                             map[y][x] = ' ';
  333.                             y-=1;
  334.                             map[y2][x] = 1;
  335.                             break;
  336.                         case 'K':
  337.                         case 'k':{
  338.                             map[y][x] = ' ';
  339.                             map[y2][x] = 1;
  340.                             key = true;
  341.                         }break;
  342.                          case 3:
  343.                              {if(key==true){system("cls");
  344.  
  345.                               *lvl+=1;
  346.                               mainSys();}}}}
  347.                               break;
  348.  
  349.                         break;
  350.                         case 's':
  351.                         case 'S':
  352.                             input = NULL;
  353.                             Sleep(speed);
  354.                             {int y2 = y+1;
  355.                         switch(map[y2][x]){
  356.                         break;
  357.                         case 2:{
  358.                             map[y2][x] = ' ';
  359.                             f.war();
  360.                             points++;
  361.                             score+=10;}
  362.                             break;
  363.                             case 4:
  364.                                 score+=5;
  365.                             case ' ':
  366.                                 steps++;
  367.                                 map[y][x] = ' ';
  368.                                 y+=1;
  369.                                 map[y2][x] = 1;
  370.                                 break;
  371.                             case 'K':
  372.                             case 'k':{
  373.                             map[y][x] = ' ';
  374.                             map[y2][x] = 1;
  375.                             key = true;
  376.                         }break;
  377.                             case 3:
  378.                              {if(key==true){system("cls");
  379.  
  380.                               *lvl+=1;
  381.                               mainSys();}}}}
  382.                               break;
  383.                         case 'd':
  384.                         case 'D':
  385.                             input = NULL;
  386.                             Sleep(speed);
  387.                             {int x2 = x+1;
  388.                             switch(map[y][x2]){
  389.                             case 'P':{
  390.                                 *lvl+=1;
  391.                                 mainSys();
  392.                             }break;
  393.                             case 'I':{
  394.                                 system("cls");
  395.                                 cout << "Use W/S/A/D to move" << endl;
  396.                                 cout << "Collect (k)eys to unlock next level" << endl;
  397.                                 cout << "bumping into enemies (2) takes you to battle" << endl;
  398.                                 cout << "When you die, you are dead for good" << endl;
  399.                                 system("pause");
  400.                                 mainSys();
  401.                             }break;
  402.                             case 'C':{
  403.                                 system("cls");
  404.                                 cout << "Game made by nuvindu with c++" << endl;
  405.                                 cout << "made in Code::Blocks" << endl;
  406.                                 cout << "2015" << endl;
  407.                                 system("pause");
  408.                                 mainSys();
  409.                             }break;
  410.                             case 'Q':{
  411.                                 exit(0);
  412.                             }break;
  413.                                 case 2:{
  414.                                     map[y][x2] = ' ';
  415.                             f.war();
  416.                             points++;
  417.                             score+=10;}
  418.                             break;
  419.                             case 4:
  420.                                 score+=5;
  421.                             case ' ':
  422.                                 steps++;
  423.                                 map[y][x] = ' ';
  424.                                 x+=1;
  425.                                 map[y][x2] = 1;
  426.                                 break;
  427.                                 case 'K':
  428.                                 case 'k':{
  429.                             map[y][x] = ' ';
  430.                             map[y][x2] = 1;
  431.                             key = true;
  432.                         }break;
  433.                             case 3:
  434.                              {if(key==true){system("cls");
  435.  
  436.                               *lvl+=1;
  437.                               mainSys();}}}}
  438.                               break;
  439.  
  440.                         case 'a':
  441.                         case 'A':
  442.                             input = NULL;
  443.                             Sleep(speed);
  444.                             {int x2 = x-1;
  445.                             switch(map[y][x2]){
  446.                         break;
  447.                                 case 2:{
  448.                                     map[y][x2] = ' ';
  449.                             f.war();
  450.                             points++;
  451.                             score+=10;}
  452.                             break;
  453.                             case 4:
  454.                                 score+=5;
  455.                             case ' ':
  456.                                 steps++;
  457.                                 map[y][x] = ' ';
  458.                                 x-=1;
  459.                                 map[y][x2] = 1;
  460.                                 break;
  461.                                 case 'K':
  462.                                 case 'k':{
  463.                             map[y][x] = ' ';
  464.                             map[y][x2] = 1;
  465.                             key = true;
  466.                         }break;
  467.                             case 3:
  468.                              {if(key==true){system("cls");
  469.  
  470.                               *lvl+=1;
  471.                               mainSys();}}}}
  472.                               break;
  473.                             }
  474.                     }
  475.                     break;
  476.                     }
  477.                 }
  478.             }
  479.         }
  480. }
  481. int game::movement(){
  482.     int i =1+ (rand() + time(0)) %4;
  483.     return i;
  484. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement