daily pastebin goal
41%
SHARE
TWEET

Untitled

a guest Jun 13th, 2018 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Player {
  2.   constructor(){
  3.     this.warrior;
  4.     this.maxHP = 20;
  5.     this.oldHP = null;
  6.   }
  7.  
  8.   isTakingDmg(warrior) {
  9.     if(warrior.health() < this.oldHP){
  10.       return true;
  11.     }
  12.     return false;
  13.   }
  14.  
  15.   isSafe(warrior){
  16.     if(this.isTakingDmg(warrior)){
  17.       return false;
  18.     }
  19.     return true;
  20.   }
  21.  
  22.   isInjured(warrior) {
  23.     if(warrior.health() < this.maxHP) {
  24.       return true;
  25.     }
  26.     return false;
  27.   }
  28.  
  29.   isCaptive(warrior){
  30.     if(warrior.feel().getUnit().isBound()){
  31.       return true;
  32.     }
  33.     return false;
  34.   }
  35.  
  36.   isDmgFromAfar(warrior){
  37.  
  38.     if(this.isTakingDmg(warrior)){
  39.       return true;
  40.     }
  41.     return false;
  42.   }
  43.  
  44.   playTurn(warrior) {
  45.     // Cool code goes here.
  46.  
  47.     let action = 'move';
  48.  
  49.     if(this.isSafe(warrior) && this.isInjured(warrior)){
  50.       action = 'rest'
  51.     }
  52.     // else if(warrior.feel().isEmpty() && this.isTakingDmg(warrior)){
  53.     //   action = 'move'
  54.     // }
  55.     else if(!this.isSafe(warrior)){
  56.       action = 'seekEnemy'
  57.     }
  58.     else if (!this.isSafe(warrior) && warrior.health() < this.maxHP / 2) {
  59.       action = 'run'
  60.     }
  61.     else if(warrior.feel().getUnit()){
  62.       action = 'fight'
  63.     }
  64.    
  65.     switch(action){
  66.       case 'move':
  67.         warrior.walk()
  68.         break;
  69.       case 'fight':
  70.         warrior.attack()
  71.         break;
  72.       case 'rest':
  73.         warrior.rest()
  74.         break;
  75.       case 'run':
  76.         warrior.walk('backward')
  77.         break;
  78.       case 'seekEnemy':
  79.         //TODO
  80.         if(warrior.feel().isEmpty() && warrior.health() < 15){
  81.           warrior.walk()
  82.         }else{
  83.           warrior.attack()
  84.         }
  85.         break;
  86.       case 'rescue':
  87.         warrior.rescue()
  88.         break;
  89.       default:
  90.         break;
  91.     }
  92.  
  93.     this.oldHP = warrior.health()
  94.   }
  95. }
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