Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx-javam
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx-javam
Commits
75301e06
Commit
75301e06
authored
Jun 13, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Uzupełnienie gry w jabłka o koszyk
parent
bf3d4eec
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
233 additions
and
24 deletions
+233
-24
nbactions.xml
20240606_Gra2/nbactions.xml
+55
-0
OknoGlowne.form
20240606_Gra2/src/main/java/gra/OknoGlowne.form
+58
-1
OknoGlowne.java
20240606_Gra2/src/main/java/gra/OknoGlowne.java
+84
-4
Plansza.java
20240606_Gra2/src/main/java/gra/Plansza.java
+36
-19
No files found.
20240606_Gra2/nbactions.xml
0 → 100644
View file @
75301e06
<?xml version="1.0" encoding="UTF-8"?>
<actions>
<action>
<actionName>
run
</actionName>
<packagings>
<packaging>
jar
</packaging>
</packagings>
<goals>
<goal>
process-classes
</goal>
<goal>
org.codehaus.mojo:exec-maven-plugin:3.1.0:exec
</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
<exec.args>
${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}
</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>
gra.OknoGlowne
</exec.mainClass>
<exec.executable>
java
</exec.executable>
</properties>
</action>
<action>
<actionName>
debug
</actionName>
<packagings>
<packaging>
jar
</packaging>
</packagings>
<goals>
<goal>
process-classes
</goal>
<goal>
org.codehaus.mojo:exec-maven-plugin:3.1.0:exec
</goal>
</goals>
<properties>
<exec.vmArgs>
-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}
</exec.vmArgs>
<exec.args>
${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}
</exec.args>
<exec.appArgs></exec.appArgs>
<exec.mainClass>
gra.OknoGlowne
</exec.mainClass>
<exec.executable>
java
</exec.executable>
<jpda.listen>
true
</jpda.listen>
</properties>
</action>
<action>
<actionName>
profile
</actionName>
<packagings>
<packaging>
jar
</packaging>
</packagings>
<goals>
<goal>
process-classes
</goal>
<goal>
org.codehaus.mojo:exec-maven-plugin:3.1.0:exec
</goal>
</goals>
<properties>
<exec.vmArgs></exec.vmArgs>
<exec.args>
${exec.vmArgs} -classpath %classpath ${exec.mainClass} ${exec.appArgs}
</exec.args>
<exec.mainClass>
gra.OknoGlowne
</exec.mainClass>
<exec.executable>
java
</exec.executable>
<exec.appArgs></exec.appArgs>
</properties>
</action>
</actions>
20240606_Gra2/src/main/java/gra/OknoGlowne.form
View file @
75301e06
...
...
@@ -72,6 +72,17 @@
<Component
id=
"jLabel1"
max=
"32767"
attributes=
"0"
/>
<Component
id=
"jLabel2"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
<Component
id=
"jSlider2"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
<Group
type=
"102"
attributes=
"0"
>
<Group
type=
"103"
groupAlignment=
"0"
attributes=
"0"
>
<Component
id=
"jLabel4"
alignment=
"0"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<Group
type=
"103"
alignment=
"0"
groupAlignment=
"1"
max=
"-2"
attributes=
"0"
>
<Component
id=
"jLabel_Zgubione"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
<Component
id=
"jLabel3"
alignment=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
<Component
id=
"jLabel_Zlapane"
alignment=
"0"
min=
"-2"
pref=
"184"
max=
"-2"
attributes=
"0"
/>
</Group>
<EmptySpace
min=
"0"
pref=
"0"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
</Group>
...
...
@@ -88,7 +99,15 @@
<Component
id=
"jLabel2"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jSlider2"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
pref=
"613"
max=
"32767"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"67"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel3"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel_Zlapane"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
min=
"-2"
pref=
"27"
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel4"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
max=
"-2"
attributes=
"0"
/>
<Component
id=
"jLabel_Zgubione"
min=
"-2"
max=
"-2"
attributes=
"0"
/>
<EmptySpace
pref=
"407"
max=
"32767"
attributes=
"0"
/>
</Group>
</Group>
</DimensionLayout>
...
...
@@ -110,6 +129,41 @@
</Properties>
</Component>
<Component
class=
"javax.swing.JSlider"
name=
"jSlider2"
>
<Events>
<EventHandler
event=
"stateChanged"
listener=
"javax.swing.event.ChangeListener"
parameters=
"javax.swing.event.ChangeEvent"
handler=
"jSlider2StateChanged"
/>
</Events>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel3"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Segoe UI"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Liczba złapanych jabłek"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel4"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Segoe UI"
size=
"18"
style=
"0"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"Liczba zgubionych jabłek"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel_Zgubione"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Segoe UI"
size=
"18"
style=
"1"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"0"
/>
</Properties>
</Component>
<Component
class=
"javax.swing.JLabel"
name=
"jLabel_Zlapane"
>
<Properties>
<Property
name=
"font"
type=
"java.awt.Font"
editor=
"org.netbeans.beaninfo.editors.FontEditor"
>
<Font
name=
"Segoe UI"
size=
"18"
style=
"1"
/>
</Property>
<Property
name=
"text"
type=
"java.lang.String"
value=
"0"
/>
</Properties>
</Component>
</SubComponents>
</Container>
...
...
@@ -123,6 +177,9 @@
</Border>
</Property>
</Properties>
<Events>
<EventHandler
event=
"mouseMoved"
listener=
"java.awt.event.MouseMotionListener"
parameters=
"java.awt.event.MouseEvent"
handler=
"plansza1MouseMoved"
/>
</Events>
<Layout>
<DimensionLayout
dim=
"0"
>
...
...
20240606_Gra2/src/main/java/gra/OknoGlowne.java
View file @
75301e06
...
...
@@ -4,6 +4,8 @@
*/
package
gra
;
import
javax.swing.Timer
;
/**
*
* @author kurs
...
...
@@ -15,6 +17,7 @@ public class OknoGlowne extends javax.swing.JFrame {
*/
public
OknoGlowne
()
{
initComponents
();
timer
.
start
();
}
/**
...
...
@@ -31,6 +34,10 @@ public class OknoGlowne extends javax.swing.JFrame {
jLabel1
=
new
javax
.
swing
.
JLabel
();
jLabel2
=
new
javax
.
swing
.
JLabel
();
jSlider2
=
new
javax
.
swing
.
JSlider
();
jLabel3
=
new
javax
.
swing
.
JLabel
();
jLabel4
=
new
javax
.
swing
.
JLabel
();
jLabel_Zgubione
=
new
javax
.
swing
.
JLabel
();
jLabel_Zlapane
=
new
javax
.
swing
.
JLabel
();
plansza1
=
new
gra
.
Plansza
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
...
...
@@ -50,6 +57,24 @@ public class OknoGlowne extends javax.swing.JFrame {
jLabel2
.
setText
(
"Skok"
);
jSlider2
.
addChangeListener
(
new
javax
.
swing
.
event
.
ChangeListener
()
{
public
void
stateChanged
(
javax
.
swing
.
event
.
ChangeEvent
evt
)
{
jSlider2StateChanged
(
evt
);
}
});
jLabel3
.
setFont
(
new
java
.
awt
.
Font
(
"Segoe UI"
,
0
,
18
));
// NOI18N
jLabel3
.
setText
(
"Liczba złapanych jabłek"
);
jLabel4
.
setFont
(
new
java
.
awt
.
Font
(
"Segoe UI"
,
0
,
18
));
// NOI18N
jLabel4
.
setText
(
"Liczba zgubionych jabłek"
);
jLabel_Zgubione
.
setFont
(
new
java
.
awt
.
Font
(
"Segoe UI"
,
1
,
18
));
// NOI18N
jLabel_Zgubione
.
setText
(
"0"
);
jLabel_Zlapane
.
setFont
(
new
java
.
awt
.
Font
(
"Segoe UI"
,
1
,
18
));
// NOI18N
jLabel_Zlapane
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
jPanel1Layout
=
new
javax
.
swing
.
GroupLayout
(
jPanel1
);
jPanel1
.
setLayout
(
jPanel1Layout
);
jPanel1Layout
.
setHorizontalGroup
(
...
...
@@ -60,7 +85,15 @@ public class OknoGlowne extends javax.swing.JFrame {
.
addComponent
(
jSlider1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
258
,
Short
.
MAX_VALUE
)
.
addComponent
(
jLabel1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
jLabel2
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
jSlider2
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
))
.
addComponent
(
jSlider2
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addGroup
(
jPanel1Layout
.
createSequentialGroup
()
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addComponent
(
jLabel4
)
.
addGroup
(
jPanel1Layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
false
)
.
addComponent
(
jLabel_Zgubione
,
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
)
.
addComponent
(
jLabel3
,
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
Short
.
MAX_VALUE
))
.
addComponent
(
jLabel_Zlapane
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
184
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
0
,
0
,
Short
.
MAX_VALUE
)))
.
addContainerGap
())
);
jPanel1Layout
.
setVerticalGroup
(
...
...
@@ -74,10 +107,23 @@ public class OknoGlowne extends javax.swing.JFrame {
.
addComponent
(
jLabel2
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jSlider2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addContainerGap
(
613
,
Short
.
MAX_VALUE
))
.
addGap
(
67
,
67
,
67
)
.
addComponent
(
jLabel3
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jLabel_Zlapane
)
.
addGap
(
27
,
27
,
27
)
.
addComponent
(
jLabel4
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jLabel_Zgubione
)
.
addContainerGap
(
407
,
Short
.
MAX_VALUE
))
);
plansza1
.
setBorder
(
javax
.
swing
.
BorderFactory
.
createLineBorder
(
new
java
.
awt
.
Color
(
0
,
153
,
0
)));
plansza1
.
addMouseMotionListener
(
new
java
.
awt
.
event
.
MouseMotionAdapter
()
{
public
void
mouseMoved
(
java
.
awt
.
event
.
MouseEvent
evt
)
{
plansza1MouseMoved
(
evt
);
}
});
javax
.
swing
.
GroupLayout
plansza1Layout
=
new
javax
.
swing
.
GroupLayout
(
plansza1
);
plansza1
.
setLayout
(
plansza1Layout
);
...
...
@@ -115,10 +161,19 @@ public class OknoGlowne extends javax.swing.JFrame {
}
// </editor-fold>//GEN-END:initComponents
private
void
jSlider1StateChanged
(
javax
.
swing
.
event
.
ChangeEvent
evt
)
{
//GEN-FIRST:event_jSlider1StateChanged
int
czas
=
2000
/
jSlider1
.
getValue
(
);
plansza1
.
setPauza
(
czas
);
int
czas
=
500
/
(
jSlider1
.
getValue
()+
1
);
setPauza
(
czas
);
}
//GEN-LAST:event_jSlider1StateChanged
private
void
jSlider2StateChanged
(
javax
.
swing
.
event
.
ChangeEvent
evt
)
{
//GEN-FIRST:event_jSlider2StateChanged
plansza1
.
setSkok
((
jSlider2
.
getValue
())/
5
+
1
);
}
//GEN-LAST:event_jSlider2StateChanged
private
void
plansza1MouseMoved
(
java
.
awt
.
event
.
MouseEvent
evt
)
{
//GEN-FIRST:event_plansza1MouseMoved
plansza1
.
ustawKoszyk
(
evt
.
getX
());
plansza1
.
repaint
();
}
//GEN-LAST:event_plansza1MouseMoved
/**
* @param args the command line arguments
*/
...
...
@@ -157,9 +212,34 @@ public class OknoGlowne extends javax.swing.JFrame {
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JLabel
jLabel1
;
private
javax
.
swing
.
JLabel
jLabel2
;
private
javax
.
swing
.
JLabel
jLabel3
;
private
javax
.
swing
.
JLabel
jLabel4
;
private
javax
.
swing
.
JLabel
jLabel_Zgubione
;
private
javax
.
swing
.
JLabel
jLabel_Zlapane
;
private
javax
.
swing
.
JPanel
jPanel1
;
private
javax
.
swing
.
JSlider
jSlider1
;
private
javax
.
swing
.
JSlider
jSlider2
;
private
gra
.
Plansza
plansza1
;
// End of variables declaration//GEN-END:variables
// w milisekundach - co jaki czas ma być odświeżony ekran
private
int
pauza
=
1000
;
private
Timer
timer
=
new
Timer
(
pauza
,
(
evt
)
->
{
plansza1
.
jedenKrok
();
jLabel_Zlapane
.
setText
(
String
.
valueOf
(
plansza1
.
getIleZlapanych
()));
jLabel_Zgubione
.
setText
(
String
.
valueOf
(
plansza1
.
getIleZgubionych
()));
// repaint();
});
public
int
getPauza
()
{
return
pauza
;
}
public
void
setPauza
(
int
pauza
)
{
this
.
pauza
=
pauza
;
timer
.
setDelay
(
pauza
);
timer
.
restart
();
}
}
20240606_Gra2/src/main/java/gra/Plansza.java
View file @
75301e06
package
gra
;
import
java.awt.Color
;
import
java.awt.Graphics
;
import
java.util.HashSet
;
import
java.util.Random
;
import
java.util.Set
;
import
javax.swing.JPanel
;
import
javax.swing.Timer
;
public
class
Plansza
extends
JPanel
{
private
Set
<
Jablko
>
jablka
=
new
HashSet
<>();
private
Random
random
=
new
Random
();
// w milisekundach - co jaki czas ma być odświeżony ekran
private
int
pauza
=
1000
;
// o ile pikseli jablka spadaja w jednym ruchu
private
int
skok
=
20
;
private
double
prawdopodobienstwoNowegoJablka
=
0.5
;
private
Timer
timer
=
new
Timer
(
pauza
,
(
evt
)
->
{
jedenKrok
();
});
public
Plansza
()
{
timer
.
start
();
}
private
int
koszyk
;
private
int
ileZlapanych
,
ileZgubionych
;
final
int
SZEROKOSC_KOSZYKA
=
50
;
final
int
WYSOKOSC_KOSZYKA
=
20
;
@Override
protected
void
paintComponent
(
Graphics
g
)
{
...
...
@@ -32,13 +27,26 @@ public class Plansza extends JPanel {
for
(
Jablko
jablko
:
jablka
)
{
jablko
.
narysujSie
(
g
);
}
g
.
setColor
(
Color
.
GREEN
);
g
.
fillRect
(
koszyk
,
getHeight
()-
WYSOKOSC_KOSZYKA
,
SZEROKOSC_KOSZYKA
,
WYSOKOSC_KOSZYKA
);
}
// tresc tej metody bedzie wykonywana cyklicznie co okreslony czas przez timera
void
jedenKrok
()
{
Set
<
Jablko
>
jablkaDoUsuniecia
=
new
HashSet
<>();
for
(
Jablko
jablko
:
jablka
)
{
jablko
.
opusc
(
skok
);
if
(
jablko
.
getY
()
>
this
.
getHeight
()-
WYSOKOSC_KOSZYKA
)
{
if
(
koszyk
<=
jablko
.
getX
()
&&
jablko
.
getX
()
<
koszyk
+
SZEROKOSC_KOSZYKA
)
{
ileZlapanych
++;
}
else
{
ileZgubionych
++;
}
jablkaDoUsuniecia
.
add
(
jablko
);
}
}
jablka
.
removeAll
(
jablkaDoUsuniecia
);
if
(
random
.
nextDouble
()
<
prawdopodobienstwoNowegoJablka
)
{
int
x
=
random
.
nextInt
(
this
.
getWidth
()
-
Jablko
.
SREDNICA
);
int
y
=
0
;
...
...
@@ -48,15 +56,6 @@ public class Plansza extends JPanel {
this
.
repaint
();
}
public
int
getPauza
()
{
return
pauza
;
}
public
void
setPauza
(
int
pauza
)
{
this
.
pauza
=
pauza
;
timer
.
setDelay
(
pauza
);
}
public
int
getSkok
()
{
return
skok
;
}
...
...
@@ -73,5 +72,23 @@ public class Plansza extends JPanel {
this
.
prawdopodobienstwoNowegoJablka
=
prawdopodobienstwoNowegoJablka
;
}
public
void
ustawKoszyk
(
int
pozycjaMyszy
)
{
int
nowaPozycja
=
pozycjaMyszy
-
SZEROKOSC_KOSZYKA
/
2
;
if
(
nowaPozycja
<
0
)
{
nowaPozycja
=
0
;
}
if
(
nowaPozycja
>
getWidth
()
-
SZEROKOSC_KOSZYKA
)
{
nowaPozycja
=
getWidth
()
-
SZEROKOSC_KOSZYKA
;
}
koszyk
=
nowaPozycja
;
}
public
int
getIleZlapanych
()
{
return
ileZlapanych
;
}
public
int
getIleZgubionych
()
{
return
ileZgubionych
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment