-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hunt.java
131 lines (114 loc) · 4.1 KB
/
Hunt.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
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Hunt extends JFrame {
public Hunt(Novice novice, Monster monster) {
super("Hunt");
setSize(400, 340);
GridBagLayout gridBag = new GridBagLayout();
setLayout(gridBag);
GridBagConstraints gbc = new GridBagConstraints();
Insets ins = new Insets(5, 5, 5, 5);
int anc = GridBagConstraints.WEST;
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 0;
gbc.gridy = 1;
add(new JLabel("Your Name: " + novice.getName()), gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 1;
gbc.gridy = 1;
JButton attackButton = new JButton("Attack");
add(attackButton, gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 1;
gbc.gridy = 2;
JButton runButton = new JButton("Run");
add(runButton, gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 1;
add(new JLabel("Monster: " + monster.getName()), gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 0;
gbc.gridy = 2;
JLabel noviceHp = new JLabel("HP: " + novice.getHp() + "/" + novice.getMaxHp());
add(noviceHp, gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 2;
JLabel monsterHp = new JLabel("HP: " + monster.getHp() + "/" + monster.getMaxHp());
add(monsterHp, gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 0;
gbc.gridy = 3;
add(new JLabel("Atk: " + novice.getAttackPower()), gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 3;
add(new JLabel("Atk: " + monster.getAttackPower()), gbc);
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 0;
gbc.gridy = 0;
add(new JLabel(new ImageIcon("novice.png")), gbc);
if (monster.getName() == "Goblin"){
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 0;
add(new JLabel(new ImageIcon("Goblin.png")), gbc);
}
else if (monster.getName() == "Slime"){
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 0;
add(new JLabel(new ImageIcon("Slime.png")), gbc);
}
else if (monster.getName() == "Org"){
gbc.anchor = anc;
gbc.insets = ins;
gbc.gridx = 2;
gbc.gridy = 0;
add(new JLabel(new ImageIcon("Org.png")), gbc);
}
runButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
new Home(novice);
dispose();
}
});
attackButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
novice.takeDamage(monster.getAttackPower());
monster.takeDamage(novice.getAttackPower());
noviceHp.setText("HP: " + novice.getHp() + "/" + novice.getMaxHp());
monsterHp.setText("HP: " + monster.getHp() + "/" + monster.getMaxHp());
if (novice.getHp() <= 0) {
novice.reborn();
new Home(novice);
dispose();
}
else if (monster.getHp() <= 0) {
novice.takeMoney(monster.getExp());
novice.expGain(monster.getExp());
novice.stackKill();
novice.levelUp(novice.getExp(), novice.getLevel());
new Home(novice);
dispose();
}
}
});
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setVisible(true);
}
}