-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBattle.java
More file actions
62 lines (50 loc) · 1.5 KB
/
Battle.java
File metadata and controls
62 lines (50 loc) · 1.5 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import java.util.*;
public class Battle {
Scanner scan = new Scanner(System.in);
Random rand = new Random();
int intChoice;
public Battle() {}
/*
* Battle method which is a constructor
*/
public void Battle(Player player, Enemy enemy) {
System.out.println("Do you wish to fight the " + enemy.name);
System.out.println("\n1. Yes\n2. No");
intChoice = scan.next().charAt(0);
if(intChoice == '1') {
do {
System.out.println("Health: " + player.health);
System.out.println(enemy.name + " health: " + enemy.health);
System.out.println("Player Attack DEBUG: " + player.getAttack());//debug
System.out.println(enemy.name + " strikes!\n");
enemy.attack = rand.nextInt(1,20);
player.health = player.health - enemy.attack;
System.out.println("Your turn!\n1.Attack\n2.Equip");
intChoice = scan.next().charAt(0);
switch(intChoice) {
case '1':
enemy.health = enemy.health - player.getAttack();
System.out.println("You attacked!");
break;
case '2':
player.Equip(scan, player);
break;
default:
System.out.println("Invalid Option");
break;
}
if (enemy.health <= 0) {
enemy.isDead =true;
System.out.println("You defeated " + enemy.name);
}
if (player.health <=0) {
player.isDead = true;
System.out.println("You have died!");
System.exit(0);
}
}while(enemy.isDead != true );
}else if(intChoice == '2') {
System.out.println("You ran away safely!");
}
}
}