SHARE
TWEET

martian.cpp

michalkowalczyk Apr 2nd, 2019 77 in 167 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<martian.h>
  2.  
  3. Martian::Martian(){
  4.  
  5.     MartianCount++;
  6.     std::cout<<"We have a new Martian, the number of all Martians is: " << MartianCount<<std::endl;
  7.  
  8.  
  9.  
  10.  
  11. }
  12.  
  13.  
  14. Martian::~Martian(){
  15.  
  16.     MartianCount--;
  17.     std::cout<<"One of Martians is destroyed, the number of all Martians is: "<<MartianCount<<std::endl;
  18.  
  19.  
  20.  
  21. }
  22.  
  23. int Martian::getMartianCount(){
  24.  
  25.     return MartianCount;
  26. }
  27.  
  28.  
  29. bool Martian:: Attack(Martian *_martian){
  30.  
  31.     bool result = false;
  32.  
  33.  
  34.         if( std::rand()%2 == 1 && std::rand()%2 == 1 && std::rand()%2 == 1 && std::rand()%2 == 1){ // four rand() to reduce the likelihood of death
  35.             std::cout<<"Martian is dead"<<std::endl;
  36.             result = true;
  37.             delete _martian;
  38.         }
  39.  
  40.     return result;
  41.  
  42.  
  43.  
  44.  
  45.  
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top