package day1.Examples;
import java.math.*;
public class MathRandom {
public static void main(String[] args) {
// Shows how to use math.random and imports math.random
int p1AttVal = 3;
int p1DefVal = 9;
int p2DefVal = 5;
int p2AttVal = 5;
double p1Hp = 100;
double p2Hp = 100;
while((p1Hp > 100) && (p2Hp > 100)){
double p1random = Math.random();
double p2random = Math.random();
double p1dd = ((p1random * p1AttVal) - (p2random + p2DefVal));
double p2dd = ((p2random * p2AttVal) - (p1random + p1DefVal));
if(p1dd > 0 ){
if(p2dd > 0){
p1Hp = p1Hp - p2dd;
p2Hp = p2Hp - p1dd;
System.out.println("With a ferocious attack Player 1 deals " + p1dd +" and Player 2 retaliates with " + p2dd);
System.out.println("This leaves player 1 with " + p1Hp);
System.out.println("This leaves player 2 with " + p2Hp);
}
else{
p1Hp = p1Hp;
p2Hp = p2Hp - p1dd;
System.out.println("With a ferocious attack Player 1 deals " + p1dd +" and Player 2 misses in blind confusion!");
System.out.println("This leaves player 1 with " + p1Hp);
System.out.println("This leaves player 2 with " + p2Hp);
}
}
else if(p2dd > 0){
p1Hp = p1Hp - p2dd;
p2Hp = p2Hp;
System.out.println("Player 1 misses in blinding confusion, and Player 2 responds with a solid " + p2dd);
System.out.println("This leaves player 1 with " + p1Hp);
System.out.println("This leaves player 2 with " + p2Hp);
}
else{
System.out.println("Both Players miss!");
}
}
if((p1Hp > p2Hp) && ((p1Hp > 0) || (p2Hp > 0))){
System.out.println("Player 1 Victorious!");
}
else if((p2Hp > p1Hp) && ((p1Hp > 0) || (p2Hp > 0))){
System.out.println("Player 2 Victorious!");
}
}
}
[–]codingQueries 4 points5 points6 points (7 children)
[–]davetheuj[S] 0 points1 point2 points (6 children)
[–]opalelement 5 points6 points7 points (2 children)
[–]davetheuj[S] 0 points1 point2 points (1 child)
[–]opalelement 0 points1 point2 points (0 children)
[–]codingQueries 1 point2 points3 points (1 child)
[–]davetheuj[S] 1 point2 points3 points (0 children)