// takes number of bullets and percentage of missing as input// i.e. 5 for 5% chance of missing// this functions guarantees that the given percentage of total bullets will miss zombiesvector<bool>hitOrMiss(intnumBullets,intpercentage){vector<bool>hits(numBullets,true);for(inti=0;i<numBullets*percentage/100;i++){hits[i]=false;}shuffle(hits.begin(),hits.end(),default_random_engine(time(0)));returnhits;}voidzombie_shootout(inttotalZombie,floatrange,intnumBullets){inttempTotalZombie=totalZombie;// holds the total number of zombiesinttempNumBullets=numBullets;// holds the total number of bulletsvector<bool>hits=hitOrMiss(numBullets,5);while(numBullets>0&&totalZombie>0&&range>0){if(hits[numBullets-1]){totalZombie--;}numBullets--;if(totalZombie==0)break;range-=0.5;}// If you shoot all the zombiesif(totalZombie==0&&range>0&&numBullets>=0){cout<<"You shot all "<<tempTotalZombie<<" zombies.\n";return;}// If you get eaten before killing all the zombies, and before running out of ammo// or If you run out of ammo at the same time as the remaining zombies reach youif(range==0&&totalZombie>0&&numBullets>=0){cout<<"You shot "<<tempTotalZombie-totalZombie<<" zombies before being eaten: overwhelmed.\n";return;}// If you run out of ammo before shooting all the zombies,if(numBullets==0&&totalZombie>0){cout<<"You shot "<<tempTotalZombie-totalZombie<<" zombies before being eaten: ran out of ammo.\n";return;}}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
C++