Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
JTankTrouble
Project
Project
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
9831111
JTankTrouble
Commits
0f8b4477
Commit
0f8b4477
authored
Aug 01, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
77f5bab3
2b3e1890
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
204 additions
and
122 deletions
+204
-122
CreateNewGameFrame.java
src/CreateNewGameFrame.java
+2
-3
GameLoop.java
src/GameLoop.java
+2
-1
GameState.java
src/GameState.java
+86
-68
LoginFrame.java
src/LoginFrame.java
+36
-37
MainFrame.java
src/MainFrame.java
+4
-7
OnlineModeFrame.java
src/OnlineModeFrame.java
+1
-2
SettingFrame.java
src/SettingFrame.java
+5
-4
temp.java
src/temp.java
+68
-0
No files found.
src/CreateNewGameFrame.java
View file @
0f8b4477
...
...
@@ -8,6 +8,7 @@ import java.io.File;
import
java.io.FileWriter
;
public
class
CreateNewGameFrame
extends
JFrame
{
private
JPanel
settingPanel
;
private
JPanel
gameDetailsPanel
;
private
JPanel
optionPanel
;
...
...
@@ -49,7 +50,7 @@ public class CreateNewGameFrame extends JFrame {
destructibleWallSlider
=
new
JSlider
(
10
,
100
,
20
);
sliderAndIcon
(
tankHealthSlider
,
"pictures/tankHealth.png"
);
sliderAndIcon
(
shotDamageSlider
,
"pictures/shotDamage.png"
);
sliderAndIcon
(
destructibleWallSlider
,
"pictures/DestructibleWall.png"
);
sliderAndIcon
(
destructibleWallSlider
,
"pictures/DestructibleWall.png"
);
add
(
settingPanel
);
settingPanel
.
add
(
gameDetailsPanel
,
BorderLayout
.
CENTER
);
...
...
@@ -136,6 +137,4 @@ public class CreateNewGameFrame extends JFrame {
ex
.
printStackTrace
();
}
}
}
src/GameLoop.java
View file @
0f8b4477
...
...
@@ -71,7 +71,8 @@ public class GameLoop implements Runnable {
long
delay
=
(
1000
/
FPS
)
-
(
System
.
currentTimeMillis
()
-
start
);
if
(
delay
>
0
)
Thread
.
sleep
(
delay
);
}
catch
(
InterruptedException
|
IOException
|
AWTException
ex
)
{
}
catch
(
Exception
ee
)
{
ee
.
printStackTrace
();
}
}
try
{
...
...
src/GameState.java
View file @
0f8b4477
...
...
@@ -32,10 +32,6 @@ public class GameState {
private
boolean
one
=
false
;
private
boolean
two
=
false
;
private
boolean
three
=
false
;
private
int
step
=
0
;
boolean
PermissionUp
=
true
;
boolean
PermissionDown
=
true
;
boolean
check
=
true
;
public
GameState
(
int
num
)
{
...
...
@@ -84,83 +80,114 @@ public class GameState {
if
(
keyUP
)
{
PermissionUp
=
true
;
move
(+
5
);
}
if
(
keyDOWN
)
{
move
(-
5
);
}
if
(
keyLEFT
)
rotateAmount
-=
15
;
if
(
keyRIGHT
)
rotateAmount
+=
15
;
locX
=
Math
.
max
(
locX
,
40
);
locX
=
Math
.
min
(
locX
,
20
+
(((
Controller
.
col
-
1
)
/
2
)
*
50
)
+
(((
Controller
.
col
-
1
)
/
2
)
+
1
)
*
5
-
25
);
locY
=
Math
.
max
(
locY
,
70
);
locY
=
Math
.
min
(
locY
,
50
+
((
Controller
.
row
-
1
)
/
2
)
*
50
+
(((
Controller
.
row
-
1
)
/
2
)
+
1
)
*
5
-
25
);
}
public
Wall
verticalWallCollision
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
//&&
// ((rotateAmount == 0 && locX < wall.getX()) || ((rotateAmount == 180 || rotateAmount == -180) && locX > wall.getX()))
PermissionUp
=
false
;
break
;
return
wall
;
}
}
}
return
null
;
}
public
Wall
horizontalWallCollision
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
// &&
// (((rotateAmount == +90 || rotateAmount == -270) && locY < wall.getY()) || (((rotateAmount == -90 || rotateAmount == -270) && locY > wall.getY())))
PermissionUp
=
false
;
break
;
}
return
wall
;
}
}
if
(
PermissionUp
)
move
(+
5
);
for
(
Wall
wall
:
Controller
.
walls
)
if
(!
PermissionDown
&&
(!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
)))
||
!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
)))))
{
move
(+
5
);
break
;
}
return
null
;
}
if
(
keyDOWN
)
{
PermissionDown
=
true
;
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
//&&
// ((((rotateAmount == 0) || locX >= wall.getX())) || (((rotateAmount == -180 || rotateAmount == 180) && locX <= wall.getX())))
PermissionDown
=
false
;
break
;
public
boolean
isMoveAllowed
(
int
px
)
{
if
(
verticalWallCollision
()
!=
null
)
{
if
(
verticalWallCollision
().
getX
()
>
locX
&&
px
>
0
)
{
if
((
rotateAmount
<=
90
&&
rotateAmount
>=
-
90
)
||
(
rotateAmount
<=
-
270
&&
rotateAmount
>
-
360
)
||
(
rotateAmount
>=
270
&&
rotateAmount
<
360
))
{
return
false
;
}
else
return
true
;
}
if
(
verticalWallCollision
().
getX
()
<
locX
&&
px
<
0
)
{
if
((
rotateAmount
<=
90
&&
rotateAmount
>=
-
90
)
||
(
rotateAmount
<=
-
270
&&
rotateAmount
>
-
360
)
||
(
rotateAmount
>=
270
&&
rotateAmount
<
360
))
{
return
false
;
}
else
return
true
;
}
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
// &&
// (((rotateAmount == -90 || rotateAmount == 270) && locY<wall.getY()))|| (((rotateAmount==90||rotateAmount==-270)&& locY>wall.getY()))
PermissionDown
=
false
;
break
;
}
if
(
verticalWallCollision
().
getX
()
>
locX
&&
px
<
0
)
{
if
((
rotateAmount
>=
90
&&
rotateAmount
<=
270
)
||
(
rotateAmount
<=
-
90
&&
rotateAmount
>=
-
270
))
{
return
false
;
}
else
return
true
;
}
if
(
verticalWallCollision
().
getX
()
<
locX
&&
px
>
0
)
{
if
((
rotateAmount
>=
90
||
rotateAmount
<=
270
)
||
(
rotateAmount
<=
-
90
&&
rotateAmount
>=
-
270
))
{
return
false
;
}
else
return
true
;
}
if
(
PermissionDown
)
move
(-
5
);
for
(
Wall
wall
:
Controller
.
walls
)
if
(!
PermissionUp
&&
(!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
)))
||
!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
)))))
{
move
(-
5
);
break
;
}
// }
if
(
horizontalWallCollision
()
!=
null
)
{
if
(
horizontalWallCollision
().
getY
()
>
locY
&&
px
>
0
)
{
if
((
rotateAmount
<=
180
&&
rotateAmount
>=
0
)
||
(
rotateAmount
<=
-
180
&&
rotateAmount
>
-
360
))
{
System
.
out
.
println
(
"1"
);
return
false
;
}
else
return
true
;
}
if
(
horizontalWallCollision
().
getY
()
<
locY
&&
px
<
0
)
{
if
((
rotateAmount
<=
180
&&
rotateAmount
>=
0
)
||
(
rotateAmount
<=
-
180
&&
rotateAmount
>
-
360
))
{
System
.
out
.
println
(
"2"
);
return
false
;
}
else
return
true
;
}
if
(
horizontalWallCollision
().
getY
()
<
locY
&&
px
>
0
)
{
if
((
rotateAmount
>=
-
180
&&
rotateAmount
<=
0
)
||
(
rotateAmount
>=
180
&&
rotateAmount
<
360
))
{
System
.
out
.
println
(
"3"
);
if
(
keyLEFT
)
rotateAmount
-=
15
;
if
(
keyRIGHT
)
rotateAmount
+=
15
;
return
false
;
}
else
return
true
;
}
if
(
horizontalWallCollision
().
getY
()
>
locY
&&
px
<
0
)
{
if
((
rotateAmount
>=
-
180
&&
rotateAmount
<=
0
)
||
(
rotateAmount
>=
180
&&
rotateAmount
<
360
))
{
System
.
out
.
println
(
"4"
);
locX
=
Math
.
max
(
locX
,
40
);
locX
=
Math
.
min
(
locX
,
20
+
(((
Controller
.
col
-
1
)
/
2
)
*
50
)
+
(((
Controller
.
col
-
1
)
/
2
)
+
1
)
*
5
-
25
);
return
false
;
}
else
return
true
;
}
locY
=
Math
.
max
(
locY
,
70
);
locY
=
Math
.
min
(
locY
,
50
+
((
Controller
.
row
-
1
)
/
2
)
*
50
+
(((
Controller
.
row
-
1
)
/
2
)
+
1
)
*
5
-
25
)
;
}
return
true
;
}
public
void
move
(
int
px
)
{
double
d
;
if
(!
isMoveAllowed
(
px
))
px
=
0
;
if
(
rotateAmount
==
0
)
locX
+=
px
;
if
(
rotateAmount
==
90
||
rotateAmount
==
-
270
)
locY
+=
px
;
if
(
rotateAmount
==
-
90
||
rotateAmount
==
270
)
locY
-=
px
;
...
...
@@ -214,15 +241,6 @@ public class GameState {
}
public
void
checkWall
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getX
()
==
locX
+
5
||
wall
.
getY
()
==
locY
+
5
)
{
keyDOWN
=
false
;
}
else
if
(
wall
.
getX
()
==
locX
-
5
||
wall
.
getY
()
==
locY
-
5
)
{
keyUP
=
false
;
}
}
}
public
KeyListener
getKeyListener
()
{
return
keyHandler
;
...
...
src/LoginFrame.java
View file @
0f8b4477
...
...
@@ -35,20 +35,6 @@ public class LoginFrame extends JFrame {
}
public
void
initInformationPanel
()
{
informationPanel
=
new
JPanel
();
informationPanel
.
setOpaque
(
true
);
informationPanel
.
setBorder
(
new
LineBorder
(
Color
.
DARK_GRAY
));
informationPanel
.
setLayout
(
new
GridLayout
(
3
,
1
));
informationPanel
.
add
(
userName
);
informationPanel
.
add
(
passwordField
);
informationPanel
.
add
(
remindMe
);
add
(
informationPanel
,
BorderLayout
.
CENTER
);
}
public
void
initLoginFrame
()
{
tankPhoto
=
new
ImageIcon
(
"gifFiles/gif.gif"
);
...
...
@@ -81,6 +67,20 @@ public class LoginFrame extends JFrame {
}
public
void
initInformationPanel
()
{
informationPanel
=
new
JPanel
();
informationPanel
.
setOpaque
(
true
);
informationPanel
.
setBorder
(
new
LineBorder
(
Color
.
DARK_GRAY
));
informationPanel
.
setLayout
(
new
GridLayout
(
3
,
1
));
informationPanel
.
add
(
userName
);
informationPanel
.
add
(
passwordField
);
informationPanel
.
add
(
remindMe
);
add
(
informationPanel
,
BorderLayout
.
CENTER
);
}
public
void
initRemindMe
()
{
File
accounts
=
new
File
(
"Accounts.txt"
);
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
accounts
)))
{
...
...
@@ -99,6 +99,28 @@ public class LoginFrame extends JFrame {
}
}
class
SignUpAction
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
File
accounts
=
new
File
(
"Accounts.txt"
);
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
accounts
)))
{
String
account
=
""
;
while
(
scanner
.
hasNextLine
())
{
account
=
scanner
.
nextLine
()
+
"\n"
;
}
if
(
account
.
contains
(
userName
.
getText
()))
{
JFrame
userFound
=
new
JFrame
();
JOptionPane
.
showMessageDialog
(
userFound
,
"This User already exists ! "
,
""
,
JOptionPane
.
ERROR_MESSAGE
);
}
else
{
signUpUser
(
accounts
);
}
}
catch
(
Exception
ee
)
{
ee
.
printStackTrace
();
}
}
}
public
void
signUpUser
(
File
accounts
)
{
try
(
FileWriter
fileWriter
=
new
FileWriter
(
accounts
,
true
))
{
fileWriter
.
write
(
userName
.
getText
()
+
" "
+
passwordField
.
getText
()
+
" "
+
remindMe
.
isSelected
()
+
" 0 0 0 0 0 "
+
"\n"
);
...
...
@@ -146,27 +168,4 @@ public class LoginFrame extends JFrame {
}
}
class
SignUpAction
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
File
accounts
=
new
File
(
"Accounts.txt"
);
try
(
Scanner
scanner
=
new
Scanner
(
new
FileReader
(
accounts
)))
{
String
account
=
""
;
while
(
scanner
.
hasNextLine
())
{
account
=
scanner
.
nextLine
()
+
"\n"
;
}
if
(
account
.
contains
(
userName
.
getText
()))
{
JFrame
userFound
=
new
JFrame
();
JOptionPane
.
showMessageDialog
(
userFound
,
"This User already exists ! "
,
""
,
JOptionPane
.
ERROR_MESSAGE
);
}
else
{
signUpUser
(
accounts
);
}
}
catch
(
Exception
ee
)
{
ee
.
printStackTrace
();
}
}
}
}
src/MainFrame.java
View file @
0f8b4477
...
...
@@ -106,8 +106,7 @@ public class MainFrame extends JFrame {
}
}
class
OfflineModeAction
implements
ActionListener
{
class
OfflineModeAction
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
@@ -115,7 +114,7 @@ public class MainFrame extends JFrame {
JFrame
dialogFrame
=
new
JFrame
(
"Change settings "
);
dialogFrame
.
setResizable
(
false
);
dialogFrame
.
setLayout
(
new
FlowLayout
());
dialogFrame
.
setBounds
(
700
,
450
,
300
,
85
);
dialogFrame
.
setBounds
(
700
,
450
,
300
,
85
);
JLabel
settingLabel
=
new
JLabel
(
"Do you want to play with current setting ?"
);
dialogFrame
.
add
(
settingLabel
);
...
...
@@ -143,10 +142,8 @@ public class MainFrame extends JFrame {
dialogFrame
.
setVisible
(
true
);
}
}
class
OnlineModeAction
implements
ActionListener
{
class
OnlineModeAction
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
...
...
src/OnlineModeFrame.java
View file @
0f8b4477
...
...
@@ -8,6 +8,7 @@ import java.io.FileReader;
import
java.util.Scanner
;
public
class
OnlineModeFrame
extends
JFrame
{
private
JComboBox
serverBox
;
private
JPanel
serverChoosePanel
;
private
JPanel
gamesPanel
;
...
...
@@ -98,6 +99,4 @@ public class OnlineModeFrame extends JFrame {
new
CreateNewGameFrame
(
"Make A New Game"
);
}
}
}
src/SettingFrame.java
View file @
0f8b4477
...
...
@@ -29,6 +29,7 @@ public class SettingFrame extends JFrame {
setVisible
(
true
);
}
public
void
initUserInformationPanel
()
{
userInformationPanel
=
new
JPanel
();
...
...
@@ -68,7 +69,9 @@ public class SettingFrame extends JFrame {
add
(
userInformationPanel
);
}
public
void
textAndLabel
(
String
pngFile
,
String
textField
)
{
ImageIcon
icon
=
new
ImageIcon
(
pngFile
);
...
...
@@ -84,6 +87,7 @@ public class SettingFrame extends JFrame {
userInformationPanel
.
add
(
text
);
}
public
void
initSettingPanel
()
{
settingPanel
=
new
JPanel
();
...
...
@@ -104,6 +108,7 @@ public class SettingFrame extends JFrame {
settingPanel
.
add
(
gameDetailsPanel
,
BorderLayout
.
NORTH
);
settingPanel
.
add
(
serverPanel
,
BorderLayout
.
CENTER
);
}
public
void
initServerPanel
()
{
JComboBox
serverBox
=
new
JComboBox
();
serverBox
.
addItem
(
"Server 1"
);
...
...
@@ -138,8 +143,4 @@ public class SettingFrame extends JFrame {
gameDetailsPanel
.
add
(
slider
);
}
}
src/temp.java
0 → 100644
View file @
0f8b4477
public
class
temp
{
// if(Math.abs((locX+5-wall.getX()))<18 && Math.abs((locY-wall.getY()))<18){
// System.out.println("4");
// Permission = false;
// break;
// }
//if (locX + 5 < wall.getX() && locY + 5 < wall.getY() && locX - 5 < wall.getX() && locY - 5 < wall.getY())
// {
// System.out.println("1111");
// if (Math.abs(locY - wall.getY()) <= 25 && Math.abs(wall.getX() - locX) <= 25 && (rotateAmount == 90 || rotateAmount == -270)) {
// System.out.println("1");
// Permission = false;
// break;
// }
// if (Math.abs((locX - wall.getX())) <= 25 && Math.abs((locY-wall.getY()))<=25 && rotateAmount == 0) {
// System.out.println("2");
// Permission = false;
// break;
// }
// if ( Math.abs(locX - wall.getX()) <=30 && Math.abs(locY-wall.getY())<=75 && (rotateAmount == -180 || rotateAmount == 180)) {
// System.out.println("3");
// Permission = false;
// break;
// }
// if((rotateAmount==-270||rotateAmount==90)&& Math.abs((locX-wall.getX()))<=25 && Math.abs(locY-wall.getY())<=25){
// System.out.println("4");
// Permission = false;
// break;
// }
// }
// if (!robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY)) ||
// robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY))) {
// //System.out.println((locX + 5, locY + 5));
// // System.out.println(robot.getPixelColor(locX , locY ));
// System.out.println("4");
// Permission = false;
// break;
// }
// System.out.println("na");
// if(Controller.g2d.hit( wall, (Shape) Controller.taken,false)){
// System.out.println("4");
// Permission = false;
// break;
// }
// boolean Permission = true;
// for (Wall wall : Controller.walls) {
// if ((wall.getX() == locX + 5 || wall.getX() == locX + 5 + 5)) {
// Permission = false;
// break;
// }
// }
// Robot robot = new Robot();
// if (!robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY)) ||
// robot.getPixelColor(locX + 5, locY + 5).equals(robot.getPixelColor(locX,locY))) {
// System.out.println("4");
// Permission = false;
// break;
// }
}
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