-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
187 lines (175 loc) · 5.74 KB
/
Player.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
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
/**
* Player deals with selection of monsters by players.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Player {
// instance variables - replace the example below with your own
private int x;
Monster pal;
Monster enemy;
private JButton[] buttons;
private JLabel label;
private JPanel panel;
private java.util.ArrayList<Monster> mon;
/**
* Constructor for objects of class Player.
*/
public Player() {
x = 0;
mon = new java.util.ArrayList<Monster>();
buttons = new JButton[4];
buttons[0] = new JButton("Earth");
buttons[1] = new JButton("Fire");
buttons[2] = new JButton("Water");
buttons[3] = new JButton("Wind"); // instansiation
buttons[0].addActionListener(new AL1());
buttons[1].addActionListener(new AL2());
buttons[2].addActionListener(new AL3());
buttons[3].addActionListener(new AL4()); // adding listener inputs
label = new JLabel("Player " + (x + 1) + ": choose your monster");
panel = new JPanel(); // more instansiation
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
// changing layout format of JPanel(default FlowManager)
panel.add(label);
panel.add(buttons[0]);
panel.add(buttons[1]);
panel.add(buttons[2]);
panel.add(buttons[3]); // adds Jcomponents to JPanel
panel.setOpaque(true);
panel.setBackground(java.awt.Color.WHITE);
}
/**
* Gets the JPanel.
* @return: JPanel panel
*/
JPanel getPanel() {
return panel;
}
/**
* Changes the layout of the JPanel.
* @post: JPanel buttons removed and changes/sets labels and a button
*/
private void decide() {
panel.remove(buttons[0]);
panel.remove(buttons[1]);
panel.remove(buttons[2]);
panel.remove(buttons[3]); // removal
label.setText("Player 1 controls are arrows and Spacebars to shoot.");
panel.add(new JLabel("Player 2 controls are WASD and Q to shoot."));
// can't do this in one JLabel for some reason
JButton b = new JButton("Start");
b.addKeyListener(new Keys(mon.get(0), mon.get(1))); // for focus issues
panel.add(b); // adds button
buttons = null; // into the garbage it goes
Game.update(mon); // for managing and painting
}
/**
* This class implements the {@link ActionListener} for the
* {@link JButton} objects.
*/
class AL1 implements ActionListener {
/**
* Creates specified object for clicking on button.
* @param: ActionEvent b to provide input info (not used, just for implementation)
*/
public void actionPerformed(ActionEvent b) {
int y = 0; // dictates Y-Coordinates
switch (x) {
case 0:
y = 270;
break;
case 1:
y = 1;
break;
}
mon.add(new EarthMonster("Grounded", 143, y)); // each different
x++;
if (x == 2) {
decide();
} // two is the specified limit for this game
}
}
/**
* This class implements the {@link ActionListener} for the
* {@link JButton} objects.
*/
class AL2 implements ActionListener {
/**
* Creates specified object for clicking on button.
* @param: ActionEvent b to provide input info (not used, just for implementation)
*/
public void actionPerformed(ActionEvent b) {
int y = 0; // dictates Y-Coordinates
switch (x) {
case 0:
y = 270;
break;
case 1:
y = 1;
break;
}
mon.add(new FireMonster("Charaturtle", 143, y)); // each different
x++;
if (x == 2) {
decide();
} // two is the specified limit for this game
}
}
/**
* This class implements the {@link ActionListener} for the
* {@link JButton} objects.
*/
class AL3 implements ActionListener {
/**
* Creates specified object for clicking on button.
* @param: ActionEvent b to provide input info (not used, just for implementation)
*/
public void actionPerformed(ActionEvent b) {
int y = 0; // dictates Y-Coordinates
switch (x) {
case 0:
y = 270;
break;
case 1:
y = 1;
break;
}
mon.add(new WaterMonster("Waturtle", 143, y)); // each different
x++;
if (x == 2) {
decide();
} // two is the specified limit for this game
}
}
/**
* This class implements the {@link ActionListener} for the
* {@link JButton} objects.
*/
class AL4 implements ActionListener {
/**
* creates specified object for clicking on button
* @param: ActionEvent b to provide input info (not used, just for implementation)
*/
public void actionPerformed(ActionEvent b) {
int y = 0; // dictates Y-Coordinates
switch (x) {
case 0:
y = 270;
break;
case 1:
y = 1;
break;
}
mon.add(new WindMonster("Windmill", 143, y)); // each different
x++;
if (x == 2) {
decide();
} // two is the specified limit for this game
}
}
}