Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Pentago_9731301
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
9731301
Pentago_9731301
Commits
1fad4f87
Commit
1fad4f87
authored
Apr 08, 2020
by
9731301
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add some changes and add single player option
parent
04b7356e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
116 additions
and
51 deletions
+116
-51
workspace.xml
.idea/workspace.xml
+20
-34
Pentago.class
out/production/MyPentago/Pentago.class
+0
-0
SinglePlay.class
out/production/MyPentago/SinglePlay.class
+0
-0
Pentago.java
src/Pentago.java
+64
-17
SinglePlay.java
src/SinglePlay.java
+32
-0
No files found.
.idea/workspace.xml
View file @
1fad4f87
...
...
@@ -3,7 +3,6 @@
<component
name=
"ChangeListManager"
>
<list
default=
"true"
id=
"63729159-695b-4499-ba7f-f31e81a0234c"
name=
"Default Changelist"
comment=
""
>
<change
beforePath=
"$PROJECT_DIR$/.idea/workspace.xml"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/.idea/workspace.xml"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/out/production/MyPentago/Block.class"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/out/production/MyPentago/Block.class"
afterDir=
"false"
/>
<change
beforePath=
"$PROJECT_DIR$/out/production/MyPentago/Pentago.class"
beforeDir=
"false"
afterPath=
"$PROJECT_DIR$/out/production/MyPentago/Pentago.class"
afterDir=
"false"
/>
</list>
<option
name=
"SHOW_DIALOG"
value=
"false"
/>
...
...
@@ -63,7 +62,8 @@
<workItem
from=
"1586162373379"
duration=
"6530000"
/>
<workItem
from=
"1586174700430"
duration=
"9185000"
/>
<workItem
from=
"1586246845885"
duration=
"2399000"
/>
<workItem
from=
"1586261785897"
duration=
"13320000"
/>
<workItem
from=
"1586261785897"
duration=
"27125000"
/>
<workItem
from=
"1586330745810"
duration=
"2315000"
/>
</task>
<servers
/>
</component>
...
...
@@ -71,42 +71,42 @@
<option
name=
"version"
value=
"1"
/>
</component>
<component
name=
"WindowStateProjectService"
>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.bottom"
timestamp=
"1586275386382
"
>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.bottom"
timestamp=
"1586351258387
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1586275386382
"
/>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.center"
timestamp=
"1586275386382
"
>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"1586351258387
"
/>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.center"
timestamp=
"1586351258387
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1586275386382
"
/>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.left"
timestamp=
"1586275386382
"
>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824"
timestamp=
"1586351258387
"
/>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.left"
timestamp=
"1586351258387
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1586275386382
"
/>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.right"
timestamp=
"1586275386382
"
>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824"
timestamp=
"1586351258387
"
/>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.right"
timestamp=
"1586351258387
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"5
64"
key=
"GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1586275386382
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.bottom"
timestamp=
"15862
74892633
"
>
<state
width=
"1493"
height=
"5
0"
key=
"GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824"
timestamp=
"1586351258387
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.bottom"
timestamp=
"15862
90133992
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
74892633
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.center"
timestamp=
"15862
74892633
"
>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.bottom/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
90133992
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.center"
timestamp=
"15862
90133992
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
74892633
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.left"
timestamp=
"15862
74892633
"
>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.center/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
90133992
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.left"
timestamp=
"15862
90133992
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
74892633
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.right"
timestamp=
"15862
74892633
"
>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.left/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
90133992
"
/>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.right"
timestamp=
"15862
90133992
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
74892633
"
/>
<state
x=
"281"
y=
"271"
key=
"com.intellij.ide.util.TipDialog"
timestamp=
"1586
261829792
"
>
<state
width=
"1493"
height=
"194"
key=
"GridCell.Tab.1.right/0.0.1536.824@0.0.1536.824"
timestamp=
"15862
90133992
"
/>
<state
x=
"281"
y=
"271"
key=
"com.intellij.ide.util.TipDialog"
timestamp=
"1586
330747078
"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
<state
x=
"281"
y=
"271"
key=
"com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824"
timestamp=
"1586
261829792
"
/>
<state
x=
"281"
y=
"271"
key=
"com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824"
timestamp=
"1586
330747078
"
/>
<state
x=
"25"
y=
"67"
key=
"new project wizard"
timestamp=
"1586105483065"
>
<screen
x=
"0"
y=
"0"
width=
"1536"
height=
"824"
/>
</state>
...
...
@@ -116,18 +116,4 @@
</state>
<state
x=
"425"
y=
"187"
key=
"run.anything.popup/0.0.1536.824@0.0.1536.824"
timestamp=
"1586180125854"
/>
</component>
<component
name=
"XDebuggerManager"
>
<breakpoint-manager>
<breakpoints>
<line-breakpoint
enabled=
"true"
type=
"java-method"
>
<url>
file://$PROJECT_DIR$/src/User.java
</url>
<line>
27
</line>
<properties
class=
"User"
method=
"isWinner"
>
<option
name=
"EMULATED"
value=
"true"
/>
</properties>
<option
name=
"timeStamp"
value=
"1"
/>
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
</project>
\ No newline at end of file
out/production/MyPentago/Pentago.class
View file @
1fad4f87
No preview for this file type
out/production/MyPentago/SinglePlay.class
0 → 100644
View file @
1fad4f87
File added
src/Pentago.java
View file @
1fad4f87
...
...
@@ -5,6 +5,7 @@ public class Pentago {
public
static
void
main
(
String
[]
args
){
ArrayList
<
Block
>
blocks
=
new
ArrayList
<>();
Scanner
scanner
=
new
Scanner
(
System
.
in
);
SinglePlay
bot
=
new
SinglePlay
();
User
user1
=
new
User
();
User
user2
=
new
User
();
User
chosenUser
=
new
User
();
...
...
@@ -17,6 +18,13 @@ public class Pentago {
int
i
;
boolean
ans
=
false
;
String
turn
;
String
singlePlay
;
System
.
out
.
println
(
"Do you want single play?yes/no"
);
singlePlay
=
scanner
.
next
().
toLowerCase
().
trim
();
if
(
singlePlay
.
equals
(
"yes"
)){
user2
=
bot
;
;
bot
.
setColor
(
'0'
);
}
for
(
i
=
0
;
i
<
4
;
i
++
){
Block
block
=
new
Block
();
block
.
createCells
();
...
...
@@ -26,11 +34,14 @@ public class Pentago {
printBlocks
(
blocks
);
while
(
true
)
{
if
(
chosenUser
.
isWinner
(
blocks
)){
System
.
out
.
println
(
chosenUser
.
getColor
()
+
" is winner"
);
if
(
user1
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user1
.
getColor
()
+
" is winner"
);
break
;
}
if
(
user2
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user2
.
getColor
()
+
" is winner"
);
break
;
}
//pass the turn if there is not any cell to choose for player
if
(
chosenUser
.
equals
(
user1
)){
chosenUser
=
user2
;
...
...
@@ -51,22 +62,57 @@ public class Pentago {
System
.
out
.
println
(
"pass"
);
continue
;
}
System
.
out
.
println
(
"\nplz enter a block number"
);
blockNumber
=
scanner
.
nextInt
()
-
1
;
System
.
out
.
println
(
"plz enter a cell number"
);
cellNumber
=
scanner
.
nextInt
()
-
1
;
if
(
chosenUser
.
cellIsAvailableToTake
(
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
)))
{
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
).
setColor
(
chosenUser
.
getColor
());
if
(
chosenUser
.
equals
(
bot
))
{
System
.
out
.
println
(
"***********************************"
);
blockNumber
=
bot
.
setBlock
()
;
cellNumber
=
bot
.
setCell
(
blocks
,
blockNumber
)
;
if
(
chosenUser
.
cellIsAvailableToTake
(
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
)))
{
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
).
setColor
(
chosenUser
.
getColor
());
}
printBlocks
(
blocks
);
if
(
user1
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user1
.
getColor
()
+
" is winner"
);
break
;
}
if
(
user2
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user2
.
getColor
()
+
" is winner"
);
break
;
}
System
.
out
.
println
();
blockNumberToTurn
=
bot
.
setBlock
()
;
turn
=
bot
.
setRightAndLeft
();
blocks
.
get
(
blockNumberToTurn
).
changePositionOfBlock
(
turn
);
printBlocks
(
blocks
);
System
.
out
.
println
(
"***********************************"
);
}
else
{
System
.
out
.
println
(
"\nplz enter a block number"
);
blockNumber
=
scanner
.
nextInt
()
-
1
;
System
.
out
.
println
(
"plz enter a cell number"
);
cellNumber
=
scanner
.
nextInt
()
-
1
;
if
(
chosenUser
.
cellIsAvailableToTake
(
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
)))
{
blocks
.
get
(
blockNumber
).
getAllCells
().
get
(
cellNumber
).
setColor
(
chosenUser
.
getColor
());
}
printBlocks
(
blocks
);
System
.
out
.
println
();
System
.
out
.
println
(
"plz enter the number of block you wanna turn"
);
blockNumberToTurn
=
scanner
.
nextInt
()
-
1
;
System
.
out
.
println
(
"plz enter how change position? right/left"
);
turn
=
scanner
.
next
().
trim
();
blocks
.
get
(
blockNumberToTurn
).
changePositionOfBlock
(
turn
);
printBlocks
(
blocks
);
printBlocks
(
blocks
);
if
(
user1
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user1
.
getColor
()
+
" is winner"
);
break
;
}
if
(
user2
.
isWinner
(
blocks
)){
System
.
out
.
println
(
user2
.
getColor
()
+
" is winner"
);
break
;
}
System
.
out
.
println
();
System
.
out
.
println
(
"plz enter the number of block you wanna turn"
);
blockNumberToTurn
=
scanner
.
nextInt
()
-
1
;
System
.
out
.
println
(
"plz enter how change position? right/left"
);
turn
=
scanner
.
next
().
trim
();
blocks
.
get
(
blockNumberToTurn
).
changePositionOfBlock
(
turn
);
printBlocks
(
blocks
);
System
.
out
.
println
();
}
}
}
public
static
void
printBlocks
(
ArrayList
<
Block
>
blocks
){
...
...
@@ -100,5 +146,6 @@ public class Pentago {
System
.
out
.
println
();
}
}
System
.
out
.
println
();
}
}
src/SinglePlay.java
0 → 100644
View file @
1fad4f87
import
java.util.ArrayList
;
import
java.util.Random
;
public
class
SinglePlay
extends
User
{
private
Random
random
=
new
Random
();
public
int
setCell
(
ArrayList
<
Block
>
blocks
,
int
blockNumber
){
while
(
true
)
{
int
x
=
random
.
nextInt
(
9
);
for
(
Block
b
:
blocks
){
if
(
b
.
getNumber
()
==
blockNumber
)
{
if
(
b
.
getAllCells
().
get
(
x
).
getColor
().
equals
(
'O'
)){
return
x
;
}
}
}
}
}
public
int
setBlock
(){
return
random
.
nextInt
(
4
);
}
public
String
setRightAndLeft
(){
int
r
=
random
.
nextInt
(
2
);
if
(
r
==
0
)
return
"right"
;
else
return
"left"
;
}
}
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