Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <time.h>
- #include <cstdlib>
- #include <string.h>
- using namespace std;
- char v[12][12], g[12][12], l, xc[3], def, dirv[10], opt[10];
- int i, j, k, dir, x, y, steps, heads, eff, something, lang, mainOpt, c1, c2, c3;
- char c, rdy, player1[20], player2[20], aux[20], t;
- float timeInterval, start, stop, q;
- struct plane
- {
- int x;
- int y;
- int dir;
- };
- void sleep(long d)
- {
- clock_t start = clock();
- while(clock() - start < d);
- }
- void cleanVector(char v[12][12])
- {
- def = 1;
- int def = 1;
- for(i = 1; i <= 10; i++)
- {
- for(j = 1; j <= 10; j++)
- v[i][j] = def;
- }
- }
- int isTheVectorAlright(int k, char v[12][12])
- {
- int hm;
- bool alright = false;
- for(i = 1; i <= 10; i++)
- {
- for(j = 1; j <= 10; j++)
- {
- if(v[i][j] == 2)
- hm++;
- }
- }
- if(hm == k * 8)
- alright = true;
- return alright;
- }
- void showVector(char v[12][12])
- {
- cout << ' ' << ' ';
- l = 'a';
- cout << " ";
- for(i = 1; i <= 10; i++)
- cout << i << ' ';
- cout << endl;
- cout << endl;
- for(i = 1; i <= 10; i++)
- {
- cout << " ";
- cout << l << " ";
- l = l + 1;
- for(j = 1; j <= 10; j++)
- cout << v[i][j] << ' ';
- cout << " " << l;
- cout << endl;
- }
- cout << endl << " ";
- for(i = 1; i <= 10; i++)
- cout << i << ' ';
- cout << endl;
- }
- void slidingShowVector(char v[12][12])
- {
- cout << ' ' << ' ';
- l = 'a';
- cout << " ";
- for(i = 1; i <= 10; i++)
- cout << i << ' ';
- cout << endl;
- cout << endl;
- for(i = 1; i <= 10; i++)
- {
- cout << " ";
- cout << l << " ";
- l = l + 1;
- sleep(17);
- for(j = 1; j <= 10; j++)
- cout << v[i][j] << ' ';
- cout << " " << l;
- cout << endl;
- }
- cout << endl << " ";
- for(i = 1; i <= 10; i++)
- cout << i << ' ';
- cout << endl;
- }
- void askDirection()
- {
- cout << " * *** * * * *" << endl; sleep(50);
- cout << " 1)*** 2) * 3) **** 4) ****" << endl; sleep(50);
- cout << " * *** * * * *" << endl; sleep(50);
- cout << " *** * " << endl;
- }
- void addPlane(int &dir, int x, int y, char v[12][12])
- {
- c = 2;
- if(dir == 1)
- {
- v[x][y] = c;
- v[x + 1][y - 1] = c;
- v[x + 1][y] = c;
- v[x + 1][y + 1] = c;
- v[x + 2][y] = c;
- v[x + 3][y] = c;
- v[x + 3][y + 1] = c;
- v[x + 3][y - 1] = c;
- }
- else if(dir == 2)
- {
- v[x][y] = c;
- v[x - 1][y - 1] = c;
- v[x - 1][y] = c;
- v[x - 1][y + 1] = c;
- v[x - 2][y] = c;
- v[x - 3][y - 1] = c;
- v[x - 3][y] = c;
- v[x - 3][y + 1] = c;
- }
- else if(dir == 3)
- {
- v[x][y] = c;
- v[x + 1][y + 1] = c;
- v[x][y + 1] = c;
- v[x - 1][y + 1] = c;
- v[x][y + 2] = c;
- v[x + 1][y + 3] = c;
- v[x][y + 3] = c;
- v[x - 1][y + 3] = c;
- }
- else if(dir == 4)
- {
- v[x][y] = c;
- v[x + 1][y - 1] = c;
- v[x][y - 1] = c;
- v[x - 1][y - 1] = c;
- v[x][y - 2] = c;
- v[x + 1][y - 3] = c;
- v[x][y - 3] = c;
- v[x - 1][y - 3] = c;
- }
- }
- int main()
- {
- player1 = {'P','l','a','y','e','r',' ',' 1'};
- player2 = {'P','l','a','y','e','r',' ',' 2'};
- Menu1:
- opt[0] = 0;
- while((strlen(opt) != 1) or (opt[0] != '1' and opt[0] != '2' and opt[0] != '3' and opt[0] != '4' and opt[0] != '5' and opt[0] != '6' ))
- {
- system("cls");
- cout << endl;
- cout << " Bun venit la Avionase!" << endl; sleep(200);
- cout << "" << player1 << " vs ";
- cout << player2 << endl; sleep(200);
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- cout << " | | " << endl; sleep(50);
- cout << " | 1. Joc nou [lovituri] | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | 2. Joc nou [lovituri + timp] | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | 3. Schimba numele jucatorilor | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | 4. Schimba rolurile | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | 5. Cum se joaca? | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " | 6. Iesire | " << endl; sleep(50);
- cout << " | | " << endl; sleep(50);
- cout << " |"; sleep(50);
- for(i = 1; i <= 43; i++)
- {
- cout << '-'; sleep(10);
- }
- cout << "|";
- cout << " ";cin >> opt;
- }
- if (opt[0] == '5')
- {
- system("cls");
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(10);
- }
- cout << endl;
- cout << "Acest joc e bazat pe jocul denumit popular 'avioane'. Are aceeleasi principii," << endl; sleep(50);
- cout << "un jucator plaseaza 3 avioane pe o grila 10*10, iar celalalt jucator incearca " << endl; sleep(50);
- cout << "sa ghiceasca cum au fost plasate. Pentru a plasa un avion, prima data trebuie " << endl; sleep(50);
- cout << "sa introduci coordonatele varfului(capului) sau, iar apoi sa alegi modul in " << endl; sleep(50);
- cout << "care doresti sa-l plasezi. Spre exemplu, daca vrei sa adaugi un avion care " << endl; sleep(50);
- cout << "sa-nceapa din casuta b2 si sa aiba restul corpului in jos, scrii b2, iar apoi " << endl; sleep(50);
- cout << "alegi orientarea acestuia, in cazul de fata, '2'. Oricum, n-ai cum sa dai gres." << endl; sleep(50);
- cout << "Distractie placuta!" << endl << endl;
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(10);
- }
- cout << endl << " 1.Inapoi la meniu" << endl;
- cout << " ";
- mainOpt = 0;
- while(mainOpt != 1)
- {
- cin >> mainOpt;
- }
- goto Menu1;
- }
- else if(opt[0] == '6')
- {
- }
- else if(opt[0] == '3')
- {
- system("cls");
- cout << endl << endl << endl << endl << endl << endl << endl << endl;
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- cout << " Introdu numele primului jucator (cel care plaseaza avioanele): " << endl << endl;
- cout << " ";
- cin >> player1;
- cout << endl;
- cout << " ";
- for(i = 1; i <= 10; i++)
- {
- cout << '-'; sleep(6);
- }
- cout << endl << endl;
- cout << " Introdu numele celui de-al doilea jucator (cel care le ghiceste): " << endl << endl;
- cout << " ";
- cin >> player2;
- cout << endl;
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- goto Menu1;
- }
- else if(opt[0] == '4')
- {
- SwitchAgain1:
- int opt2;
- system("cls");
- cout << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl << endl;
- cout << " ";
- cout << "Schimb rolurile";
- sleep(400);
- cout << ".";
- sleep(400);
- cout << ".";
- sleep(400);
- cout << ".";
- system("cls");
- for(i = 0; i <= 20; i++)
- aux[i] = player1[i];
- for(i = 0; i <= 20; i++)
- player1[i] = player2[i];
- for(i = 0; i <= 20; i++)
- player2[i] = aux[i];
- if(something == 3)
- {
- something = 0;
- goto playAgain1;
- }
- cout << endl << endl << endl << " Roluri schimbate. " << endl << endl << endl;
- (player1[strlen(player1) - 1]=='a')? cout << " Cea": cout << " Cel";
- cout << " care plaseaza avioanele este acum " << player1 << "." << endl << endl;sleep(50);
- (player2[strlen(player2) - 1]=='a')? cout << " Cea": cout << " Cel";
- cout << " care le ghiceste e " << player2 << "." << endl << endl << endl; sleep(50);
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- cout << endl << endl << endl;
- cout << " 1. Inapoi la Meniul principal" << endl << endl << endl; sleep(50);
- cout << " 2. Schimba din nou" << endl << endl << endl; sleep(50);
- cin >> opt2;
- if(opt2 == 2)
- goto SwitchAgain1;
- else
- goto Menu1;
- }
- else if(opt[0] == '1' or opt[0] == '2')
- {
- playAgain1:
- system("cls");
- cout << endl << " Inainte sa-ncepi, asigura-te ca " << player2 << " nu trage cu ochiul la ce scrii! :)" << endl;sleep(50);
- cout << " Distractie placuta!" << endl << endl; sleep(50);
- cleanVector(v);
- plane p1,p2,p3;
- for(k = 1; k < 4; k++) // repeating until all three planes are placed
- {
- slidingShowVector(v);
- cout << endl << endl << " Introdu varful avionului " << k << ":" << endl << endl;
- cout << " ";
- cin >> xc;
- x = xc[0] - 96;
- y = xc[1] - 48;
- if((y == 1) and (xc[2] - 48 == 0))
- y = 10;
- //check if valid input
- if((x < 1) or (x > 10) or (y < 1) or (y > 10) or ((strlen(xc) > 2) and (y != 10)))
- {
- system("cls");
- cout << endl << endl << " Coordonate invalide. Incearca din nou." << endl << endl;
- sleep(1500);
- k = k-1;
- continue;
- }
- cout << endl << " Cum doresti sa asezi avionul?" << endl << endl;
- dir = 0;
- while((dir < 1) or (dir > 4)) //check if valid input
- {
- askDirection();
- cout << " ";
- cin >> dirv;
- dir = dirv[0] - 48;
- if((dir < 1) or (dir > 4))
- cout << " Optiune invalida. Incearca din nou." << endl;
- }
- //storing planes in structs
- if(k == 1)
- {
- p1.x = x;
- p1.y = y;
- p1.dir = dir;
- }
- else if(k == 2)
- {
- p2.x = x;
- p2.y = y;
- p2.dir = dir;
- }
- else if(k == 3)
- {
- p3.x = x;
- p3.y = y;
- p3.dir = dir;
- }
- //depending at what step, which planes' coordinates to use
- if(k == 1)
- {
- addPlane(p1.dir, p1.x, p1.y, v);
- }
- else if(k == 2)
- {
- addPlane(p2.dir, p2.x, p2.y, v);
- }
- else if(k == 3)
- {
- addPlane(p3.dir, p3.x, p3.y, v);
- }
- if(!isTheVectorAlright(k,v))
- {
- system("cls");
- cout << endl << " Avioanele se intersecteaza sau exced marimea vectorului. Incearca din nou." << endl << endl << endl << endl;
- sleep(1500);
- cleanVector(v);
- if(k == 2)
- addPlane(p1.dir, p1.x, p1.y, v);
- if(k == 3)
- {
- addPlane(p1.dir, p1.x, p1.y, v);
- addPlane(p2.dir, p2.x, p2.y, v);
- }
- k = k - 1;
- continue;
- }
- system("cls");
- cout << endl << endl << endl << " Avion adaugat cu succes." << endl << endl;
- if(k == 3)
- {
- showVector(v);
- cout << endl << endl << endl << " Buna treaba " << player1 << ", ai plasat toate cele 3 avioane." << endl << endl;
- }
- }
- cout << " Scrie 'c' cand esti gata sa-l lasi pe " << player2 << " sa joace." << endl;
- // player 2 starts here
- rdy = 'd';
- cout << " ";
- while(rdy != 'c')
- {
- cin >> rdy;
- }
- system("cls");
- cout << endl << " " << player2 << ", cand esti gata, scrie 't' pentru a incepe sa ghicesti!" << endl << endl;
- cleanVector(g);
- t = 'bolovan';
- cout << " ";
- while(t != 't')
- {
- cin >> t;
- }
- system("cls");
- cout << endl << " Bafta " << player2 << "!" << endl << endl;
- heads = 0;
- start = clock();
- while(heads < 3)
- {
- showVector(g);
- cout << " ";
- cin >> xc;
- x = xc[0] - 96;
- y = xc[1] - 48;
- if((y == 1) and (xc[2] - 48 == 0))
- y = 10;
- if((x < 1) or (x > 10) or (y < 1) or (y > 10) or ((strlen(xc) > 2) and (y != 10)))
- {
- cout << endl << endl << " Coordonate invalide. Incearca din nou." << endl;
- sleep(2000);
- system("cls");
- cout << endl << endl << endl;
- continue;
- }
- if((g[x][y] == '*') or (g[x][y] == 'x') or (g[x][y] == 2))
- {
- system("cls");
- cout << endl << " Ai mai dat o data aici." << endl << endl;
- continue;
- }
- if(v[x][y] == 2)
- g[x][y] = 2;
- else
- g[x][y] = 'x';
- if(((x == p1.x) and (y == p1.y)) or ((x == p2.x) and (y == p2.y)) or ((x == p3.x) and (y == p3.y)))
- {
- system("cls");
- if(heads == 0)
- cout << endl << " Bravo! Ai lovit un varf!" << endl << endl;
- else if(heads == 1)
- cout << endl << " Bravo! Ai lovit inca un varf!" << endl << endl;
- g[x][y] = '*';
- heads++;
- }
- else
- {
- system("cls");
- cout << endl << endl << endl;
- }
- steps++;
- }
- system("cls");
- slidingShowVector(v);
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- stop = clock();
- timeInterval = stop - start;
- if(opt[0] == '1')
- cout << endl << " Felicitari " << player2 << "! Scorul tau: " << 104-steps << endl << endl;
- else
- {
- q = steps * 10 + (timeInterval/1000);
- eff = 115 - q/10;
- cout << endl << " Felicitari " << player2 << "! Ai distrus toate 3 avioanele!" << endl;
- cout << " Scorul tau: " << eff << endl;
- cout << endl;
- }
- for(i = 1; i <= 80; i++)
- {
- cout << '-'; sleep(6);
- }
- sleep(2000);
- cout << " 1. Joaca din nou "<< endl; sleep(50);
- cout << " 2. Schimba rolurile & joaca din nou"<< endl; sleep(50);
- cout << " 3. Meniul principal "<< endl; sleep(50);
- cout << " 4. Iesire "<< endl; sleep(50);
- int opt3 = 0;
- cin >> opt3;
- if(opt3 == 1)
- {
- steps = 0;
- goto playAgain1;
- }
- if(opt3 == 2)
- {
- steps = 0;
- opt[0] = '2';
- something = 3;
- goto SwitchAgain1;
- }
- if(opt3 == 3)
- goto Menu1;
- if(opt3 == 4)
- exit(0);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement