Advertisement
cgorrillaha

ZombieWithFight

Dec 2nd, 2021
919
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.31 KB | None | 0 0
  1. package Zombie2021;
  2.  
  3. public class Apoc {
  4.     private int numZombies;
  5.     private int daysLeft;
  6.     private Person p;
  7.  
  8.     public Apoc(int days, Person p){
  9.         this.p=p;
  10.         daysLeft=days;
  11.     }
  12.  
  13.     public void runSimulation(){
  14.         //while( days and food and people are left){
  15.         // eat
  16.         // fight
  17.         // }
  18.         //resolve victory conditions
  19.     }
  20.  
  21.     public void eatFood(){
  22.         //access person object and remove food
  23.     }
  24.  
  25.     public boolean fight(){
  26.         boolean peopleLeft=p.getPersonCount()>0;
  27.         //generate zombies
  28.         numZombies=Utilities.randomInRange(10,25);
  29.  
  30.         //if(ammo left){
  31.         // gunfight()
  32.         // }
  33.         //else{
  34.         // bluntfight()
  35.         // }
  36.  
  37.         peopleLeft=p.getPersonCount()>0;
  38.         return peopleLeft;
  39.     }
  40.  
  41.     public boolean gunFight(int numZed){
  42.         //fight until all zombies are dead
  43.         //person shoots
  44.         int zHits=0;
  45.         while(numZed>0&&p.getPersonCount()>0){
  46.             if(p.getAmmo()>0) {//shoot
  47.                 p.setAmmo(p.getAmmo()-1);//consume ammo
  48.                 if (Utilities.randomInRange(1,5)==2) {//hit
  49.                     zHits++;
  50.                     if(Utilities.randomInRange(1,3)==1||zHits==2){
  51.                         numZed--;
  52.                         zHits=0;
  53.                     }
  54.                 }else{//miss with gun
  55.                     if(Utilities.randomInRange(1,3)==1){
  56.                         p.killPerson();
  57.                     }
  58.                 }//end gun miss
  59.             }else{//no ammo do blunt fight
  60.                 return bluntFight(numZed);
  61.             }
  62.         }
  63.         return p.getPersonCount()>0;
  64.     }
  65.  
  66.     public boolean bluntFight(int numZed){
  67.         int zHits=0;
  68.         while(p.getPersonCount()>0&&numZed>0){//each iteration is a single hit
  69.             if(Utilities.randomInRange(1,3)==1){
  70.                 zHits++;
  71.                 if(Utilities.randomInRange(1,10)==1 || zHits==3){
  72.                     numZed--;
  73.                     zHits=0;
  74.                 }
  75.             }else{//miss
  76.                 if(Utilities.randomInRange(1,2)==1){
  77.                     p.killPerson();
  78.                 }//person dies
  79.             }//end miss
  80.         }//end fight loop
  81.         return p.getPersonCount()>0;
  82.     }//end blunt fight
  83.  
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement