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
df12700b
Commit
df12700b
authored
Apr 19, 2019
by
9731077
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
First police of java fifnished
parent
7b284a5f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
1 deletion
+61
-1
Field.java
Field.java
+61
-1
No files found.
Field.java
View file @
df12700b
package
PACKAGE_NAME
;
import
java.util.ArrayList
;
import
java.util.Random
;
//string to
public
class
Field
{
private
int
m
,
n
;
private
String
[][]
fieldShape
;
ArrayList
<
Police
>
polices
;
ArrayList
<
Robber
>
robberPosotion
;
public
Field
(
int
m
,
int
n
)
{
polices
=
new
ArrayList
<>();
robberPosotion
=
new
ArrayList
<>();
this
.
m
=
m
;
this
.
n
=
n
;
fieldShape
=
new
String
[
m
][
n
];
}
public
int
getM
()
{
return
m
;
}
public
void
setM
(
int
m
)
{
this
.
m
=
m
;
}
public
int
getN
()
{
return
n
;
}
public
void
setN
(
int
n
)
{
this
.
n
=
n
;
}
public
void
setFirstPlaceOfPolice
(
int
policeNum
)
{
int
tmpX
,
tmpY
,
cnt
=
0
;
Random
randomGenerator
=
new
Random
();
for
(
int
i
=
0
;
i
<
policeNum
;
i
++)
{
tmpX
=
randomGenerator
.
nextInt
(
m
);
tmpY
=
randomGenerator
.
nextInt
(
n
);
if
(
polices
.
size
()
==
0
)
{
Police
p
=
new
Police
(
tmpX
,
tmpY
);
fieldShape
[
tmpX
][
tmpY
]
=
"P"
;
polices
.
add
(
p
);
System
.
out
.
println
(
"First police created"
);
}
else
{
for
(
Police
police
:
polices
)
{
if
(
police
.
getX
()
==
tmpX
&&
police
.
getY
()
==
tmpY
)
{
i
--;
cnt
++;
break
;
}
}
if
(
cnt
==
0
){
Police
p
=
new
Police
(
tmpX
,
tmpY
);
fieldShape
[
tmpX
][
tmpY
]
=
"P"
;
polices
.
add
(
p
);
System
.
out
.
println
(
i
+
"th police created"
);
}
}
}
}
}
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