Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
ParallelPathfinding
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Enes Herguel
ParallelPathfinding
Commits
82beabdc
Commit
82beabdc
authored
4 years ago
by
NET-D3v3l0p3r
Browse files
Options
Downloads
Patches
Plain Diff
Input ready
parent
48e82604
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/algorithm/ParallelPathfinder.java
+14
-1
14 additions, 1 deletion
src/algorithm/ParallelPathfinder.java
src/window/Game.java
+40
-0
40 additions, 0 deletions
src/window/Game.java
src/window/MainWindow.java
+10
-2
10 additions, 2 deletions
src/window/MainWindow.java
with
64 additions
and
3 deletions
src/algorithm/ParallelPathfinder.java
+
14
−
1
View file @
82beabdc
...
@@ -8,7 +8,17 @@ import java.awt.*;
...
@@ -8,7 +8,17 @@ import java.awt.*;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
public
class
ParallelPathfinder
{
public
class
ParallelPathfinder
{
private
int
lastDestX
;
private
int
lastDestY
;
private
void
flood
(
int
destX
,
int
destY
)
{
private
void
flood
(
int
destX
,
int
destY
)
{
lastDestX
=
destX
;
lastDestY
=
destY
;
System
.
out
.
println
(
"[*] Flooding..."
);
SharedRessources
SharedRessources
.
getInstance
().
add
(
new
Explorer
(
destX
-
1
,
destY
,
1
,
Explorer
.
Direction
.
West
));
.
getInstance
().
add
(
new
Explorer
(
destX
-
1
,
destY
,
1
,
Explorer
.
Direction
.
West
));
SharedRessources
SharedRessources
...
@@ -31,6 +41,8 @@ public class ParallelPathfinder {
...
@@ -31,6 +41,8 @@ public class ParallelPathfinder {
}
}
public
ArrayList
<
Point
>
calculatePath
(
int
startX
,
int
startY
,
int
destX
,
int
destY
)
{
public
ArrayList
<
Point
>
calculatePath
(
int
startX
,
int
startY
,
int
destX
,
int
destY
)
{
if
(
destX
!=
lastDestX
||
destY
!=
lastDestY
)
flood
(
destX
,
destY
);
flood
(
destX
,
destY
);
ArrayList
<
Point
>
path
ArrayList
<
Point
>
path
...
@@ -59,6 +71,7 @@ public class ParallelPathfinder {
...
@@ -59,6 +71,7 @@ public class ParallelPathfinder {
return
path
;
return
path
;
}
}
public
void
draw
(
Graphics
g
)
{
public
void
draw
(
Graphics
g
)
{
...
...
This diff is collapsed.
Click to expand it.
src/window/Game.java
+
40
−
0
View file @
82beabdc
...
@@ -4,6 +4,8 @@ import javax.swing.*;
...
@@ -4,6 +4,8 @@ import javax.swing.*;
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.event.KeyAdapter
;
import
java.awt.event.KeyAdapter
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.MouseAdapter
;
import
java.awt.event.MouseEvent
;
public
abstract
class
Game
extends
JFrame
{
public
abstract
class
Game
extends
JFrame
{
...
@@ -13,12 +15,16 @@ public abstract class Game extends JFrame {
...
@@ -13,12 +15,16 @@ public abstract class Game extends JFrame {
private
boolean
running
;
private
boolean
running
;
private
boolean
[]
pressedKeyMap
;
private
boolean
[]
pressedKeyMap
;
private
boolean
[]
pressedMouseKeyMap
;
private
int
mX
,
mY
;
public
Game
(
String
title
,
int
w
,
int
h
)
{
public
Game
(
String
title
,
int
w
,
int
h
)
{
super
(
title
);
super
(
title
);
this
.
setSize
(
w
,
h
);
this
.
setSize
(
w
,
h
);
pressedKeyMap
=
new
boolean
[
1024
];
pressedKeyMap
=
new
boolean
[
1024
];
pressedMouseKeyMap
=
new
boolean
[
4
];
this
.
windowThread
=
new
Thread
(()
->
{
this
.
windowThread
=
new
Thread
(()
->
{
loadGame
();
loadGame
();
...
@@ -55,6 +61,24 @@ public abstract class Game extends JFrame {
...
@@ -55,6 +61,24 @@ public abstract class Game extends JFrame {
pressedKeyMap
[
e
.
getKeyCode
()]
=
false
;
pressedKeyMap
[
e
.
getKeyCode
()]
=
false
;
}
}
});
this
.
addMouseListener
(
new
MouseAdapter
()
{
@Override
public
void
mousePressed
(
MouseEvent
e
)
{
super
.
mousePressed
(
e
);
mX
=
e
.
getX
();
mY
=
e
.
getY
();
pressedMouseKeyMap
[
e
.
getButton
()]
=
true
;
}
@Override
public
void
mouseReleased
(
MouseEvent
e
)
{
super
.
mouseReleased
(
e
);
pressedMouseKeyMap
[
e
.
getButton
()]
=
false
;
}
});
});
this
.
setDefaultCloseOperation
(
EXIT_ON_CLOSE
);
this
.
setDefaultCloseOperation
(
EXIT_ON_CLOSE
);
...
@@ -70,6 +94,22 @@ public abstract class Game extends JFrame {
...
@@ -70,6 +94,22 @@ public abstract class Game extends JFrame {
return
!
isKeyDown
(
key
);
return
!
isKeyDown
(
key
);
}
}
public
boolean
isMouseKeyDown
(
int
key
)
{
return
pressedMouseKeyMap
[
key
];
}
public
boolean
isMouseKeyUp
(
int
key
)
{
return
!
isMouseKeyDown
(
key
);
}
public
int
getMouseX
()
{
return
mX
;
}
public
int
getMouseY
()
{
return
mY
;
}
public
final
void
run
()
{
public
final
void
run
()
{
this
.
setVisible
(
true
);
this
.
setVisible
(
true
);
this
.
running
=
true
;
this
.
running
=
true
;
...
...
This diff is collapsed.
Click to expand it.
src/window/MainWindow.java
+
10
−
2
View file @
82beabdc
...
@@ -7,6 +7,7 @@ import parallel.SharedRessources;
...
@@ -7,6 +7,7 @@ import parallel.SharedRessources;
import
javax.imageio.ImageIO
;
import
javax.imageio.ImageIO
;
import
java.awt.*
;
import
java.awt.*
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.MouseEvent
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -33,12 +34,19 @@ public class MainWindow extends Game {
...
@@ -33,12 +34,19 @@ public class MainWindow extends Game {
=
new
ParallelPathfinder
();
=
new
ParallelPathfinder
();
}
}
private
boolean
pressed
;
@Override
@Override
public
void
updateGame
()
{
public
void
updateGame
()
{
if
(
isKeyDown
(
KeyEvent
.
VK_ENTER
))
if
(
isMouseKeyDown
(
MouseEvent
.
BUTTON1
)
&&
!
pressed
)
{
pts
=
parallelPathfinder
.
calculatePath
(
8
,
5
,
1590
,
800
);
pts
=
parallelPathfinder
.
calculatePath
(
this
.
getMouseX
(),
this
.
getMouseY
(),
1590
,
800
);
pressed
=
true
;
}
if
(
isMouseKeyUp
(
MouseEvent
.
BUTTON1
))
pressed
=
false
;
}
}
@Override
@Override
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment