0
|
1
|
|
2 /*
|
23
|
3 Kopiec Kreta - gra w odgadywanie slow
|
0
|
4 ver. 0.4.0-beta
|
23
|
5 autor: Przemyslaw R. Pietraszczyk
|
0
|
6 data: 2020-09-30
|
23
|
7 licencja: GPL v3
|
0
|
8
|
23
|
9 slownik pochodzi z: sjp.pl
|
0
|
10
|
|
11 */
|
|
12
|
|
13 package src;
|
|
14
|
|
15 import java.awt.*; // Toolkit
|
|
16 import javax.swing.JFrame;
|
|
17 import javax.swing.JLabel;
|
|
18 import javax.swing.JPanel;
|
|
19 import javax.swing.JButton;
|
|
20 //import javax.swing.JComponent;
|
|
21 import javax.swing.JMenuBar;
|
|
22 import javax.swing.JMenu;
|
|
23 import javax.swing.JMenuItem;
|
|
24 import javax.swing.JOptionPane;
|
|
25 import javax.swing.Box;
|
|
26 import javax.swing.JTextArea;
|
|
27 import javax.swing.JDialog;
|
|
28 import javax.swing.JTextField;
|
|
29 import javax.swing.JCheckBox;
|
|
30 import javax.swing.BorderFactory;
|
|
31 import javax.swing.WindowConstants;
|
|
32 import java.awt.event.*;
|
|
33 import java.awt.event.ActionListener;
|
|
34 //import java.awt.event.KeyListener;
|
|
35 import java.awt.event.ActionEvent;
|
|
36 import java.awt.event.WindowEvent;
|
|
37 import java.awt.event.WindowAdapter;
|
|
38 import java.awt.event.ComponentAdapter;
|
|
39 import java.awt.event.ComponentEvent;
|
|
40 import java.awt.event.ItemEvent;
|
|
41 //import java.awt.event.KeyEvent;
|
|
42 import java.util.*; //Timer
|
|
43 //import java.awt.Robot;
|
|
44 import java.awt.Toolkit;
|
|
45
|
|
46 import java.beans.*; //property change stuff
|
|
47 import java.io.BufferedReader;
|
|
48 import java.io.InputStream;
|
|
49 import java.io.OutputStream;
|
|
50 import java.io.InputStreamReader;
|
|
51 import java.io.IOException;
|
|
52
|
|
53 public class KopiecKreta extends JTextArea implements ActionListener {
|
|
54
|
|
55 static JMenuBar menuBar;
|
|
56 static JMenu menu, info, menu2;
|
|
57 static JMenuItem menuItem, menuExit, menuInfo, menuPref;
|
|
58 static JFrame frame;
|
|
59 static boolean go=false;
|
|
60 static Timer timer = new Timer();
|
|
61 static String content;
|
|
62 final static int NRINGS=11;
|
|
63 final static int NCHAR=23; //32;
|
|
64 static MyResource res = new MyResource();
|
|
65 static wavResource wav;
|
|
66 static Ring []truering = new Ring[NRINGS];
|
|
67 static Ring []falsering = new Ring[NRINGS];
|
|
68 static String [] mound = new String[20]; // tekst do wyswietlenia przez paint
|
|
69 static JTextArea textArea;
|
|
70 static JPanel startScreen;
|
23
|
71 static int activeRing; // indeks ringu na ktorym jest prowadzona aktualnie gra
|
0
|
72 static KopiecKreta kk;
|
|
73 static Actions actions;
|
|
74 final static String CONSTCH="1234";
|
|
75 final static Character[] charsInStock= {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'r', 's', 't', 'u', 'w', 'y', 'z'};
|
|
76 static ArrayList<String> cheatSheet;
|
|
77 static int pointsForTheRing;
|
|
78 static int pointsFOrTheMund;
|
|
79 static int totalScore, level;
|
|
80 static boolean cheatActivate=false;
|
|
81 static SoundDialog sounddialog;
|
|
82 //static ResetDialog resetdialog;
|
|
83 //static GetNameDialog getNameDialog;
|
|
84 //Boolean runSoundDialog=Boolean.valueOf(false);
|
|
85 static ConfigFile configfile;
|
|
86 //static char pressKey=' ';
|
|
87
|
|
88 public KopiecKreta() {
|
|
89 //GridBagLayout gridbag = (GridBagLayout)getLayout();
|
|
90 //GridBagConstraints c = new GridBagConstraints();
|
|
91
|
|
92 menuBar = new JMenuBar();
|
|
93 menu = new JMenu("Plik");
|
|
94 menuBar.add(menu);
|
|
95 menu2 = new JMenu("Opcje");
|
|
96 menuBar.add(menu2);
|
|
97 // przenosi INFO na prawa strone
|
|
98 menuBar.add(Box.createHorizontalGlue());
|
|
99 info = new JMenu("Info");
|
|
100 // kierunek wyswietlania menu
|
|
101 info.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
|
|
102 menuBar.add(info);
|
|
103 menuItem = new JMenuItem("Nowa Gra", null);
|
|
104 menuItem.setActionCommand("MenuItem1");
|
|
105 menuItem.addActionListener(this);
|
23
|
106 menuItem.setToolTipText("Rozpoczyna nowa gre.");
|
0
|
107 menu.add(menuItem);
|
23
|
108 //menuItem = new JMenuItem("Sala slawy", null);
|
0
|
109 //menuItem.setActionCommand("MenuItem11");
|
|
110 //menuItem.addActionListener(this);
|
23
|
111 //menuItem.setToolTipText("Wyswietla najlepsze wyniki");
|
0
|
112 //menu.add(menuItem);
|
|
113 menu.addSeparator();
|
23
|
114 menuExit = new JMenuItem("Zakoncz", null);
|
0
|
115 menuExit.setActionCommand("MenuItem2");
|
|
116 menuExit.addActionListener(this);
|
23
|
117 menuExit.setToolTipText("Wyjscie z programu");
|
0
|
118 menu.add(menuExit);
|
23
|
119 menuPref = new JMenuItem("Preferencje dzwieku",null);
|
0
|
120 menuPref.setActionCommand("MenuItem4");
|
|
121 menuPref.addActionListener(this);
|
23
|
122 menuPref.setToolTipText("Preferencje dotyczace dzwieku");
|
0
|
123 menu2.add(menuPref);
|
|
124 /*
|
|
125 menuPref = new JMenuItem("Resetowanie",null);
|
|
126 menuPref.setActionCommand("MenuItem5");
|
|
127 menuPref.addActionListener(this);
|
23
|
128 menuPref.setToolTipText("Resetowanie najlepszych wynikow");
|
0
|
129 menu2.add(menuPref);
|
|
130 */
|
|
131 menuInfo = new JMenuItem("Pomoc", null);
|
|
132 menuInfo.setActionCommand("MenuItem33");
|
|
133 menuInfo.addActionListener(this);
|
|
134 menuInfo.setToolTipText("Samouczek");
|
|
135 info.add(menuInfo);
|
|
136 menuInfo = new JMenuItem("O Programie", null);
|
|
137 menuInfo.setActionCommand("MenuItem3");
|
|
138 menuInfo.addActionListener(this);
|
|
139 menuInfo.setToolTipText("Informacje o programie");
|
|
140 info.add(menuInfo);
|
|
141
|
|
142 //addKeyListener(this);
|
|
143 //actions = new Actions();
|
|
144 //addKeyListener(actions);
|
|
145 //setFocusable(true);
|
|
146
|
|
147
|
|
148 }
|
|
149
|
|
150
|
|
151 public void actionPerformed(final ActionEvent e) {
|
|
152
|
|
153 // Nowa gra
|
|
154 if(e.getActionCommand().equals("MenuItem1")) {
|
|
155 //getNameDialog.initUI(configfile, frame, getNameDialog.runGetNameDialog);
|
|
156 //getNameDialog.runGetNameDialog=true;
|
|
157 //if (getNameDialog.go){
|
|
158
|
|
159 activeRing=10;
|
|
160 totalScore=0;
|
|
161 pointsForTheRing=0;
|
|
162 pointsFOrTheMund=0;
|
|
163 level=1;
|
|
164 //frame.remove(startScreen);
|
|
165 //frame.add(textArea);
|
|
166 startScreen.setVisible(false);
|
|
167 textArea.setVisible(true);
|
|
168 create_secret_mound();
|
|
169 create_real_mound(); // generuje prawdziwy kopiec
|
|
170 cheatSheet = new ArrayList<String>();
|
|
171 setCharCheatSheet ();
|
|
172 go=true;
|
|
173 setDisplayMound();
|
|
174 // }
|
|
175 }
|
|
176 // Zakonczenie
|
|
177 else if(e.getActionCommand().equals("MenuItem2")) {
|
|
178 System.exit(0);
|
|
179 }
|
|
180 // O Programie
|
|
181 else if(e.getActionCommand().equals("MenuItem3")) {
|
|
182 String s1=" Port mojej gry pierwotnie napisanej dla Androida 2.3\n\n",
|
23
|
183 s2=" Program napisany na podstawie fragmentow kodow,\n",
|
0
|
184 s3=" wyszukanych w wyszukiwarce Google,\n",
|
23
|
185 s4=" plus wlasna inwencja\n\n",
|
|
186 s5=" Autor zarzeka sie ze nigdy nie posiadal, ani nie posiada\n",
|
|
187 s6=" zadnej ksiazki na temat Javy.\n",
|
|
188 s7="Oraz nie przeczytal ani jednej ksiazki na temat tego jezyka!\n\n",
|
|
189 s8=" Przemyslaw R. Pietraszczyk - jesien 2020\n",
|
|
190 s9=" Licencja: GPL v3\n\n",
|
0
|
191 s10=" Stworzono w oparciu o OpenJDK 11 oraz ANT\n\n",
|
|
192 s11=" o/s: "+configfile.osName+" ver. "+configfile.osVersion+"\n",
|
|
193 s12=" java ver: "+configfile.jvmVersion;
|
|
194
|
|
195 JOptionPane.showMessageDialog(frame,
|
|
196 s1+s2+s3+s4+s5+s6+s7+s8+s9+s10+s11+s12,
|
23
|
197 "Kopiec Kreta 0.230924-0",
|
0
|
198 JOptionPane.PLAIN_MESSAGE);
|
|
199
|
|
200 }
|
|
201 else if(e.getActionCommand().equals("MenuItem33")) {
|
23
|
202 String s1="Celem gry jest odgadniecie wszyskich zakrytych pol.\n",
|
|
203 s2="Rozgrywke rozpoczyna sie od dolnego pierscienia.\n",
|
|
204 s3="Po odgadnieciu wszyskich liter w danym pierscieniu,\n",
|
|
205 s4="rozgrywka przenosi sie na kolejny, wyzszy ring.\n",
|
|
206 s5="Po odgadnieciu wszystkich liter, gracz pytany jest\n",
|
|
207 s6="o chec gry na opcjonalnym nastepnym poziomie.\n\n",
|
0
|
208 s7="UWAGA ! Caps Lock - bez znaczenia !\n",
|
|
209 s8="\n";
|
|
210 JOptionPane.showMessageDialog(frame,
|
|
211 s1+s2+s3+s4+s5+s6+s7+s8,
|
|
212 "Pomoc",
|
|
213 JOptionPane.PLAIN_MESSAGE);
|
|
214 }
|
|
215 else if(e.getActionCommand().equals("MenuItem4")) {
|
|
216 sounddialog.initUI(configfile, frame, sounddialog.runSoundDialog);
|
|
217 sounddialog.runSoundDialog=true;
|
|
218 }
|
|
219 /*
|
|
220 else if(e.getActionCommand().equals("MenuItem5")) {
|
|
221 resetdialog.initUI(configfile);
|
|
222 }
|
|
223 */
|
23
|
224 // sala slawy
|
0
|
225 /*
|
|
226 else if(e.getActionCommand().equals("MenuItem11")) {
|
|
227
|
|
228 }
|
|
229 */
|
|
230 //System.out.println("ACTION PERFORMED " + e);
|
|
231 }
|
|
232
|
|
233 private static void createAndShowGUI() {
|
|
234
|
|
235 frame=new JFrame("Kopiec Kreta");
|
|
236 //Robot robot;
|
|
237 // menuBar z konstruktora
|
|
238 final int frameWidth = 250;
|
|
239 final int frameHeight = 460;
|
23
|
240 final int GNOMEPANEL=80; // nieco nizej niz panel
|
0
|
241 final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
|
|
242 //frame.setBounds((int) screenSize.getWidth() - frameWidth,
|
|
243 // (int) screenSize.getHeight() - frameHeight, frameWidth, frameHeight);
|
|
244 frame.setBounds((int) screenSize.getWidth() - frameWidth,
|
|
245 GNOMEPANEL, frameWidth, frameHeight);
|
|
246 frame.setResizable(false);
|
|
247 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
248 sounddialog = new SoundDialog();
|
|
249 //resetdialog = new ResetDialog();
|
|
250 //getNameDialog = new GetNameDialog();
|
|
251 textArea = new KopiecKreta();
|
|
252 startScreen = new StartScreen();
|
|
253 //textArea.setFont(new Font("Serif", Font.ITALIC, 18));
|
|
254 textArea.setFont(new Font("Serif", Font.BOLD, 18));
|
|
255 textArea.setLineWrap(true); //nowe
|
|
256 textArea.setWrapStyleWord(true); // nowe
|
|
257 textArea.setEditable(false);
|
|
258 textArea.setBounds(5,5,240,430);
|
|
259 frame.add(textArea);
|
|
260 textArea.setVisible(false);
|
|
261 frame.add(menuBar);
|
|
262 frame.add(startScreen);
|
|
263 startScreen.setFont(new Font("Serif", Font.BOLD, 18));
|
|
264 startScreen.setBounds(5,5,240,430);
|
|
265
|
|
266 frame.setJMenuBar(menuBar);
|
|
267 frame.setLayout(null);
|
|
268 frame.setSize(250,500); // 400 x 400
|
|
269 frame.setVisible(true);
|
|
270 actions = new Actions();
|
|
271 frame.addKeyListener(actions);
|
|
272 frame.setFocusable(true);
|
|
273 textArea.setForeground(Color.BLACK);
|
|
274 textArea.setBackground(Color.GREEN);
|
23
|
275 // zapobiega utracie KeyEvent po wyjsciu z SoundDialog i ResetDialog
|
0
|
276 frame.addFocusListener(new FocusListener(){
|
|
277 public void focusGained(FocusEvent e){
|
|
278 //System.out.println("Focus GAINED:"+e);
|
|
279 }
|
|
280 public void focusLost(FocusEvent e){
|
|
281 //System.out.println("Focus LOST:"+e);
|
|
282
|
|
283 // FIX FOR GNOME/XWIN FOCUS BUG
|
|
284 e.getComponent().requestFocus();
|
|
285 }
|
|
286 });
|
|
287 try {
|
|
288 configfile = new ConfigFile();
|
|
289 }catch (IOException e){}
|
|
290 configfile.load();
|
|
291
|
|
292 /*
|
|
293 try {
|
|
294 // obiekt robot posiada metode do pobierania koloru pixela
|
|
295 robot = new Robot();
|
|
296 robot.mouseMove(screenSize.width-100, 200);
|
|
297 robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
|
|
298 robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
|
|
299 }catch (AWTException e) {}
|
|
300 frame.setAlwaysOnTop(true);
|
|
301 */
|
|
302
|
|
303 timer.schedule(new KeyTicks(), 0, 1000); // lepiej 1000
|
|
304
|
|
305 }
|
23
|
306 // dodaje punkty za pierscien i kazuje pozostale litery sciagi
|
0
|
307 static public void addScores(){
|
|
308 int n;
|
|
309 pointsForTheRing=0;
|
|
310 if (!cheatActivate){
|
|
311 for (int i=0;i< cheatSheet.size();i++){
|
|
312 pointsForTheRing++;
|
|
313 }
|
|
314 pointsFOrTheMund+=pointsForTheRing;
|
|
315 }
|
23
|
316 //System.out.println("Naliczylem "+pointsForTheRing+" punktow za ring");
|
0
|
317 }
|
23
|
318 // zapelnia tablice ze znakami do podpowiedzi
|
0
|
319 static private void setCharCheatSheet (){
|
|
320
|
|
321 for (int i=0; i<NCHAR; i++){
|
23
|
322 // przepisujemy kolejno znaki do listy stringow
|
0
|
323 char c= Character.toUpperCase(charsInStock[i]);
|
|
324 cheatSheet.add(String.valueOf(c));
|
|
325 }
|
|
326 }
|
|
327 static private void refreshCheatSheet(int n){
|
|
328 String t="";
|
|
329 cheatSheet.remove(n);
|
|
330 for (int i=0;i< cheatSheet.size();i++){
|
|
331 t+=cheatSheet.get(i);
|
|
332 }
|
|
333 }
|
|
334 // szuka znaku w tablicy z podpowiedzia
|
|
335 static private int searchCharChaetSheet(char c){
|
|
336 String s="";
|
|
337 String sc="";
|
|
338 //String test="";
|
|
339 for (int i=0;i< cheatSheet.size();i++){
|
|
340 s=cheatSheet.get(i);
|
|
341 sc = String.valueOf(c);
|
|
342 // test+=sc;
|
|
343 if (s.equals(sc)) {
|
|
344 return i;
|
|
345 }
|
|
346 }
|
23
|
347 //System.out.println("Nie odnalazlem znaku:"+sc);
|
0
|
348 return -1;
|
|
349 }
|
|
350 static private void create_real_mound(){
|
|
351
|
|
352 int n_char=3;
|
|
353 String r="";
|
|
354
|
|
355 for (int i=0; i<NRINGS; i++){
|
|
356 truering[i] = new Ring(res.getDirectory(n_char));
|
|
357 n_char++;
|
|
358 for (int j=0;j<truering[i].getLength();j++){
|
|
359 String _r=Character.toString(truering[i].getChar(j));
|
|
360
|
|
361 r+=_r;
|
|
362 }
|
|
363 r+="\n";
|
|
364 }
|
|
365
|
|
366 System.out.println(r);
|
|
367
|
|
368 }
|
|
369 public static void create_secret_mound(){
|
|
370 // kodujemy od 3 liter
|
|
371 String s="???";
|
|
372
|
|
373 for (int i=0; i<NRINGS; i++){
|
|
374 falsering[i] = new Ring(s);
|
|
375 s+="?";
|
|
376 }
|
|
377 }
|
|
378
|
|
379 public static void main(final String[] args) {
|
|
380
|
|
381 try {
|
|
382 res.read();
|
|
383 //wav = new wavResource();
|
|
384 //wav.loadWav();
|
|
385 //wav.initWav();
|
|
386 }catch (Exception e) {
|
|
387 e.printStackTrace();
|
|
388 }
|
|
389 javax.swing.SwingUtilities.invokeLater(new RunnableImplementation());
|
|
390 }
|
|
391
|
|
392 static private void setDisplayMound(){
|
|
393 String sr = new String();
|
|
394 String r="";
|
|
395 textArea.setText(null);
|
|
396 sr+="\n";
|
23
|
397 // i=1 poniewaz pomijamy 3 literowy ring
|
0
|
398 for (int i=1;i<NRINGS;i++){
|
|
399
|
|
400 //String r="";
|
|
401 for (int j=0;j<truering[i].getLength();j++){
|
|
402
|
|
403 String _r=Character.toString(truering[i].getChar(j));
|
|
404 r+=_r;
|
|
405 }
|
|
406 //System.out.println(r);
|
|
407 r="";
|
|
408 sr+=" ";
|
|
409 if (i==activeRing){
|
|
410 sr+=">";
|
|
411 }
|
|
412 else sr+=" ";
|
|
413 for (int j=0;j<falsering[i].getLength();j++){
|
|
414 String _s=Character.toString(falsering[i].getChar(j));
|
|
415 sr +=_s;
|
|
416 }
|
|
417 if (i==activeRing){
|
|
418 sr+="<";
|
|
419 }
|
|
420 mound[i]=sr;
|
|
421 //System.out.println("mound["+i+"] "+mound[i]);
|
|
422
|
|
423 textArea.append(mound[i]+"\n");
|
|
424 sr="";
|
|
425 }
|
|
426 textArea.append("\n\n");
|
|
427 for (int i=0; i<cheatSheet.size();i++){
|
|
428 textArea.append(cheatSheet.get(i));
|
|
429 textArea.append(" ");
|
|
430 }
|
|
431
|
|
432 }
|
|
433
|
|
434
|
|
435 private static final class RunnableImplementation implements Runnable {
|
|
436 public void run(){
|
|
437 wav = new wavResource();
|
|
438 createAndShowGUI();
|
|
439 }
|
|
440 }
|
|
441 public static void unhideWords(){
|
|
442 for (int j=0;j<truering[activeRing].getLength();j++){
|
|
443 falsering[activeRing].setChar(truering[activeRing].getChar(j),j);
|
|
444 }
|
|
445 }
|
|
446
|
|
447 static class KeyTicks extends TimerTask {
|
|
448 int cw=0;
|
|
449 static char pressKey='Q';
|
|
450 static char lastKey='Q';
|
|
451 static boolean firstRun=true;
|
|
452 int n=0;
|
|
453 /* FIXME - miga gdy odnaleziono litere ?
|
|
454 */
|
|
455 public void run() {
|
|
456 ArrayList<Integer> indexExist = new ArrayList<Integer>();
|
|
457 int returnIndex;
|
|
458
|
|
459
|
|
460 pressKey=actions.getKey();
|
|
461
|
|
462 if (go) {
|
|
463 wav.stop();
|
|
464 indexExist=checkInstance(pressKey);
|
|
465 for (int exist: indexExist){
|
|
466 falsering[activeRing].setChar(pressKey,exist);
|
|
467 wav.PlayFlag=true;
|
|
468 if (lastKey != pressKey) {
|
|
469 if (sounddialog.soundAccept()){
|
23
|
470 //System.out.println("Dzwiek akceptuje");
|
0
|
471 wav.play("/smooth-ok.wav");
|
|
472 }
|
23
|
473 else System.out.println("Dzwiek NIE akceptuje");
|
0
|
474 }
|
|
475 }
|
|
476 if (lastKey != pressKey && indexExist.isEmpty() && !firstRun) {
|
|
477 //if (lastKey != pressKey && indexExist.isEmpty()) {
|
|
478
|
|
479 wav.PlayFlag=true;
|
|
480 if (sounddialog.soundAccept()){
|
23
|
481 //System.out.println("Dzwiek akceptuje");
|
0
|
482 wav.play("/bass-bad.wav");
|
|
483 }
|
23
|
484 else System.out.println("Dzwiek NIE akceptuje");
|
0
|
485 }
|
|
486 lastKey=pressKey;
|
|
487
|
|
488 returnIndex = searchCharChaetSheet(pressKey);
|
|
489 if (returnIndex != -1){
|
|
490 refreshCheatSheet(returnIndex);
|
|
491 }
|
|
492 setDisplayMound();
|
|
493 pressKey=' ';
|
|
494 indexExist.clear();
|
|
495
|
|
496 if (actions.getCheat().equals(CONSTCH)){
|
|
497 //pointsForTheRing=0;
|
|
498 actions.resetCheat();
|
|
499 cheatActivate=true;
|
|
500 unhideWords();
|
|
501 }
|
|
502 if (checkFullRing()) {
|
|
503 totalScore+=pointsForTheRing;
|
|
504 setCharCheatSheet ();
|
|
505 setDisplayMound();
|
|
506
|
|
507 }
|
|
508
|
|
509 firstRun=false;
|
|
510 }
|
|
511 }
|
|
512 static private boolean checkFullRing() {
|
|
513 if (truering[activeRing].getString().equals(falsering[activeRing].getString())){
|
23
|
514 //System.out.println("Czy zaliczony pierscien ? activeRing:"+activeRing);
|
0
|
515 if (activeRing >1){
|
|
516 addScores();
|
|
517 cheatActivate=false;
|
23
|
518 // nowa sciaga
|
0
|
519 cheatSheet = new ArrayList<String>();
|
|
520 activeRing--;
|
|
521 return true;
|
|
522 }
|
|
523 else {
|
|
524 go=false;
|
|
525
|
|
526 setDisplayMound();
|
|
527 if(activeRing==1){
|
|
528
|
23
|
529 String s1="Ukonczyles poziom "+level+" !\n",
|
|
530 s2="Na tym poziomie uzyskales "+pointsFOrTheMund+" punktow.\n",
|
|
531 s3="Poki co ugrales "+totalScore+" punktow !\n\n",
|
|
532 s4="Kontynujesz gre ?";
|
0
|
533
|
|
534 // moze boolean ?
|
|
535 int dialogButton = JOptionPane.YES_NO_OPTION;
|
|
536 int answer = JOptionPane.showConfirmDialog (frame, s1+s2+s3+s4,"Komunikat", dialogButton);
|
|
537
|
|
538 if(answer == JOptionPane.YES_OPTION) {
|
|
539 activeRing=10;
|
|
540 go=true;
|
|
541 level++;
|
|
542 create_secret_mound();
|
|
543 create_real_mound(); // generuje prawdziwy kopiec
|
|
544 setDisplayMound();
|
|
545 pointsFOrTheMund=0;
|
|
546 }
|
|
547 if(answer == JOptionPane.NO_OPTION) {
|
|
548 System.exit(0);
|
|
549
|
|
550 }
|
|
551 }
|
|
552 }
|
|
553 }
|
|
554 return false;
|
|
555 }
|
23
|
556 // sprawdza czy rzadana litera znajduje sie w pierscieniu
|
0
|
557 static private ArrayList<Integer> checkInstance(char key){
|
|
558 ArrayList<Integer> indexExist = new ArrayList<Integer>();
|
|
559
|
|
560 for (int i=0; i<truering[activeRing].getLength();i++){
|
|
561 if (truering[activeRing].getChar(i) == key) {
|
|
562 indexExist.add(i);
|
|
563 }
|
|
564 }
|
|
565 /*
|
|
566 if (indexExist.size()!=0) {
|
|
567 changeView=true;
|
|
568 }
|
|
569 */
|
|
570 return indexExist;
|
|
571 }
|
|
572 }
|
|
573 static class Ring {
|
|
574 char c[];
|
|
575 int l=0; // dlugosc
|
|
576 public Ring(String s){
|
|
577 //System.out.println("Z Ring constructor: "+s+" dlugosc: "+s.length());
|
|
578 c = new char[s.length()+2];
|
|
579 c =s.toCharArray();
|
|
580 l=s.length();
|
|
581 }
|
|
582 public char getChar(int poz){
|
|
583 return (char) c[poz];
|
|
584 }
|
|
585 public void setChar(char _c,int p){
|
|
586 c[p]=_c;
|
|
587 }
|
|
588 public int getLength(){
|
|
589 return l;
|
|
590 }
|
|
591 public String getString(){
|
|
592 String sr = new String();
|
|
593 for (int j=0;j<l;j++){
|
|
594 String _s=Character.toString(c[j]);
|
|
595 sr +=_s;
|
|
596 }
|
|
597 return sr;
|
|
598 }
|
|
599 }
|
|
600 }
|
|
601 class SoundDialog implements ItemListener, ActionListener{
|
|
602 JCheckBox chkBox1;
|
|
603 JFrame frame;
|
|
604 boolean sound = true;
|
|
605 ConfigFile config;
|
|
606 public Boolean runSoundDialog=false;
|
|
607
|
|
608 protected void initUI(ConfigFile cf, JFrame f, Boolean run) {
|
|
609 if (!run) {
|
|
610 frame = new JFrame("Zapytanko");
|
23
|
611 frame.getContentPane().setSize(new Dimension(300,200)); // nie dziala
|
0
|
612 frame.getContentPane().setLayout(new GridBagLayout());
|
|
613 frame.setAlwaysOnTop(true);
|
|
614 GridBagConstraints c = new GridBagConstraints();
|
|
615 // nadpisanie metody zamykania okna
|
|
616 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
617 frame.addWindowListener(new WindowAdapter() {
|
|
618 public void windowClosing(WindowEvent ev) {
|
|
619 runSoundDialog=false;
|
|
620 frame.dispose();
|
|
621 }
|
|
622 // zapobiega minimalizacji okna dialogowego
|
|
623 public void windowIconified(WindowEvent we) {
|
|
624 frame.setState(JFrame.NORMAL);
|
|
625 //JOptionPane.showMessageDialog(frame, "Cant Minimize");
|
|
626 }
|
|
627 });
|
|
628 JLabel label = new JLabel(" ");
|
23
|
629 JButton button = new JButton("Zatwierdz");
|
|
630 chkBox1= new JCheckBox("Odtwarzaj dzwiek");
|
0
|
631 config=cf;
|
|
632 sound = cf.load();
|
|
633 System.out.println("Dzwiek: "+sound);
|
|
634 chkBox1.setSelected(sound);
|
|
635 c.fill = GridBagConstraints.HORIZONTAL;
|
|
636 c.ipady = 0;
|
|
637 c.weighty = 1.0;
|
|
638 c.gridwidth = 3;
|
|
639 c.gridx = 0;
|
|
640 c.gridy = 0;
|
|
641 frame.getContentPane().add(chkBox1,c);
|
|
642
|
|
643 c.fill = GridBagConstraints.HORIZONTAL;
|
|
644 c.ipady = 0;
|
|
645 c.weighty = 1.0;
|
|
646 c.gridwidth = 3;
|
|
647 c.gridx = 0;
|
|
648 c.gridy = 1;
|
|
649 frame.getContentPane().add(label,c);
|
|
650
|
|
651 c.fill = GridBagConstraints.HORIZONTAL;
|
|
652 c.ipady = 0;
|
|
653 c.weighty = 1.0;
|
|
654 c.anchor = GridBagConstraints.PAGE_END; //bottom of space
|
|
655 c.gridwidth = 3;
|
|
656 c.gridx = 0;
|
|
657 c.gridy = 2;
|
|
658 frame.getContentPane().add(button,c);
|
|
659
|
|
660 chkBox1.addItemListener(this);
|
|
661 button.addActionListener(this);
|
|
662 if (cf.osName.equals("Linux")) frame.setUndecorated(true);
|
|
663 chkBox1.setBorder(BorderFactory.createMatteBorder(20, 20, 20, 20, Color.RED)); // w tym wypadku kolor nie ma znaczenia
|
|
664 frame.getRootPane().setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.RED));
|
|
665 frame.pack();
|
23
|
666 // pojawi sie nad oknem rodzica
|
0
|
667 frame.setLocationRelativeTo(f);
|
|
668 frame.setResizable(false);
|
|
669 frame.setVisible(true);
|
|
670 }
|
|
671 }
|
|
672 public void itemStateChanged(ItemEvent e) {
|
|
673
|
|
674 Object source = e.getItemSelectable();
|
|
675
|
|
676 if (source == chkBox1) {
|
|
677 //System.out.println("Zaznaczono dzwiek");
|
|
678 sound = true;
|
|
679 }
|
|
680 if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
681 //System.out.println("Odznaczono dzwiek");
|
|
682 sound = false;
|
|
683
|
|
684 }
|
|
685
|
|
686 }
|
|
687 public void actionPerformed(ActionEvent e) {
|
|
688 frame.setVisible(false);
|
|
689 config.save(sound);
|
|
690 runSoundDialog=false;
|
23
|
691 //System.out.println("Zapisuje dzwiek: "+sound);
|
0
|
692
|
|
693 }
|
|
694 public boolean soundAccept(){
|
|
695 return sound;
|
|
696 }
|
|
697 }
|
|
698 /*
|
|
699 class ResetDialog implements ItemListener, ActionListener{
|
|
700 JCheckBox chkBox1;
|
|
701 JFrame frame;
|
|
702 boolean reset = false;
|
|
703 protected void initUI(ConfigFile cf) {
|
|
704
|
|
705 frame = new JFrame("Zapytanko");
|
|
706
|
|
707 JPanel mainPanel;
|
|
708 JButton button;
|
|
709 frame.getContentPane().setLayout(new GridBagLayout());
|
|
710 GridBagConstraints c = new GridBagConstraints();
|
23
|
711 button = new JButton("Zatwierdz");
|
|
712 //chkBox1= new JCheckBox("Odtwarzaj dzwiek");
|
0
|
713 chkBox1= new JCheckBox("Zresetuj najlepsze wyniki");
|
|
714
|
|
715 chkBox1.setSelected(reset);
|
|
716 c.fill = GridBagConstraints.HORIZONTAL;
|
|
717 c.ipady = 0;
|
|
718 c.weighty = 1.0;
|
|
719 //c.anchor = GridBagConstraints.PAGE_END; //bottom of space
|
|
720 c.gridwidth = 3;
|
|
721 c.gridx = 0;
|
|
722 c.gridy = 0;
|
|
723 frame.getContentPane().add(chkBox1,c);
|
|
724
|
|
725
|
|
726
|
|
727 c.fill = GridBagConstraints.HORIZONTAL;
|
|
728 c.ipady = 0;
|
|
729 c.weighty = 1.0;
|
|
730 c.anchor = GridBagConstraints.PAGE_END; //bottom of space
|
|
731 c.gridwidth = 3;
|
|
732 c.gridx = 0;
|
|
733 c.gridy = 2;
|
|
734 frame.getContentPane().add(button,c);
|
|
735
|
|
736
|
|
737
|
|
738 chkBox1.addItemListener(this);
|
|
739 button.addActionListener(this);
|
|
740 frame.pack();
|
|
741 frame.setLocationRelativeTo(null);
|
|
742 frame.setResizable(false);
|
|
743 frame.setVisible(true);
|
|
744 }
|
|
745 public void itemStateChanged(ItemEvent e) {
|
|
746 //t index = 0;
|
|
747 //ar c = '-';
|
|
748 Object source = e.getItemSelectable();
|
|
749
|
|
750 if (source == chkBox1) {
|
|
751 //dex = 0;
|
|
752 System.out.println("Zaznaczono dzwiek");
|
|
753 reset = true;
|
|
754 }
|
|
755 if (e.getStateChange() == ItemEvent.DESELECTED) {
|
|
756 System.out.println("Odznaczono dzwiek");
|
|
757 reset = false;
|
|
758
|
|
759 }
|
|
760
|
|
761 }
|
|
762 public void actionPerformed(ActionEvent e) {
|
|
763 frame.setVisible(false);
|
|
764 System.out.println("jestem action");
|
|
765 }
|
|
766 public boolean resetAccept(){
|
|
767 return reset;
|
|
768 }
|
|
769 }
|
|
770 */
|
|
771 /*
|
|
772 class GetNameDialog implements ActionListener, KeyListener {
|
|
773 JTextField text;
|
|
774 JFrame frame;
|
|
775 public String namePlayer="";
|
|
776 public boolean go;
|
|
777 ConfigFile config;
|
|
778 public Boolean runGetNameDialog=false;
|
|
779
|
|
780 protected void initUI(ConfigFile cf, JFrame f, Boolean run) {
|
|
781 if (!run) {
|
|
782 frame = new JFrame("Zapytanko");
|
23
|
783 frame.getContentPane().setSize(new Dimension(300,200)); // nie dziala
|
0
|
784 frame.getContentPane().setLayout(new GridBagLayout());
|
|
785 frame.setAlwaysOnTop(true);
|
|
786 GridBagConstraints c = new GridBagConstraints();
|
|
787 // nadpisanie metody zamykania okna
|
|
788 frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
|
789 frame.addWindowListener(new WindowAdapter() {
|
|
790 public void windowClosing(WindowEvent ev) {
|
|
791 runGetNameDialog=false;
|
|
792 frame.dispose();
|
|
793 }
|
|
794 });
|
|
795 JLabel label1 = new JLabel(" ");
|
23
|
796 JLabel label2 = new JLabel("Najperw sie przedstaw:");
|
|
797 JButton button = new JButton("Zatwierdz");
|
0
|
798 button.setActionCommand("Button");
|
|
799
|
|
800 text = new JTextField();
|
|
801 //text.addActionListener(this);
|
|
802 //text.setActionCommand("Text");
|
|
803
|
|
804 text.addKeyListener(this);
|
|
805 text.setFocusable(true);
|
|
806 text.requestFocus();
|
|
807
|
|
808 c.fill = GridBagConstraints.HORIZONTAL;
|
|
809 c.ipady = 0;
|
|
810 c.weighty = 1.0;
|
|
811 c.gridwidth = 3;
|
|
812 c.gridx = 0;
|
|
813 c.gridy = 0;
|
|
814 frame.getContentPane().add(label2,c);
|
|
815
|
|
816 c.fill = GridBagConstraints.HORIZONTAL;
|
|
817 c.ipady = 0;
|
|
818 c.weighty = 1.0;
|
|
819 c.gridwidth = 3;
|
|
820 c.gridx = 0;
|
|
821 c.gridy = 1;
|
|
822 frame.getContentPane().add(text,c);
|
|
823
|
|
824 c.fill = GridBagConstraints.HORIZONTAL;
|
|
825 c.ipady = 0;
|
|
826 c.weighty = 1.0;
|
|
827 c.gridwidth = 3;
|
|
828 c.gridx = 0;
|
|
829 c.gridy = 2;
|
|
830 frame.getContentPane().add(label1,c);
|
|
831
|
|
832 c.fill = GridBagConstraints.HORIZONTAL;
|
|
833 c.ipady = 0;
|
|
834 c.weighty = 1.0;
|
|
835 c.anchor = GridBagConstraints.PAGE_END; //bottom of space
|
|
836 c.gridwidth = 3;
|
|
837 c.gridx = 0;
|
|
838 c.gridy = 3;
|
|
839 frame.getContentPane().add(button,c);
|
|
840 text.setEditable(true);
|
|
841 if (namePlayer.length()!=0){
|
|
842 text.setText(namePlayer);
|
|
843 text.selectAll();
|
|
844 }
|
|
845 button.addActionListener(this);
|
|
846 if (cf.osName.equals("Linux")) frame.setUndecorated(true);
|
|
847 frame.getRootPane().setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.RED));
|
|
848 frame.pack();
|
|
849 frame.setLocationRelativeTo(f);
|
|
850 frame.setResizable(false);
|
|
851 frame.setVisible(true);
|
|
852 }
|
|
853 }
|
|
854
|
|
855 public void actionPerformed(ActionEvent e) {
|
|
856 if(e.getActionCommand().equals("Button")) {
|
|
857
|
|
858 frame.setVisible(false);
|
|
859 namePlayer=text.getText();
|
|
860 runGetNameDialog=false;
|
|
861 if (namePlayer.length()!=0){
|
|
862 go=true;
|
|
863 }
|
|
864 }
|
|
865 else if(e.getActionCommand().equals("Text")) {
|
|
866
|
|
867 String t= text.getText();
|
|
868 text.setText(t);
|
|
869 text.selectAll();
|
|
870
|
|
871 }
|
|
872 }
|
|
873
|
|
874 @Override
|
|
875 public void keyTyped(KeyEvent e) {
|
|
876 }
|
|
877
|
|
878 @Override
|
|
879 public void keyReleased(KeyEvent event) {
|
|
880 }
|
|
881
|
|
882 @Override
|
|
883 public void keyPressed(KeyEvent event) {
|
|
884 if (event.getExtendedKeyCode() == KeyEvent.getExtendedKeyCodeForChar('a')) {
|
|
885 System.out.println("OK");
|
|
886 }
|
|
887 System.out.println("GETNAME");
|
|
888 String t= text.getText();
|
|
889 text.setText(t);
|
|
890 text.selectAll();
|
|
891 }
|
|
892 }
|
|
893
|
|
894 /*
|
|
895 private void readConfig() {
|
|
896
|
|
897
|
|
898 try {
|
|
899 InputStream is = this.getClass().getResourceAsStream("/config");
|
|
900 BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8"));
|
|
901
|
|
902 lineConfig = br.readLine();
|
|
903 } catch (Exception e){
|
|
904 e.printStackTrace();
|
|
905 }
|
|
906 }
|
|
907 */
|
|
908 /*
|
|
909 private void writeConfig() {
|
|
910
|
|
911
|
|
912 try {
|
|
913 OutputStream is = this.getClass().getResourceAsStream("/config");
|
|
914 BufferedReader br=new BufferedReader(new InputStreamReader(is, "utf-8"));
|
|
915
|
|
916 lineConfig = br.readLine();
|
|
917 } catch (Exception e){
|
|
918 e.printStackTrace();
|
|
919 }
|
|
920 }
|
|
921 */
|
23
|
922 //}
|