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
9731077
Police
Commits
a0959836
Commit
a0959836
authored
Apr 20, 2019
by
9731077
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
one method removed + add change field method
parent
71952f2f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
14 deletions
+43
-14
Field.java
Field.java
+43
-14
No files found.
Field.java
View file @
a0959836
...
...
@@ -3,17 +3,19 @@ import java.util.Random;
//string to
public
class
Field
{
private
int
m
,
n
;
private
String
[][]
fieldShape
;
ArrayList
<
Police
>
polices
;
ArrayList
<
Robber
>
robberPosotion
;
private
int
m
;
private
int
n
;
private
ArrayList
<
Police
>
polices
=
new
ArrayList
<
Police
>();
private
Robber
Robber
;
public
String
[][]
fieldShape
;
public
Field
(
int
m
,
int
n
)
{
polices
=
new
ArrayList
<>();
robberPosotion
=
new
ArrayList
<>();
this
.
m
=
m
;
this
.
n
=
n
;
fieldShape
=
new
String
[
m
][
n
];
for
(
int
i
=
0
;
i
<
m
;
i
++)
for
(
int
j
=
0
;
j
<
n
;
j
++)
fieldShape
[
i
][
j
]
=
"-"
;
}
public
int
getM
()
{
...
...
@@ -43,8 +45,7 @@ public class Field {
fieldShape
[
tmpX
][
tmpY
]
=
"P"
;
polices
.
add
(
p
);
System
.
out
.
println
(
"First police created"
);
}
else
{
}
else
{
for
(
Police
police
:
polices
)
{
if
(
police
.
getX
()
==
tmpX
&&
police
.
getY
()
==
tmpY
)
{
i
--;
...
...
@@ -52,20 +53,19 @@ public class Field {
break
;
}
}
if
(
cnt
==
0
){
if
(
cnt
==
0
)
{
Police
p
=
new
Police
(
tmpX
,
tmpY
);
fieldShape
[
tmpX
][
tmpY
]
=
"P"
;
polices
.
add
(
p
);
System
.
out
.
println
(
i
+
"th police created"
);
}
}
}
}
public
void
setFirstPlaceOfRobber
(){
public
void
setFirstPlaceOfRobber
()
{
int
tmpX
,
tmpY
,
cnt
=
0
;
while
(
true
){
while
(
true
)
{
Random
randomGenerator
=
new
Random
();
tmpX
=
randomGenerator
.
nextInt
(
m
);
tmpY
=
randomGenerator
.
nextInt
(
n
);
...
...
@@ -75,12 +75,41 @@ public class Field {
break
;
}
}
if
(
cnt
==
0
){
Robber
r
obber
=
new
Robber
();
if
(
cnt
==
0
)
{
Robber
R
obber
=
new
Robber
();
fieldShape
[
tmpX
][
tmpY
]
=
"-"
;
return
;
}
}
}
public
void
changeField
()
{
for
(
int
i
=
0
;
i
<
m
;
i
++)
for
(
int
j
=
0
;
j
<
n
;
j
++)
fieldShape
[
i
][
j
]
=
"-"
;
fieldShape
[
Robber
.
getX
()][
Robber
.
getY
()]
=
"D"
;
boolean
b
=
false
;
for
(
Police
police
:
polices
)
{
if
(
fieldShape
[
police
.
getX
()][
police
.
getY
()].
equals
(
"D"
))
{
b
=
true
;
fieldShape
[
police
.
getX
()][
police
.
getY
()]
=
"*"
;
}
if
(
fieldShape
[
police
.
getPreviosX
()][
police
.
getPreviosY
()].
equals
(
"D"
))
{
b
=
true
;
fieldShape
[
police
.
getX
()][
police
.
getY
()]
=
"*"
;
}
if
(!
fieldShape
[
police
.
getX
()][
police
.
getY
()].
equals
(
"*"
))
fieldShape
[
police
.
getX
()][
police
.
getY
()]
=
"P"
;
}
if
(
b
==
true
)
{
//show field
System
.
exit
(
0
);
}
}
}
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