-
Notifications
You must be signed in to change notification settings - Fork 0
/
level.dart
140 lines (105 loc) · 2.64 KB
/
level.dart
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
import 'dart:math' as math;
void main() {
// Level lvl_one = new Level(1);
// print(lvl_one);
// Level lvl_two = new Level(2);
// print(lvl_two);
// Level lvl_three = new Level(3);
// print(lvl_three);
// print('-------------');
// Experience playerXP = new Experience(0);
// print('Player created!');
// print('Player XP: ${playerXP}');
// print('Player is level: ${playerXP.getLevel()}\n');
// print('Player completes training!');
// print('+200xp');
// playerXP.addExperience(200);
// print('Player XP: ${playerXP}');
// print('Player is level: ${playerXP.getLevel()}\n');
// print('Player completes training!');
// print('+1200xp');
// playerXP.addExperience(1200);
// print('Player XP: ${playerXP}');
// print('Player is level: ${playerXP.getLevel()}\n');
User alec = new User(
2200, 'Alec', 'Sibilia', '[email protected]', 'http://image.com');
// alec.addExperience(2200);
print(alec);
}
class User extends Player {
String firstName;
String lastName;
String email;
String photoUrl;
User(xp, this.firstName, this.lastName, this.email, this.photoUrl)
: super(xp);
@override
toString() {
return 'Name: $firstName $lastName\nEmail: $email\nPhoto URL: $photoUrl\nLevel: $level\nExperience: $xp';
}
}
class Player extends Experience {
int level;
Player(xp) : super(xp) {
this.level = super.getLevel();
}
}
class Experience {
int xp;
@override
toString() {
return '$xp xp';
}
Experience(int xp) {
this.xp = xp;
}
addExperience(int value) {
this.xp += xp;
}
removeExperience(int value) {
this.xp -= xp;
}
getLevel() {
int userLevel = 1;
int maxLevel = 100;
while (userLevel <= maxLevel) {
var isInLevel = new Level(userLevel).isInLevel(this.xp);
if (isInLevel) {
return userLevel;
}
userLevel++;
}
}
}
class Level {
double exponent = 1.5;
int baseXP = 1000;
int currentLevel;
int minXp;
int maxXp;
@override
toString() {
return 'Level: $currentLevel \nRange: $minXp -- $maxXp xp \n';
}
Level(int currentLevel) {
this.currentLevel = currentLevel;
this.minXp = this.setMinXp(currentLevel);
this.maxXp = this.setMaxXp(currentLevel);
}
setMinXp(int level) {
var newMaxXp =
this.baseXP * math.pow((level - 1).toDouble(), this.exponent);
return newMaxXp.floor();
}
setMaxXp(int level) {
var newMaxXp = this.baseXP * math.pow(level.toDouble(), this.exponent);
return newMaxXp.floor() - 1;
}
isInLevel(int xp) {
if ((xp >= this.minXp) && (xp <= this.maxXp)) {
return true;
} else {
return false;
}
}
}