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
22d731ec
Commit
22d731ec
authored
Apr 21, 2019
by
9731077
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
finished
parent
95728c84
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
71 deletions
+80
-71
Field.java
Field.java
+80
-71
No files found.
Field.java
View file @
22d731ec
import
java.util.
ArrayList
;
import
java.
util.Random
;
import
java.util.
*
;
import
java.
sql.SQLOutput
;
//string to
public
class
Field
{
private
int
m
;
private
int
n
;
private
ArrayList
<
Police
>
polices
=
new
ArrayList
<
Police
>();
private
Robber
Robber
;
private
final
int
m
;
private
final
int
n
;
public
String
[][]
fieldShape
;
private
Robber
robber
;
private
ArrayList
<
Police
>
polices
=
new
ArrayList
<
Police
>();
public
Field
(
int
m
,
int
n
)
{
this
.
m
=
m
;
...
...
@@ -18,98 +18,107 @@ public class Field {
fieldShape
[
i
][
j
]
=
"-"
;
}
public
int
getM
()
{
return
m
;
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
)
{
showFieldShape
();
System
.
exit
(
0
);
}
}
public
void
setRobber
(
Robber
robber
)
{
this
.
robber
=
robber
;
}
public
void
setM
(
int
m
)
{
this
.
m
=
m
;
public
Robber
getRobber
(
)
{
return
robber
;
}
public
int
getN
()
{
return
n
;
public
String
[][]
getCourt
()
{
return
fieldShape
;
}
public
void
setN
(
int
n
)
{
this
.
n
=
n
;
public
ArrayList
<
Police
>
getPolices
(
)
{
return
polices
;
}
public
void
setFirstPlaceOfPoli
ce
(
int
policeNum
)
{
int
tmpX
,
tmpY
,
cnt
=
0
;
Random
randomGenerator
=
new
Random
();
public
void
randomPolicePla
ce
(
int
policeNum
)
{
Random
random
=
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
{
int
x
=
random
.
nextInt
(
m
);
int
y
=
random
.
nextInt
(
n
);
boolean
bl
=
true
;
if
(
polices
.
size
()
!=
0
)
{
for
(
Police
police
:
polices
)
{
if
(
police
.
getX
()
==
tmpX
&&
police
.
getY
()
==
tmpY
)
{
if
(
police
.
getX
()
==
x
&&
police
.
getY
()
==
y
)
{
i
--;
cnt
++
;
bl
=
false
;
break
;
}
}
if
(
cnt
==
0
)
{
Police
p
=
new
Police
(
tmpX
,
tmpY
);
fieldShape
[
tmpX
][
tmpY
]
=
"P"
;
polices
.
add
(
p
);
}
}
if
(
bl
==
true
)
{
fieldShape
[
x
][
y
]
=
"P"
;
Police
p
=
new
Police
(
x
,
y
);
polices
.
add
(
p
);
}
}
}
public
void
setFirstPlaceOfRobber
()
{
int
tmpX
,
tmpY
,
cnt
=
0
;
}
public
void
randomRobberPlce
()
{
Random
random
=
new
Random
();
while
(
true
)
{
Random
randomGenerator
=
new
Random
(
);
tmpX
=
randomGenerator
.
nextInt
(
m
);
tmpY
=
randomGenerator
.
nextInt
(
n
)
;
int
x
=
random
.
nextInt
(
m
);
int
y
=
random
.
nextInt
(
n
);
boolean
b
=
true
;
for
(
Police
police
:
polices
)
{
if
(
police
.
getX
()
==
tmpX
&&
police
.
getY
()
==
tmpY
)
{
cnt
++;
break
;
}
if
(
police
.
getX
()
==
x
&&
police
.
getY
()
==
y
)
b
=
false
;
}
if
(
cnt
==
0
)
{
Robber
Robber
=
new
Robber
(
);
fieldShape
[
tmpX
][
tmpY
]
=
"-
"
;
return
;
if
(
b
==
true
)
{
robber
=
new
Robber
(
x
,
y
);
fieldShape
[
x
][
y
]
=
"D
"
;
break
;
}
}
}
public
void
changeField
()
{
for
(
int
i
=
0
;
i
<
m
;
i
++)
public
void
showFieldShape
()
{
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
);
System
.
out
.
print
(
fieldShape
[
i
][
j
]
+
" | "
);
System
.
out
.
println
();
}
}
}
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