Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
PentagoProject
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
9831006
PentagoProject
Commits
cc77ce89
Commit
cc77ce89
authored
Apr 28, 2020
by
kiana
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pentago project
parents
Pipeline
#4335
failed with stages
Changes
3
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
175 additions
and
0 deletions
+175
-0
Main.java
src/Main.java
+80
-0
Move.java
src/Move.java
+0
-0
PentagoMap.java
src/PentagoMap.java
+95
-0
No files found.
src/Main.java
0 → 100644
View file @
cc77ce89
import
java.util.Scanner
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
boolean
isEnd
=
false
;
Scanner
scanner
=
new
Scanner
(
System
.
in
);
PentagoMap
ground
=
new
PentagoMap
();
Move
play
=
new
Move
();
ground
.
first
();
ground
.
map
();
int
i
=
1
;
System
.
out
.
println
(
"First write x then y of the place you wanna put your nut in "
+
"then select a ground to rotate and then write if you want to rotate it to right or left by "
+
"typing 'L' or 'R' "
);
/**
* while no one hasnt won :
* gets x and y of the place
* then gets the play ground it wants to rotate and which direction to rotate if L or R
* checks if the inputs are valid
* put the nut and rotate the play ground
* same thing happens to the other player
* prints the map after each turn
*/
while
(!(
play
.
end
(
ground
.
getNuts
(),
1
)
||
play
.
end
(
ground
.
getNuts
(),
2
)))
{
i
--;
int
y1
=
scanner
.
nextInt
();
int
x1
=
scanner
.
nextInt
();
while
(!
play
.
check
(
y1
,
x1
,
ground
.
getNuts
())){
System
.
out
.
println
(
"invalid input"
);
y1
=
scanner
.
nextInt
();
x1
=
scanner
.
nextInt
();
}
y1
--;
x1
--;
play
.
move
(
y1
,
x1
,
ground
.
getNuts
(),
1
);
play
.
rotation
(
scanner
.
nextInt
(),
scanner
.
next
().
charAt
(
0
),
ground
.
getNuts
());
ground
.
map
();
if
(
play
.
end
(
ground
.
getNuts
(),
1
))
{
System
.
out
.
println
(
"winner is white"
);
return
;
}
if
(
play
.
end
(
ground
.
getNuts
(),
2
))
{
System
.
out
.
println
(
"winner is black"
);
return
;
}
int
y2
=
scanner
.
nextInt
();
int
x2
=
scanner
.
nextInt
();
while
(!
play
.
check
(
y2
,
x2
,
ground
.
getNuts
())){
System
.
out
.
println
(
"invalid input"
);
y2
=
scanner
.
nextInt
();
x2
=
scanner
.
nextInt
();
}
y2
--;
x2
--;
play
.
move
(
y2
,
x2
,
ground
.
getNuts
(),
2
);
play
.
rotation
(
scanner
.
nextInt
(),
scanner
.
next
().
charAt
(
0
),
ground
.
getNuts
());
ground
.
map
();
if
(
play
.
end
(
ground
.
getNuts
(),
1
))
{
System
.
out
.
println
(
"winner is white"
);
isEnd
=
true
;
}
if
(
play
.
end
(
ground
.
getNuts
(),
2
))
{
System
.
out
.
println
(
"winner is black"
);
isEnd
=
true
;
}
if
(
isEnd
)
return
;
}
}
}
src/Move.java
0 → 100644
View file @
cc77ce89
This diff is collapsed.
Click to expand it.
src/PentagoMap.java
0 → 100644
View file @
cc77ce89
import
java.util.ArrayList
;
public
class
PentagoMap
{
private
int
[][]
nuts
=
new
int
[
6
][
6
];
/**
* make the array 0 at first
*/
public
void
first
(){
for
(
int
i
=
0
;
i
<
6
;
i
++){
for
(
int
j
=
0
;
j
<
6
;
j
++){
nuts
[
i
][
j
]
=
0
;
}
}
}
/**
* sets the nuts
* @param nuts
*/
public
void
setNuts
(
int
[][]
nuts
)
{
this
.
nuts
=
nuts
;
}
/**
* gets the nuts
* @return
*/
public
int
[][]
getNuts
()
{
return
nuts
;
}
/**
* prints the map
*/
public
void
map
()
{
for
(
int
i
=
0
;
i
<
3
;
i
++)
{
for
(
int
j
=
0
;
j
<
3
;
j
++)
{
if
(
nuts
[
i
][
j
]
==
0
)
System
.
out
.
print
(
"\u2B55 "
);
else
if
(
nuts
[
i
][
j
]
==
1
)
System
.
out
.
print
(
"\u26AA "
);
else
if
(
nuts
[
i
][
j
]
==
2
)
System
.
out
.
print
(
"\u26AB "
);
}
System
.
out
.
print
(
"| "
);
for
(
int
k
=
3
;
k
<
6
;
k
++)
{
if
(
nuts
[
i
][
k
]
==
0
)
System
.
out
.
print
(
"\u2B55 "
);
else
if
(
nuts
[
i
][
k
]
==
1
)
System
.
out
.
print
(
"\u26AA "
);
else
if
(
nuts
[
i
][
k
]
==
2
)
System
.
out
.
print
(
"\u26AB "
);
}
System
.
out
.
println
();
}
//System.out.print("-");
for
(
int
z
=
0
;
z
<
6
;
z
++)
System
.
out
.
print
(
"--- "
);
System
.
out
.
println
();
for
(
int
i
=
3
;
i
<
6
;
i
++)
{
for
(
int
j
=
0
;
j
<
3
;
j
++)
{
if
(
nuts
[
i
][
j
]
==
0
)
System
.
out
.
print
(
"\u2B55 "
);
else
if
(
nuts
[
i
][
j
]
==
1
)
System
.
out
.
print
(
"\u26AA "
);
else
if
(
nuts
[
i
][
j
]
==
2
)
System
.
out
.
print
(
"\u26AB "
);
}
System
.
out
.
print
(
"| "
);
for
(
int
k
=
3
;
k
<
6
;
k
++)
{
if
(
nuts
[
i
][
k
]
==
0
)
System
.
out
.
print
(
"\u2B55 "
);
else
if
(
nuts
[
i
][
k
]
==
1
)
System
.
out
.
print
(
"\u26AA "
);
else
if
(
nuts
[
i
][
k
]
==
2
)
System
.
out
.
print
(
"\u26AB "
);
}
System
.
out
.
println
();
}
System
.
out
.
println
(
" "
);
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