Skip to content

Commit 5991273

Browse files
author
“Tezz03”
committed
feat:create java file and test file
1 parent 957c931 commit 5991273

File tree

1 file changed

+96
-0
lines changed
  • lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/playerleveling

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
package com.codedifferently.lesson16.playerleveling;
2+
3+
4+
public class Player {
5+
private String name;
6+
private Type type;
7+
private int level;
8+
private double currentExperience;
9+
private int expPerFight;
10+
private boolean isAlive;
11+
12+
public enum Type {
13+
HUMAN,
14+
ELF,
15+
ORC,
16+
DRAGONIOD
17+
}
18+
19+
public Player ( String name, Type type, int level, double currentExperience, int expPerFight, boolean isAlive) {
20+
this.name = name;
21+
this.type = type;
22+
this.level = level;
23+
this.currentExperience = currentExperience;
24+
this.expPerFight = expPerFight;
25+
this.isAlive = isAlive;
26+
}
27+
28+
// Getters and Setters
29+
30+
public String getName() {
31+
return name;
32+
}
33+
34+
public void setName(String name) {
35+
this.name = name;
36+
}
37+
38+
public Type getType() {
39+
return type;
40+
}
41+
42+
public void setType(Type characterType) {
43+
this.type = characterType;
44+
}
45+
public int getLevel() {
46+
return level;
47+
}
48+
49+
public void setLevel(int level) {
50+
this.level = level;
51+
}
52+
53+
public double getCurrentExperience() {
54+
return currentExperience;
55+
}
56+
57+
public void setCurrentExperiience (double currentExperience) {
58+
this.currentExperience = currentExperience;
59+
}
60+
61+
public int getExpPerFight() {
62+
return expPerFight;
63+
}
64+
65+
public void setExpPerFight ( int expPerFight) {
66+
this.expPerFight = expPerFight;
67+
68+
}
69+
70+
public boolean getIsAlive() {
71+
return isAlive;
72+
}
73+
74+
75+
public void gainExperience(int fights) {
76+
for (int i = 0; i < fights; i++) {
77+
currentExperience += expPerFight;
78+
79+
double requiredExp = 100 * Math.pow(2, level - 1); // Level 1: 100 XP, Level 2: 200 XP, etc.
80+
81+
while (currentExperience >= requiredExp) {
82+
currentExperience -= requiredExp; // carry over any extra XP
83+
level++;
84+
System.out.println(name + " leveled up to level " + level + "!");
85+
requiredExp = 100 * Math.pow(2, level - 1); // Update the required XP for the new level
86+
}
87+
}
88+
// used ai for lines between 85 and 97
89+
}
90+
}
91+
92+
93+
94+
95+
96+
//int level = 1; int experience = 0; for(int i = 1; i <= 100; i++) {

0 commit comments

Comments
 (0)