Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
police
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
9611046
police
Commits
1b0bf0d9
Commit
1b0bf0d9
authored
Apr 21, 2019
by
9611046
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adds Move class to avoid duplicative codes
parent
8dd280cc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
0 deletions
+100
-0
Move.java
src/Move.java
+100
-0
No files found.
src/Move.java
0 → 100644
View file @
1b0bf0d9
import
java.util.Random
;
public
class
Move
{
private
int
x
;
private
int
y
;
private
Land
moveLand
;
public
Move
(
int
x
,
int
y
,
Land
land
){
this
.
x
=
x
;
this
.
y
=
y
;
moveLand
=
land
;
}
public
void
moveXY
(){
Random
rand
=
new
Random
();
int
a
=
rand
.
nextInt
(
8
);
switch
(
a
)
{
case
0
:
//Right
if
(
y
+
1
<
moveLand
.
getLength
())
{
y
+=
1
;
break
;
}
else
moveXY
();
case
1
:
//Left
if
(
y
>
0
)
{
y
-=
1
;
break
;
}
else
moveXY
();
case
2
:
//Up
if
(
x
>
0
)
{
x
-=
1
;
break
;
}
else
moveXY
();
case
3
:
//Down
if
(
x
+
1
<
moveLand
.
getWidth
())
{
x
+=
1
;
break
;
}
else
moveXY
();
case
4
:
//North East
if
((
x
>
0
)
&&
(
y
+
1
<
moveLand
.
getLength
()))
{
x
-=
1
;
y
+=
1
;
break
;
}
else
moveXY
();
case
5
:
//North west
if
(
x
>
0
&&
y
>
0
)
{
y
-=
1
;
x
-=
1
;
break
;
}
else
moveXY
();
case
6
:
//Southeast
if
((
x
+
1
<
moveLand
.
getWidth
())
&&
(
y
+
1
<
moveLand
.
getLength
()))
{
y
+=
1
;
x
+=
1
;
break
;
}
else
moveXY
();
case
7
:
//Southwest
if
((
x
+
1
<
moveLand
.
getWidth
())
&&
(
y
>
0
))
{
x
+=
1
;
y
-=
1
;
break
;
}
else
moveXY
();
}
}
public
int
getX
(){
return
x
;
}
public
int
getY
(){
return
y
;
}
}
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