This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBattle.java
131 lines (131 loc) · 4.87 KB
/
Battle.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Write a description of class battle here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class Battle{
public static boolean battle(character c, enemy e){
Scanner s = new Scanner(System.in);
int turn = 1;
int damage;
boolean guard = false;
while(c.tempHp > 0 && e.tempHp > 0){
guard = false;
boolean correct = false;
while(correct == false){
damage = 0;
System.out.println("Turn " + turn);
System.out.println("current hp:" + c.tempHp);
System.out.println("current sp:" + c.tempSp);
System.out.println("Please input a command");
String input = s.nextLine().toLowerCase();
if (input.equals("attack")){
damage = c.attack();
System.out.println(c.getName() + " has dealt " + damage + " damage.");
e.takeDamage(damage);
correct = true;
}
else if (input.equals("slash")){
damage = c.slash();
e.takeDamage(damage);
correct = true;
}
else if (input.equals("first aid") && c.firstAid == true){
c.firstAid();
correct = true;
}
else if (input.equals("plasma gun") && c.plasmaGun == true){
damage = c.plasmaGun();
e.takeDamage(damage);
correct = true;
}
else if (input.equals("sonar gun") && c.sonarGun == true){
damage = c.sonarGun();
e.takeDamage(damage);
correct = true;
}
else if (input.equals("flamethrower") && c.flamethrower == true){
if (Game.story.size()<=8)
{
damage = c.flamethrower();
e.takeDamage(damage);
correct = true;
}
else
{
System.out.println("Without the engine on, the flames fly out of control and back towards you.");
c.takeDamage(c.flamethrower());
correct = true;
}
}
else if (input.equals("plasma grenade") && c.plasmaGrenade == true){
damage = c.plasmaGrenade();
e.takeDamage(damage);
correct = true;
}
else if (input.equals("help")){
System.out.println("available commands:");
System.out.println("Attack");
System.out.println("Guard");
ArrayList<String> list = new ArrayList<String>();
list = c.getSkills();
for( int x=0; x < list.size(); x++){
String skill = list.get(x);
System.out.println(skill);
}
System.out.println("Slash sp cost: 2");
if(c.firstAid == true){
System.out.println("First aid sp cost: 10");
}
if(c.plasmaGun == true){
System.out.println("Plasma gun sp cost: 5");
}
if(c.sonarGun == true){
System.out.println("Sonar gun sp cost: 8");
}
if(c.flamethrower == true){
System.out.println("Flamethrower sp cost: 12");
}
if(c.plasmaGrenade == true){
System.out.println("Plasma grenade sp cost: 20");
}
}
else if(input.equals("guard")){
guard = c.guard();
correct = true;
}
else{
System.out.println("please type a proper input");
}
}
if (e.tempHp > 0){
if(guard == true){
damage = e.attack()/2;
}
else{
damage = e.attack();
}
c.takeDamage(damage);
}
turn ++;
}
if(c.tempHp <= 0){
System.out.println("Game Over");
return false;
}
else if(e.tempHp <= 0){
System.out.println("You won!");
c.exp(e.getExp());
e.tempHp = e.getHp();
}
else{
System.out.println("An error has occured");
return false;
}
c.tempHp = c.getHp();
c.tempSp = c.getSp();
return true;
}
}