Написах една малка игричка на C++. Вероятно се досещате каква е идеята от заглавието.
#include <cstdlib> #include <iostream> #include <math.h> using namespace std; const float pi=3.14159; //nabor ot konstanti nujni za igrata const float g=9.8; const int broi_izstreli=15; const int V=120; const int min_rng=40; //min_rng i max_rng opredelqt interwala na sluchainoto chislo const int max_rng=1300; int traektoria(float ugul){ //funkciq izchislqwashta traektoriqta na snarqda float rng,Vy,Vx; Vx=V*cos(ugul*(pi/180)); Vy=V*sin(ugul*(pi/180)); rng=(2*Vx*Vy)/g; return (int) rng; } int protivnik () { // funkciq generirashta proizwolno chislo za mishenata w daden iterwal int protivnik=rand() %max_rng + min_rng ; return protivnik; } int main(int argc, char *argv[]) { int rng,wrag,snarqdi=broi_izstreli; char otgowor; float ugul; srand(time(NULL)); //srand(time(NULL)) garantira che wsqko startirane na programata shte e s proizwolni chisla. wrag=protivnik(); //Chislata generirani ot rand() moje da izglejdat sluchaini no se poluchawat chrez algoritum t.e. cout<<"Mishenata e na "<<wrag<<" metra\n"; //sledwat shema, chiqto osnowa e chislo. To shte e edno i sushto wseki put ako srand() ne go promenq do { cout<<"Wuwedi ugul na strelba: "; cin>>ugul; if ((ugul>0)&&(ugul<=180)) { rng=traektoria(ugul); snarqdi-=1; if (abs(rng-wrag)<=5) // prowerka za popadenie { cout<<"Wie ucelihte protivnika ot "; //obrabotka na suob6teniqta switch (abs(snarqdi)-15) { case 1:cout<<(abs(snarqdi-15))<<"-wi opit.";break; case 2:cout<<(abs(snarqdi-15))<<"-ri opit.";break; case 3:cout<<(abs(snarqdi-15))<<"-ti opit.";break; default: cout<<(abs(snarqdi-15))<<"-ti opit."; } snarqdi=broi_izstreli; wrag=protivnik(); //suzdawa se nowa mishena cout<<endl<<"<><><><><><><><><><><><><><><><><><><><>\n"; cout<<"Nowata mishena e na "<<wrag<<" metra. Iskate li da produljite (Y/N)?\n"; cin>>otgowor; while ((otgowor!='n')&&(otgowor!='N')&&(otgowor!='Y')&&(otgowor!='y')) { cout<<"Iskate li da produljite (Y/N)?"; cin >>otgowor; cout<<endl; } if ((otgowor=='n')||(otgowor=='N')) { cout<<"Dovijdane!\n"; break; } } else if ((rng-wrag)>0) cout<<"Snarqda padna "<<rng-wrag<<" metra sled protiwnika.\n"<<"Opitaite otnowo, ostawat wi "<<snarqdi<<" opita.\n"; else cout<<"Snarqda padna "<<abs(rng-wrag)<<" metra predi protiwnika.\n"<<"Opitaite otnowo, ostawat wi "<<snarqdi<<" opita.\n"; } else cout <<"Newaliden ugul!\n"; } while (snarqdi!=0); if (snarqdi==0) cout <<"Swurshiha wi municiite!\n"; system("PAUSE"); return EXIT_SUCCESS; }
Мен ми дава грешка на 33-и ред – ‘time’ was not declared in this scope
Ехеее, игра :-) Браво, ползвал си и функции в нея (удачно), и константи в началото, и коментари има, и случайни числа – съвсем истинска е станала! Супер!