aykuta3474 / depoo

0 stars 0 forks source link

Fighter #35

Open aykuta3474 opened 2 years ago

aykuta3474 commented 2 years ago

public class Fighter { String name; int damage; int health; int weight; double dodge; double starValue;

public Fighter(String name, int damage, int health, int weight, double dodge,double starValue) {
    this.name = name;
    this.damage = damage;
    this.health = health;
    this.weight = weight;
    this.dodge = dodge;
    this.starValue=starValue;
}

public int hit(Fighter foe) {
    System.out.println("------------");
    System.out.println(this.name + " => " + foe.name + " " +  this.damage + " hasar vurdu.");

    if (foe.dodge()) {
        System.out.println(foe.name + " gelen hasarı savurdu.");
        return foe.health;
    }

    if (foe.health - this.damage < 0)
        return 0;

    return foe.health - this.damage;
}

public boolean dodge() {
    double randomValue = Math.random() * 100;  //0.0 to 99.9
    return randomValue <= this.dodge;
}

public  boolean isStart(){
    double randomStartValue=Math.random()*100;
    return randomStartValue<=starValue;

}

}

aykuta3474 commented 2 years ago

public class Main { public static void main(String[] args) { Fighter f1=new Fighter("A", 10,100,100, 100,50); Fighter f2=new Fighter("B", 20,85,85, 0,50);

    Match match=new Match(f1,f2,50,120);
    match.run();

}

}

aykuta3474 commented 2 years ago

public class Match { Fighter f1; Fighter f2; int minWeight; int maxWeight;

public Match(Fighter f1, Fighter f2, int minWeight, int maxWeight) {
    this.f1 = f1;
    this.f2 = f2;
    this.minWeight = minWeight;
    this.maxWeight = maxWeight;
}

public void run(){
    if (isCheck()) {
        while  (this.f1.health>0 && this.f2.health>0){
            if (this.f1.isStart() && this.f2.isStart()){
                System.out.println("=====>>> ROUND <<<====");
                if (this.f1.isStart()){
                    f2.health=f1.hit(f2);
                    if (isWin()){
                        break;
                    }
                }else{
                    f1.health=f2.hit(f1);
                    if (isWin()){
                        break;
                    }
                }
                System.out.printf("Canlar\nSavasci : %s  | Can : %d\nSavasci : %s  | Can : %d\n",f1.name  ,f1.health,f2.name,f2.health);
            }

        }

    }else {
        System.out.println("Sporcular maça giremez...");
    }
}

public boolean isCheck(){
    return (this.f1.weight>=minWeight && this.f1.weight<=maxWeight) && (this.f2.weight>=minWeight && this.f2.weight<=maxWeight);
}

public boolean isWin(){
    if(this.f1.health==0){
        System.out.println(f2.name + " kazandı.");
        return true;
    }else if(this.f2.health==0){
        System.out.println(f1.name + " kazandı.");
        return true;
    }
    return false;
}

}