-
Notifications
You must be signed in to change notification settings - Fork 1
/
PlayerStats.java
228 lines (207 loc) · 6.74 KB
/
PlayerStats.java
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import java.util.ArrayList;
import java.io.File; // Import the File class
import java.io.FileNotFoundException; // Import this class to handle errors
import java.util.Scanner; // Import the Scanner class to read text files
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import javax.imageio.*;
import java.io.File;
import java.awt.event.*;
import java.io.IOException;
import javax.swing.*;
public class PlayerStats{
public int damage;
public int shield;
public int health;
public ArrayList<String> weapons;
public int combStage;
public int money;
public int count = 0;
BufferedImage BookImage, DeathImage, SkullImage;
public int bw, bh, dw, dh, sw, sh;
public PlayerStats(int newDmg, int newShld, int newHlth){
try{
File bookImg = new File("book.png");
BookImage = ImageIO.read(bookImg);
bw = BookImage.getWidth(null);
bh = BookImage.getHeight(null);
File deathImg = new File("deadtext.png");
DeathImage = ImageIO.read(deathImg);
dw = DeathImage.getWidth(null);
dh = DeathImage.getHeight(null);
File skullImg = new File("skull.png");
SkullImage = ImageIO.read(skullImg);
sw = SkullImage.getWidth(null);
sh = SkullImage.getHeight(null);
}
catch(IOException e){
System.exit(1);
}
damage = newDmg;
shield = newShld;
health = newHlth;
weapons = new ArrayList<String>();
weapons.add("Fist");
combStage = 1;
money = 0;
}
public void addDamage(int incDmg){
damage += incDmg;
}
public void setDamage(int newDmg){
damage = newDmg;
}
public void addShield(int incShield){
shield += incShield;
}
public void drawInfoBook(Graphics g){
g.drawImage(BookImage, 15, 100, 15+bw, 50+bh+250, 0, 0, bw, bh, null);
g.drawString("Keybinds", 175, 200);
g.drawString("WASD - Move around", 85, 230);
g.drawString("Space - Attack enemies in arena", 85, 260);
g.drawString("I - Open/Close info book", 85, 290);
g.drawString("E - Enter/Exit a room", 85, 320);
g.drawString("J - Exit tutorial room", 85, 350);
g.drawString("K - Save game stats", 85, 380);
g.drawString("B - Buy items in shop", 85, 410);
g.drawString("Destinations", 400, 200);
g.drawString("Main Map: ", 350, 220);
g.drawString("Go to different destinations", 370, 250);
g.drawString("through doors", 370, 260);
g.drawString("Tutorial: ", 350, 290);
g.drawString("Learn the basics of the game", 370, 320);
g.drawString("Farm: ", 350, 340);
g.drawString("Earn money while harvesting", 370, 370);
g.drawString("crops", 370, 380);
g.drawString("Arena: ", 350, 410);
g.drawString("Battle strong mobs for", 370, 440);
g.drawString("lots of money", 370, 450);
g.drawString("Shop: ", 350, 480);
g.drawString("Buy powerful weapons", 370, 510);
g.drawString("and armor", 370, 520);
g.drawString("Boss Room: ", 350, 550);
g.drawString("Fight The Eck", 370, 580);
}
public void loadStats(){
int count = 0;
try {
File myObj = new File("stats.txt");
Scanner myReader = new Scanner(myObj);
while (myReader.hasNextLine()) {
String data = myReader.nextLine();
if(count == 0){
shield = Integer.parseInt(data);
}
else if(count == 1){
damage = Integer.parseInt(data);
}
else if(count == 2){
money = Integer.parseInt(data);
}
else if(count == 3){
combStage = Integer.parseInt(data);
}
else if(count >= 4){
weapons.add(data);
}
count += 1;
}
myReader.close();
} catch (FileNotFoundException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public void saveStats(){
try {
FileWriter myWriter = new FileWriter("stats.txt");
myWriter.write(Integer.toString(shield));
myWriter.write(System.getProperty( "line.separator" ));
myWriter.write(Integer.toString(damage));
myWriter.write(System.getProperty( "line.separator" ));
myWriter.write(Integer.toString(money));
myWriter.write(System.getProperty( "line.separator" ));
myWriter.write(Integer.toString(combStage));
myWriter.write(System.getProperty( "line.separator" ));
for(int i = 0; i < weapons.size(); i++){
myWriter.write(weapons.get(i));
myWriter.write(System.getProperty( "line.separator" ));
}
myWriter.close();
System.out.println("Successfully wrote to the file.");
} catch (IOException e) {
System.out.println("An error occurred.");
e.printStackTrace();
}
}
public void drawDead(Graphics g){
g.setColor(Color.BLACK);
g.fillRect(0, 0, 700, 700);
g.drawImage(DeathImage, 150, 80, 550, 180, 0, 0, dw, dh, null);
g.setColor(Color.WHITE);
g.setFont(new Font("Purisa", Font.BOLD, 15));
g.drawString("Press 'R' to respawn", 300, 250);
g.drawImage(SkullImage, 100, 300, 150+sw, 300+sh, 0, 0, sw, sh, null);
}
public void setShield(int newShield){
shield = newShield;
}
public void addHealth(int incHealth){
shield += incHealth;
}
public String curWeapon(){
String a = "";
for(int i = 0; i < weapons.size(); i++){
if(weapons.get(i).equals("Sword")){
count = 1;
}
}
for(int i = 0; i < weapons.size(); i++){
if(weapons.get(i).equals("Spear")){
count = 2;
}
}
for(int i = 0; i < weapons.size(); i++){
if(weapons.get(i).equals("Hammer")){
count = 3;
}
}
if(count == 1){
a = "Sword";
}
else if(count == 2){
a = "Spear";
}
else if(count == 3){
a = "Hammer";
}
else{
a = "Fist";
}
return a;
}
public void setHealth(int newHealth){
health = newHealth;
}
public void addStage(){
combStage += 1;
}
public int getWeaponDamage(String weapon){
if(weapon.equals("Fist")){
return 2;
}
else if(weapon.equals("Sword")){
return 5;
}
else if(weapon.equals("Spear")){
return 10;
}
else if(weapon.equals("Hammer")){
return 20;
}
return 0;
}
}