Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <cstdio>
- #include <ctime>
- #include <windows.h>
- #include"Alien1.h"
- #include"alien2.h"
- #include "Ship.h"
- using namespace std;
- void printtab(char board[15][20])
- {
- for (int i = 0; i < 15; i++)
- {
- for (int j = 0; j < 20; j++) cout << board[i][j];
- cout << endl;
- }
- }
- template <class Type>
- void inserttab(Type tab[30], char board[15][20], Ship &player)
- {
- int tempx, tempy;
- for (int i = 0; i < 30; i++)
- {
- {
- if (tab[i].life > 0)
- {
- if (tab[i].y<20)
- board[tab[i].y][tab[i].x] = tab[i].symbole;
- }
- }
- }
- board[player.y][player.x] = player.symbole;
- for (int i = 0; i < 100; i++)
- {
- if (player.tab[i].readl() > 0)
- {
- tempx = player.tab[i].readx();
- tempy = player.tab[i].ready();
- if (board[tempy][tempx] == 'O' || board[tempy][tempx] == '@') { colision(tab, player.tab[i]); }
- board[tempy][tempx] = player.tab[i].reads();
- }
- }
- }
- template <class Type>
- void colision(Type *tab, Bullet &temp)
- {
- for (int i = 0; i < 30; i++)
- {
- if (tab[i].x == temp.x && tab[i].y == temp.y)
- {
- tab[i].life--;
- temp.life = 0;
- }
- }
- }
- int main()
- {
- srand(time(NULL));
- char board[15][20] =
- {
- "###################",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "# #",
- "###################"
- };
- Alien1 Al1[30];
- Alien2 Al2[30];
- Ship player;
- int temp = 0;
- int countertab = 0;
- int cont = 0;
- int flag = 1;
- while (1)
- {
- if (GetAsyncKeyState(VK_LEFT) != 0) player.moveleft();
- if (GetAsyncKeyState(VK_RIGHT) != 0) player.moveright();
- if (GetAsyncKeyState(VK_UP) != 0) player.shot();
- temp = ((rand() % 10) + 0);
- if (countertab < 30 && (cont % 10 == 0))
- {
- if(temp < 3) Al1[countertab].born();
- else Al2[countertab].born();
- countertab++;
- }
- inserttab(Al1, board,player);
- inserttab(Al2, board,player);
- printtab(board);
- if (cont%10 == 0)
- {
- for (int i = 0; i < 30; i++)
- {
- Al2[i].movedown();
- Al1[i].movedown();
- }
- }
- for (int i = 0; i < 15; i++)
- for (int j = 0; j < 20; j++) board[i][j] = clon[i][j];
- player.shotup();
- if (countertab >= 30)
- {
- for (int i = 0; i < 30; i++)
- {
- if ( (Al1[i].readlife()) >0 || (Al2[i].readlife()) > 0) { flag = 1; break; }
- else { flag = 0; }
- }
- if (flag == 0) { system("cls"); cout << "WYGRAGLES!" << endl << endl << endl; system("pause"); exit(0); };
- }
- cont++;
- Sleep(100);
- system("cls");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement