Advertisement
kamillo111

MainSpace

Jan 22nd, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <ctime>
  5. #include <windows.h>
  6. #include"Alien1.h"
  7. #include"alien2.h"
  8. #include "Ship.h"
  9. using namespace std;
  10.  
  11.  
  12.  
  13. void printtab(char board[15][20])
  14. {
  15.     for (int i = 0; i < 15; i++)
  16.  
  17.     {
  18.         for (int j = 0; j < 20; j++) cout << board[i][j];
  19.  
  20.         cout << endl;
  21.     }
  22.    
  23. }
  24.  
  25. template <class Type>
  26. void inserttab(Type tab[30], char board[15][20], Ship &player)
  27. {
  28.     int tempx, tempy;
  29.     for (int i = 0; i < 30; i++)
  30.     {
  31.        
  32.         {
  33.             if (tab[i].life > 0)
  34.             {
  35.                 if (tab[i].y<20)
  36.                 board[tab[i].y][tab[i].x] = tab[i].symbole;
  37.             }
  38.         }
  39.     }
  40.     board[player.y][player.x] = player.symbole;
  41.  
  42.     for (int i = 0; i < 100; i++)
  43.     {
  44.         if (player.tab[i].readl() > 0)
  45.         {
  46.             tempx = player.tab[i].readx();
  47.             tempy = player.tab[i].ready();
  48.  
  49.             if (board[tempy][tempx] == 'O' || board[tempy][tempx] == '@') { colision(tab, player.tab[i]);  }
  50.                
  51.             board[tempy][tempx] = player.tab[i].reads();
  52.            
  53.         }
  54.     }
  55. }
  56.  
  57. template <class Type>
  58. void colision(Type *tab, Bullet &temp)
  59. {
  60.     for (int i = 0; i < 30; i++)
  61.     {
  62.         if (tab[i].x == temp.x && tab[i].y == temp.y)
  63.         {
  64.             tab[i].life--;
  65.             temp.life = 0;
  66.            
  67.         }
  68.     }
  69.  
  70. }
  71.  
  72.  
  73.  
  74. int main()
  75. {
  76.     srand(time(NULL));
  77.     char board[15][20] =
  78.     {
  79.         "###################",
  80.         "#                 #",
  81.         "#                 #",
  82.         "#                 #",
  83.         "#                 #",
  84.         "#                 #",
  85.         "#                 #",
  86.         "#                 #",
  87.         "#                 #",
  88.         "#                 #",
  89.         "#                 #",
  90.         "#                 #",
  91.         "#                 #",
  92.         "#                 #",
  93.         "###################"
  94.     };
  95.  
  96.  
  97.     Alien1 Al1[30];
  98.     Alien2 Al2[30];
  99.     Ship player;
  100.     int temp = 0;
  101.     int countertab = 0;
  102.     int cont = 0;
  103.     int flag = 1;
  104.  
  105.     while (1)
  106.     {
  107.        
  108.             if (GetAsyncKeyState(VK_LEFT) != 0) player.moveleft();
  109.             if (GetAsyncKeyState(VK_RIGHT) != 0) player.moveright();
  110.             if (GetAsyncKeyState(VK_UP) != 0)  player.shot();
  111.  
  112.         temp = ((rand() % 10) + 0);
  113.  
  114.         if (countertab < 30 && (cont % 10 == 0))
  115.         {
  116.             if(temp < 3) Al1[countertab].born();
  117.             else Al2[countertab].born();
  118.             countertab++;
  119.         }
  120.        
  121.        
  122.         inserttab(Al1, board,player);
  123.         inserttab(Al2, board,player);
  124.         printtab(board);
  125.        
  126.        
  127.         if (cont%10 == 0)
  128.         {
  129.         for (int i = 0; i < 30; i++)
  130.             {  
  131.                 Al2[i].movedown();
  132.                 Al1[i].movedown();
  133.             }
  134.         }
  135.        
  136.         for (int i = 0; i < 15; i++)
  137.         for (int j = 0; j < 20; j++) board[i][j] = clon[i][j];
  138.        
  139.         player.shotup();
  140.        
  141.         if (countertab >= 30)
  142.         {
  143.             for (int i = 0; i < 30; i++)
  144.             {
  145.                 if ( (Al1[i].readlife()) >0 || (Al2[i].readlife()) > 0) { flag = 1; break; }
  146.                 else { flag = 0; }
  147.             }
  148.             if (flag == 0) { system("cls"); cout << "WYGRAGLES!" << endl << endl << endl;  system("pause"); exit(0); };
  149.         }
  150.  
  151.         cont++;
  152.         Sleep(100);
  153.  
  154.         system("cls");
  155.        
  156.     }
  157.  
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement