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
f73fbc75
Commit
f73fbc75
authored
Jul 28, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Color checking feature(test).
parent
66ea0959
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
311 additions
and
197 deletions
+311
-197
GameState.java
src/GameState.java
+311
-197
No files found.
src/GameState.java
View file @
f73fbc75
/*** In The Name of Allah ***/
/*** In The Name of Allah ***/
import
org.w3c.dom.css.RGBColor
;
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
;
...
@@ -21,15 +23,18 @@ public class GameState {
...
@@ -21,15 +23,18 @@ public class GameState {
public
int
locX
,
locY
,
diam
;
public
int
locX
,
locY
,
diam
;
public
boolean
gameOver
;
public
boolean
gameOver
;
private
boolean
keyUP
,
keyDOWN
,
keyRIGHT
,
keyLEFT
;
private
boolean
keyUP
,
keyDOWN
,
keyRIGHT
,
keyLEFT
;
private
boolean
mousePress
;
private
boolean
mousePress
;
private
int
mouseX
,
mouseY
;
private
int
mouseX
,
mouseY
;
private
KeyHandler
keyHandler
;
private
KeyHandler
keyHandler
;
private
MouseHandler
mouseHandler
;
private
MouseHandler
mouseHandler
;
public
double
rotateAmount
;
public
double
rotateAmount
;
private
boolean
one
=
false
;
private
boolean
two
=
false
;
private
boolean
three
=
false
;
public
GameState
(
)
{
public
GameState
(
int
num
)
{
locX
=
100
;
locX
=
100
;
locY
=
100
;
locY
=
100
;
diam
=
42
;
diam
=
42
;
...
@@ -45,37 +50,62 @@ public class GameState {
...
@@ -45,37 +50,62 @@ public class GameState {
mouseX
=
0
;
mouseX
=
0
;
mouseY
=
0
;
mouseY
=
0
;
//
//
if
(
num
==
1
)
{
one
=
true
;
}
if
(
num
==
2
)
{
two
=
true
;
}
if
(
num
==
3
)
{
three
=
true
;
}
keyHandler
=
new
KeyHandler
();
keyHandler
=
new
KeyHandler
();
mouseHandler
=
new
MouseHandler
();
mouseHandler
=
new
MouseHandler
();
}
}
public
Rectangle
getBounds
(
int
locX
,
int
locY
){
return
new
Rectangle
(
locX
,
locY
,
25
,
25
);
}
/**
/**
* The method which updates the game state.
* The method which updates the game state.
*/
*/
public
void
update
()
{
public
void
update
()
throws
AWTException
{
if
(
rotateAmount
>=
360
||
rotateAmount
<=
-
360
)
rotateAmount
=
0
;
if
(
rotateAmount
>=
360
||
rotateAmount
<=
-
360
)
rotateAmount
=
0
;
if
(
mousePress
)
{
if
(
mousePress
)
{
locY
=
mouseY
-
diam
/
2
;
locY
=
mouseY
-
diam
/
2
;
locX
=
mouseX
-
diam
/
2
;
locX
=
mouseX
-
diam
/
2
;
}
}
if
(
keyUP
)
{
if
(
keyUP
)
{
// boolean Permission=true;
// for (Wall wall : Controller.walls) {
// if(wall.intersects(getBounds(locX+5,locY+5))){
// System.out.println("4");
// Permission = false;
// break;
// }
// }
// if (Permission)
move
(+
5
);
move
(+
5
);
}
}
if
(
keyDOWN
)
{
if
(
keyDOWN
)
{
boolean
Permission
=
true
;
move
(-
5
);
move
(-
5
);
}
}
if
(
keyLEFT
)
if
(
keyLEFT
)
rotateAmount
-=
10
;
rotateAmount
-=
15
;
if
(
keyRIGHT
)
if
(
keyRIGHT
)
rotateAmount
+=
10
;
rotateAmount
+=
15
;
locX
=
Math
.
max
(
locX
,
42
);
locX
=
Math
.
max
(
locX
,
42
);
locX
=
Math
.
min
(
locX
,
GameFrame
.
GAME_WIDTH
-
diam
-
160
);
locX
=
Math
.
min
(
locX
,
GameFrame
.
GAME_WIDTH
-
diam
-
42
);
locY
=
Math
.
max
(
locY
,
5
0
);
locY
=
Math
.
max
(
locY
,
7
0
);
locY
=
Math
.
min
(
locY
,
GameFrame
.
GAME_HEIGHT
-
diam
-
1
60
);
locY
=
Math
.
min
(
locY
,
((
Controller
.
row
-
1
)/
2
)*
50
+
60
);
}
}
public
void
move
(
int
px
)
{
public
void
move
(
int
px
)
{
...
@@ -134,6 +164,16 @@ public class GameState {
...
@@ -134,6 +164,16 @@ 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
()
{
public
KeyListener
getKeyListener
()
{
return
keyHandler
;
return
keyHandler
;
}
}
...
@@ -154,6 +194,7 @@ public class GameState {
...
@@ -154,6 +194,7 @@ public class GameState {
@Override
@Override
public
void
keyPressed
(
KeyEvent
e
)
{
public
void
keyPressed
(
KeyEvent
e
)
{
if
(
one
)
{
switch
(
e
.
getKeyCode
())
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_UP
:
case
KeyEvent
.
VK_UP
:
keyUP
=
true
;
keyUP
=
true
;
...
@@ -172,9 +213,49 @@ public class GameState {
...
@@ -172,9 +213,49 @@ public class GameState {
break
;
break
;
}
}
}
}
if
(
two
)
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_W
:
keyUP
=
true
;
break
;
case
KeyEvent
.
VK_S
:
keyDOWN
=
true
;
break
;
case
KeyEvent
.
VK_A
:
keyLEFT
=
true
;
break
;
case
KeyEvent
.
VK_D
:
keyRIGHT
=
true
;
break
;
case
KeyEvent
.
VK_ESCAPE
:
gameOver
=
true
;
break
;
}
}
if
(
three
)
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_I
:
keyUP
=
true
;
break
;
case
KeyEvent
.
VK_K
:
keyDOWN
=
true
;
break
;
case
KeyEvent
.
VK_J
:
keyLEFT
=
true
;
break
;
case
KeyEvent
.
VK_L
:
keyRIGHT
=
true
;
break
;
case
KeyEvent
.
VK_ESCAPE
:
gameOver
=
true
;
break
;
}
}
}
@Override
@Override
public
void
keyReleased
(
KeyEvent
e
)
{
public
void
keyReleased
(
KeyEvent
e
)
{
if
(
one
)
{
switch
(
e
.
getKeyCode
())
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_UP
:
case
KeyEvent
.
VK_UP
:
keyUP
=
false
;
keyUP
=
false
;
...
@@ -190,6 +271,39 @@ public class GameState {
...
@@ -190,6 +271,39 @@ public class GameState {
break
;
break
;
}
}
}
}
if
(
two
)
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_W
:
keyUP
=
false
;
break
;
case
KeyEvent
.
VK_S
:
keyDOWN
=
false
;
break
;
case
KeyEvent
.
VK_A
:
keyLEFT
=
false
;
break
;
case
KeyEvent
.
VK_D
:
keyRIGHT
=
false
;
break
;
}
}
if
(
three
)
{
switch
(
e
.
getKeyCode
())
{
case
KeyEvent
.
VK_I
:
keyUP
=
false
;
break
;
case
KeyEvent
.
VK_K
:
keyDOWN
=
false
;
break
;
case
KeyEvent
.
VK_J
:
keyLEFT
=
false
;
break
;
case
KeyEvent
.
VK_L
:
keyRIGHT
=
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