Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include <conio.h>
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include <stdio.h>
- #define LATIME 30
- #define LUNGIME 30
- #define SIMBOL_MARGINE1 '-'
- #define SIMBOL_MARGINE2 '|'
- #include <windows.h>
- using namespace std;
- void gotoxy( int column, int line ) //
- {
- COORD coord;
- coord.X = column;
- coord.Y = line;
- SetConsoleCursorPosition(
- GetStdHandle( STD_OUTPUT_HANDLE ),
- coord
- );
- }
- char Monster[4][4];
- bool GAMEEND = false;
- char matTer[LUNGIME][LATIME];
- long long Score,M_ShootRate=0;
- short int pozNava = 15, Player_Lifes=3;
- void show_cursor(bool show){ //vizibilitate curosor in consola
- HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO infCursor;
- GetConsoleCursorInfo(out, &infCursor);
- infCursor.bVisible = show;
- SetConsoleCursorInfo(out, &infCursor);
- }
- void DEL_Monster(int m, int n){
- for(int i = m - 1; i <= m + 3; i++)
- for(int j = n; j<=n + 3; j++)
- if(matTer[i][j]!=char(219))
- matTer[i][j]='\0';
- }
- void afisare(){
- for (int i = 1; i <= LUNGIME - 1; i++){
- for (int j = 1; j <= LATIME - 1; j++)
- cout << matTer[i][j];
- cout << endl;
- }
- }
- void creare_teren(){
- int i;
- for (i = 1; i <= LATIME ; i++)
- matTer[i][1] = matTer[i][LUNGIME - 1] = SIMBOL_MARGINE2;
- for (i = 1; i <= LUNGIME - 1; i++)
- matTer[1][i] = matTer[LATIME - 1][i] = SIMBOL_MARGINE1;
- }
- void nava(){
- matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-2][pozNava] = matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = (char)219;
- }
- void Check_KeyPress ()
- {
- char newKey;
- if (_kbhit())
- newKey = _getch();
- if(newKey == 'd' ||newKey == 'D')
- if(pozNava < LATIME-3){
- matTer[LUNGIME-2][pozNava + 2] = matTer[LUNGIME-2][pozNava];
- matTer[LUNGIME-3][pozNava+1] =matTer[LUNGIME-2][pozNava] ;
- matTer[LUNGIME-2][pozNava-1] = matTer[LUNGIME-3][pozNava] = '\0';
- pozNava++;
- }
- if(newKey == 'a' || newKey == 'A')
- if(pozNava > 3){
- matTer[LUNGIME-2][pozNava-2] = matTer[LUNGIME-3][pozNava-1]= char(219);
- matTer[LUNGIME-2][pozNava+1] = matTer[LUNGIME-3][pozNava] = '\0';
- pozNava--;
- }
- if(newKey == (char)32){
- matTer[LUNGIME-4][pozNava] = char(248);
- }
- }
- void Delete_Monster(int x, int y)
- {
- if(matTer[x][y]=='o' && matTer[x][y-1]=='\0' && matTer[x][y+1]=='\0')
- {
- matTer[x][y] = matTer[x-1][y] = matTer[x-1][y-1]= matTer[x-1][y+1] = matTer[x-2][y-1] = matTer[x-2][y+1] = '\0';
- }
- else
- if(matTer[x][y]=='o' && matTer[x][y-1]=='o' && matTer[x][y+1]=='\0')
- matTer[x+1][y-1] = matTer[x][y-1] = matTer[x][y]= matTer[x][y-2] = matTer[x-1][y] = matTer[x-1][y-2] = '\0';
- else
- if(matTer[x][y]=='o' && matTer[x][y+1]=='o' && matTer[x][y-1]=='\0')
- matTer[x+1][y+1] = matTer[x][y+1] = matTer[x][y]= matTer[x][y+2] = matTer[x-1][y] = matTer[x-1][y+2] = '\0';
- }
- int Last_monster(int i)
- {
- for( int j=4;j<=LUNGIME;j+=4)
- if(matTer[j][i]=='o' && matTer[j+4][i]=='\0')
- return j;
- return 0;
- }
- void Generate_Monster_Bullets()
- {
- if(Last_monster(3)!=0 && M_ShootRate%50==49)
- matTer[Last_monster(3)+1][3]='.';
- if(Last_monster(7)!=0 && M_ShootRate%50==32)
- matTer[Last_monster(7)+1][7]='.';
- if(Last_monster(11)!=0 && M_ShootRate%50==23)
- matTer[Last_monster(11)+1][11]='.';
- if(Last_monster(15)!=0 && M_ShootRate%50==1)
- matTer[Last_monster(15)+1][15]='.';
- if(Last_monster(19)!=0 && M_ShootRate%50==10)
- matTer[Last_monster(19)+1][19]='.';
- if(Last_monster(23)!=0 && M_ShootRate%50==40)
- matTer[Last_monster(23)+1][23]='.';
- if(Last_monster(27)!=0 && M_ShootRate%50==17)
- matTer[Last_monster(27)+1][27]='.';
- M_ShootRate++;
- }
- void Bullet_Movement ()
- {
- int i, j;
- for(i=2;i<=LATIME-1;i++)
- for(j=2;j<=LUNGIME-1;j++)
- {if (matTer[i][j]==char(248))
- if(i==2)
- matTer[i][j]='\0';
- else
- if(matTer[i-1][j]=='\0')
- {matTer[i-1][j]=char(248);
- matTer[i][j]='\0'; }
- else
- if(matTer[i-1][j]=='o')
- {Delete_Monster(i-1, j);
- matTer[i][j]='\0';
- Score+= 500; }
- }
- Generate_Monster_Bullets();
- char aux;
- for(i=2;i<=LATIME-1;i++)
- for(j=2;j<=LUNGIME-1;j++)
- {if(matTer[j][i]=='.')
- if(matTer[j+1][i]=='\0')
- {if(M_ShootRate%5==0)
- {matTer[j+1][i]='.';
- matTer[j][i]='\0'; j+=2;}
- }
- else
- if(matTer[j+1][i]==char(219))
- {Player_Lifes--;
- Sleep(2000);
- matTer[j][i]='\0';
- Score-=1000;
- if(Player_Lifes==0)
- GAMEEND=TRUE;
- }
- else
- if(matTer[j+1][i]==char(248))
- {Sleep(120);
- aux=matTer[j+1][i];
- matTer[j+1][i]=matTer[j][i];
- matTer[j][i]=aux;
- }
- else
- if (j==LUNGIME-2)
- matTer[j][i]='\0';
- }
- }
- void Create_Monsters()
- {
- int i,j;
- for(i=2;i<=LUNGIME/2;i+=4)
- for(j=2;j<=LATIME-3;j+=4)
- {matTer[i][j]= matTer[i][j+2] = matTer[i+1][j] = matTer[i+1][j+1]= matTer[i+1][j+2]=matTer[i+2][j+1]= 'o';
- }
- }
- void GameOver_Animation()
- {
- gotoxy(11,15);
- cout<<"GAME";
- gotoxy(11,16); cout<<"OVER";
- gotoxy(11,17);
- cout<<"FINAL SCORE: ";
- gotoxy(11,18); cout<<Score;
- Sleep(5500);
- gotoxy(0, 32);
- }
- int main (){
- char x,y;
- show_cursor(false);
- while(x!='4' )
- {cout << "_______________________________________________________________________" << endl;
- cout << "| |" << endl;
- cout << "| * * *** * *** ** * * *** |" << endl;
- cout << "| * * * ** * * * * * * * ** |" << endl;
- cout << "| * * *** *** *** ** * * *** |" << endl;
- cout << "| |" << endl;
- cout << "| |" << endl;
- cout << "| PRESS 1 TO START GAME |" << endl;
- cout << "| PRESS 2 FOR INSTRUCTIONS |" << endl;
- cout << "| PRESS 3 TO KNOW MORE ABOUT THE GAME |" << endl;
- cout << "| PRESS 4 TO QUIT |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin >> x;
- system("cls");
- if(x == '1'){
- creare_teren();
- nava();
- Create_Monsters();
- afisare();
- while (GAMEEND==FALSE)
- {
- Check_KeyPress();
- Sleep(100);
- gotoxy(0, 0);
- Bullet_Movement();
- afisare();
- Score++;
- cout<<"Scor:"<<Score<<" "<<"Lifes: ";
- for(int h=1;h<=Player_Lifes;h++)
- cout<< char(254)<< ' ';
- }
- GameOver_Animation();
- x='4';
- }
- else
- if(x=='2')
- {
- gotoxy(0, 0);
- cout << "_______________________________________________________________________" << endl;
- cout << "| |"<< endl;
- cout << "| USE 'D' KEY TO MOVE TO RIGHT |"<<endl;
- cout << "| USE 'A' KEY TO MOVE LEFT |"<< endl;
- cout << "| USE SPACEBAR TO SHOOT |"<< endl;
- cout << "| |"<< endl;
- cout << "| YOUR GOAL IS TO KILL ALL THE INVADERS AND SAVE OUR PLANET |"<< endl;
- cout << "| THE WHOLE WORLD COUTS ON YOU. DO NOT DISAPPOINT |"<< endl;
- cout << "| GOOD LUCK IN YOUR JOURNEY |"<< endl;
- cout << "| |"<< endl;
- cout << "| PRESS B TO GO BACK TO MAIN MENU |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin >> x;
- system("cls");
- }
- else
- if(x=='3')
- { system("cls");
- cout << "_______________________________________________________________________" << endl;
- cout << "| |"<< endl;
- cout << "| MADE BY: Aenasoaei Denis-Claudiu |"<< endl;
- cout << "| DEVELOPED IN: CODE::BLOCKS IDE |"<< endl;
- cout << "| PROFESOR COORDONATOR: Hulea Monica |"<< endl;
- cout << "| |"<< endl;
- cout << "| PRESS B TO GO BACK TO MAIN MENU |" << endl;
- cout << "|______________________________________________________________________|" << endl;
- cin>> x;
- gotoxy(0,0);
- system("cls");}
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement