-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.java
More file actions
159 lines (130 loc) · 4.53 KB
/
Character.java
File metadata and controls
159 lines (130 loc) · 4.53 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// polymorphism
import java.util.Scanner;
class Character {
public static String playerName;
public static int playerLevel;
protected static int magic = 3;
protected static int attack = 3;
protected static int speed = 3;
protected static int health = 10;
String role = " ";
protected User user; // reference
protected GAP main;
public void setPlayerName(String playerName) {
this.playerName = playerName;
}
public String getPlayerName() {
return playerName;
}
public void setPlayerLevel(int playerLevel) {
this.playerLevel = playerLevel;
}
public int getPlayerLevel() {
return playerLevel;
}
public void setHealth(int health) {
this.health = health;
}
public int getHealth() {
return health;
}
public int getAttack() {
return attack;
}
public int getMagic() {
return magic;
}
interface Skill{
void chooseSkill();
}
public void setUp() {
Scanner scanner = new Scanner(System.in);
System.out.println("\nLet's set up your character!");
System.out.print("Enter player name: ");
playerName = scanner.nextLine();
setPlayerName(capitalizeFirstLetter(playerName));
int classChoice;
boolean validChoice = false;
do {
System.out.println("\nChoose your class:");
System.out.println("1. Mage\n2. Fighter\n3. Assassin\n4. Tank");
System.out.print("\nEnter -> ");
classChoice = scanner.nextInt();
switch (classChoice) {
case 1:
role = "mage";
magic += 5;
System.out.println("You have chosen the Mage class. Your magic increased by 5.");
validChoice = true;
break;
case 2:
role = "fighter";
attack += 5;
System.out.println("You have chosen the Fighter class. Your attack increased by 5.");
validChoice = true;
break;
case 3:
role = "assassin";
speed += 5;
System.out.println("You have chosen the Assassin class. Your speed increased by 5.");
validChoice = true;
break;
case 4:
role = "tank";
System.out.println("You have chosen the Tank class. Your health increased by 5");
health += 5;
validChoice = true;
break;
default:
System.out.println("Invalid choice. Please choose a valid class.");
break;
}
} while (!validChoice);
playerLevel = 0;
System.out.println("Your level is currently " + playerLevel);
}
private String capitalizeFirstLetter(String name) {
if (name != null && name.length() > 0) {
return name.substring(0, 1).toUpperCase() + name.substring(1);
} else {
return name;
}
}
public void checkStats() {
// user.updateStats();
System.out.println("\nPlayer Stats:");
System.out.println("Name: " + playerName);
System.out.println("Level: " + playerLevel);
System.out.println("Magic: " + magic);
System.out.println("Attack: " + attack);
System.out.println("Speed: " + speed);
System.out.println("Health: " + health);
System.out.println();
}
public void levelDown() {
if (playerLevel > 1) {
playerLevel--;
magic = Math.max(0, magic - 5);
attack = Math.max(0, attack - 5);
speed = Math.max(0, speed - 5);
health = Math.max(1, health - 5); // Ensure health is at least 1
// main.updateStats();
System.out.println("You lost a level! All stats decreased by 5.");
} else {
System.out.println("You are already at the lowest level.");
}
}
public void levelUp() {
playerLevel++;
magic += 5;
attack += 5;
speed += 5;
health += 5;
checkStats();
System.out.println("You leveled up! All stats increased by 5.");
if (playerLevel == 10) {
System.out.println("You have Reached Level 10! You have Finished The Game!");
System.exit(0); // End the game
}
}
}