Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Player {
- constructor(){
- this.warrior;
- this.maxHP = 20;
- this.oldHP = null;
- }
- isTakingDmg(warrior) {
- if(warrior.health() < this.oldHP){
- return true;
- }
- return false;
- }
- isSafe(warrior){
- if(this.isTakingDmg(warrior)){
- return false;
- }
- return true;
- }
- isInjured(warrior) {
- if(warrior.health() < this.maxHP) {
- return true;
- }
- return false;
- }
- isCaptive(warrior){
- if(warrior.feel().getUnit().isBound()){
- return true;
- }
- return false;
- }
- isDmgFromAfar(warrior){
- if(this.isTakingDmg(warrior)){
- return true;
- }
- return false;
- }
- playTurn(warrior) {
- // Cool code goes here.
- let action = 'move';
- if(this.isSafe(warrior) && this.isInjured(warrior)){
- action = 'rest'
- }
- // else if(warrior.feel().isEmpty() && this.isTakingDmg(warrior)){
- // action = 'move'
- // }
- else if(!this.isSafe(warrior)){
- action = 'seekEnemy'
- }
- else if (!this.isSafe(warrior) && warrior.health() < this.maxHP / 2) {
- action = 'run'
- }
- else if(warrior.feel().getUnit()){
- action = 'fight'
- }
- switch(action){
- case 'move':
- warrior.walk()
- break;
- case 'fight':
- warrior.attack()
- break;
- case 'rest':
- warrior.rest()
- break;
- case 'run':
- warrior.walk('backward')
- break;
- case 'seekEnemy':
- //TODO
- if(warrior.feel().isEmpty() && warrior.health() < 15){
- warrior.walk()
- }else{
- warrior.attack()
- }
- break;
- case 'rescue':
- warrior.rescue()
- break;
- default:
- break;
- }
- this.oldHP = warrior.health()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement