-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpell.java~
45 lines (40 loc) · 1.38 KB
/
Spell.java~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.util.Random;
public class Spell{
//attributes
private String name;
private double minDmg;
private double maxDmg;
private double chanceSuccess;
//constructor
public Spell(String name, double minDmg, double maxDmg, double chanceSuccess){
//if the chance of success isnt between 0 and 1 or the min damage is smaller
//than 0 or the minimum damage is bigger than the max damage, it breaks and throw an Illegalargumentexception
if(this.chanceSuccess<0||this.chanceSuccess>1
||this.minDmg<0||this.minDmg>this.maxDmg){
throw new IllegalArgumentException();
}
this.name=name;
this.minDmg=minDmg;
this.maxDmg=maxDmg;
this.chanceSuccess=chanceSuccess;
}
public String getName(){
return this.name;
}
public double getMagicDamage(int seed){
Random randomGenerator=new Random(seed);
//if the randomgenerator is larger than the success chance, the magic damage isn't returned
//this makes a success chance of 100%(10) always run
if(randomGenerator.nextDouble()>this.chanceSuccess){
return 0;
}else{
return randomGenerator.nextDouble()*(this.maxDmg-this.minDmg)+this.minDmg;
}
}
//returns the string with the information
public String toString(){
String s="Name: "+this.name+" Damage: "+this.minDmg+"-"+this.maxDmg+" Chance: "+
this.chanceSuccess*100+"%";
return s;
}
}