-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathMain.java
More file actions
79 lines (66 loc) · 2.57 KB
/
Main.java
File metadata and controls
79 lines (66 loc) · 2.57 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
import org.project.entity.Entity;
import org.project.entity.players.Assassin;
import org.project.entity.players.Knight;
import org.project.entity.players.Wizard;
import org.project.entity.enemies.Dragon;
import org.project.entity.enemies.Goblin;
import org.project.entity.enemies.Skeleton;
import org.project.object.weapons;
import org.project.object.weapons.Sward;
import org.project.object.armors;
import org.project.object.armors.KnightArmor;
import java.util.Scanner;
public class JavaRingGame {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Select your character: ");
System.out.println("1. Wizard");
System.out.println("2. Knight");
System.out.println("3. Assassin");
int choice = scanner.nextInt();
Entity player = null;
switch (choice) {
case 1:
player = new Wizard(100, 50, new Sword(30, 10));
break;
case 2:
player = new Knight(120, 30, new Sword(40, 15));
break;
case 3:
player = new Assassin(80, 70, new Sword(25, 5));
break;
default:
System.out.println("Invalid choice, defaulting to Wizard.");
player = new Wizard(100, 50, new Sword(30, 10));
}
Entity enemy = generateRandomEnemy();
System.out.println("\nYour enemy: " + enemy.getClass().getSimpleName());
System.out.println("Battle Start!");
while (player.isAlive() && enemy.isAlive()) {
System.out.println("\nYour turn to attack!");
player.attack(enemy);
if (enemy.isAlive()) {
System.out.println("\nEnemy's turn to attack!");
enemy.attack(player);
}
}
if (!player.isAlive()) {
System.out.println("You have been defeated by " + enemy.getClass().getSimpleName() + "!");
} else if (!enemy.isAlive()) {
System.out.println("You have defeated " + enemy.getClass().getSimpleName() + "!");
}
}
public static Entity generateRandomEnemy() {
int rand = (int) (Math.random() * 3);
switch (rand) {
case 0:
return new Goblin(50, 20, new Sword(15, 5));
case 1:
return new Skeleton(70, 25, new Sword(20, 8));
case 2:
return new Dragon(200, 50, new Sword(50, 20));
default:
return new Goblin(50, 20, new Sword(15, 5)); // Default enemy
}
}
}