-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSpamZiel.java
166 lines (145 loc) · 4.52 KB
/
SpamZiel.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
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SpamZiel extends AbstractMiniGame {
// Anfang Attribute
private static String titel = "Spam Ziel";
private JTextArea taBeschreibung = new JTextArea("");
private JScrollPane taBeschreibungScrollPane = new JScrollPane(taBeschreibung);
private JButton btInstall = new JButton();
private JButton btFertig = new JButton();
private int spam = 0;
private int x = 500;
private int y = 250;
private int rndCnt = 0;
// Ende Attribute
// Diese Timerschleife lässt nach dem btInstall gedrückt wurde (s.u.)
// Spamnachrichten (SKMelde Objekte) erscheinen,
// die jeweils leicht veränderte x und y koordinaten besitzen
private ActionListener alTm1 = new ActionListener() {
public void actionPerformed(ActionEvent e) {
btFertig.setEnabled(true); // der Fertigstellknopf wird
// freigeschaltet, damit man sich
// durch den Timerdelay keinen Sieg
new SKMelde().setLocation(x, y); // erbuggen kann
spam++;
switch(spam) {
case 0: x += 50;
break;
case 1: y += 25;
break;
case 2: x += 50;
break;
case 3: y += 25;
break;
case 4: x += 50;
break;
case 5: tm1.stop();
x = 500;
y = 250;
spam = 0;
break;
default:break;
}
};
};
private Timer tm1 = new Timer(800, alTm1);
private ActionListener alTm2 = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
tm1.start();
rndCnt++;
if(rndCnt == 5) {
// verloren!
erfolg = false;
fertig = true;
guiLoseScreen.setVisible(true);
} else {
tm1.start(); // neue Runde starten
}
}
};
private Timer tm2 = new Timer(5000, alTm2);
public SpamZiel(int schwierigkeit) {
super(titel);
this.schwierigkeit = schwierigkeit;
int frameWidth = 611;
int frameHeight = 308;
setSize(frameWidth, frameHeight);
int x = 400;
int y = 180;
setLocation(x, y);
setResizable(false);
Container cp = getContentPane();
cp.setLayout(null);
taBeschreibungScrollPane.setBounds(88, 16, 417, 169);
taBeschreibung.setText("Missionsbeschreibung"
+ "\n----------------------------------------------"
+ "\n- Drücke den Installieren-Button!"
+ "\n- Schließe die Spamnachrichten!"
+ "\n- Drücke zwischen den Wellen den Fertigstellen-Button!"
+ "\n- Wenn du zu langsam bist und die fünfte Spamwelle"
+ "\n vorüber ist, hast du verloren!");
taBeschreibung.setBackground(Color.BLACK);
taBeschreibung.setFont(new Font("Fixedsys", Font.PLAIN, 12));
taBeschreibung.setForeground(Color.GREEN);
cp.add(taBeschreibungScrollPane);
btInstall.setBounds(104, 192, 169, 33);
btInstall.setText("Installieren");
btInstall.setMargin(new Insets(2, 2, 2, 2));
btInstall.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btInstall_ActionPerformed(evt);
}
});
btInstall.setBackground(Color.BLACK);
btInstall.setBorder(new javax.swing.border.LineBorder(Color.GREEN, 3));
btInstall.setFont(new Font("Fixedsys", Font.PLAIN, 12));
btInstall.setForeground(Color.GREEN);
cp.add(btInstall);
btFertig.setBounds(320, 192, 169, 33);
btFertig.setText("Fertigstellen");
btFertig.setMargin(new Insets(2, 2, 2, 2));
btFertig.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
btFertig_ActionPerformed(evt);
}
});
btFertig.setEnabled(false);
btFertig.setBackground(Color.BLACK);
btFertig.setBorder(new javax.swing.border.LineBorder(Color.GREEN, 3));
btFertig.setFont(new Font("Fixedsys", Font.PLAIN, 12));
btFertig.setForeground(Color.GREEN);
cp.add(btFertig);
cp.setBackground(Color.BLACK);
}
public static void main(String[] args) {
AbstractMiniGame spamZiel = new SpamZiel(0);
spamZiel.initialisieren();
spamZiel.setVisible(true);
}
private void btInstall_ActionPerformed(ActionEvent evt) {
// Start der Spamnachrichten
tm2.start();
btInstall.setEnabled(false);
}
private void btFertig_ActionPerformed(ActionEvent evt) {
// wenn dieser Knopp gedrückt wurde, wurde gewonnen.
tm1.stop();
tm2.stop();
erfolg = true;
fertig = true;
guiWinScreen.setVisible(true);
}
public void initialisieren() {
// die Initialisierungsfunktion der Mutterklasse aufrufen
super.initialisieren();
// die Buttons konfigurieren #noloveforcheaters
btFertig.setEnabled(false);
btInstall.setEnabled(true);
// nicht warten vor dem Timerstart
tm1.setInitialDelay(0);
tm2.setInitialDelay(0);
// zurück auf Anfang..
rndCnt = 0;
}
}