annotate kopieckreta/src/KopiecKreta.java @ 21:bef3b1af6326

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