-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
106 lines (101 loc) · 3.06 KB
/
Main.java
File metadata and controls
106 lines (101 loc) · 3.06 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
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
import java.util.Scanner;
class enemy{
int health;
int damage;
String name;
boolean isAlive = true;
public enemy(){
}
public void takeDamage(int damageTaken){
health -= damageTaken;
System.out.println("You dealt " + damageTaken + " damage to " + this.name);
if(health > 0){
System.out.println(name + " health: " + health);
} else{
System.out.println("Deafeated " + name);
System.out.println("");
isAlive = false;
}
}
}
class fourthChorus extends enemy{
public fourthChorus(){
this.health = 150;
this.damage = 40;
this.name = "fourth Chorus";
}
}
class lace extends enemy{
public lace(){
this.health = 80;
this.damage = 30;
this.name = "Lace";
}
}
class SisterSplinter extends enemy{
public SisterSplinter(){
this.health = 200;
this.damage = 10;
this.name = "Sister Splinter";
}
}
class player{
int health;
int damage;
boolean isAlive;
public player(){
health = 100;
damage = 50;
isAlive = true;
}
public void takeDamage(int damageTaken, String attacker){
health -= damageTaken;
System.out.println(attacker + " attacked you and dealt " + damageTaken + " damage");
if(health>0){
System.out.println("Current health: " + health);
} else{
isAlive = false;
}
}
public void heal(){
health+=20;
System.out.println("You healed 30 health");
}
}
public class Main{
static void battle(player myPlayer, enemy myEnemy,Scanner myScanner ){
System.out.println(myEnemy.name + " is blocking your path");
System.out.println("Battle initiated");
while(myEnemy.isAlive == true && myPlayer.isAlive == true){
boolean correctInput = false;
while(correctInput == false){
System.out.println("Your turn(type 1 for attack and 2 for heal):");
int playerChoice = myScanner.nextInt();
if(playerChoice == 1){
myEnemy.takeDamage(myEnemy.damage);
correctInput = true;
} else if(playerChoice ==2){
myPlayer.heal();
correctInput = true;
} else{
System.out.println("incorrect input");
}
}
if(myEnemy.isAlive){
myPlayer.takeDamage(myEnemy.damage, myEnemy.name);
}
}
}
public static void main(String[] args){
Scanner myScanner = new Scanner(System.in);
fourthChorus myChorus = new fourthChorus();
lace myLace = new lace();
SisterSplinter mySplinter = new SisterSplinter();
player myPlayer = new player();
battle(myPlayer,myLace,myScanner);
myPlayer.health =100;
battle(myPlayer,myChorus,myScanner);
myPlayer.health =100;
battle(myPlayer,mySplinter,myScanner);
}
}