Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
P
Project1Othello
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
9831113
Project1Othello
Commits
5ad9f2e8
Commit
5ad9f2e8
authored
Apr 13, 2020
by
amir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Scanning in graphic version
parent
5a06e374
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
13 deletions
+92
-13
Console.java
Console.java
+15
-1
Display.java
Display.java
+5
-0
Graphic.java
Graphic.java
+22
-1
Main.java
Main.java
+21
-11
Players.java
Players.java
+29
-0
No files found.
Console.java
View file @
5ad9f2e8
package
com
.
company
;
package
com
.
company
;
import
java.util.Scanner
;
public
class
Console
extends
Display
{
public
class
Console
extends
Display
{
public
Console
(
byte
displayType
)
{
public
Console
(
byte
displayType
)
{
super
(
displayType
);
super
(
displayType
);
}
}
@Override
public
void
display
(
int
[][]
a1
,
int
[][]
a2
)
{
public
void
display
(
int
[][]
a1
,
int
[][]
a2
)
{
super
.
display
(
a1
,
a2
);
super
.
display
(
a1
,
a2
);
System
.
out
.
println
(
" A B C D E F G H"
);
System
.
out
.
println
(
" A B C D E F G H"
);
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
System
.
out
.
print
(
i
+
" "
);
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
if
(
a2
[
j
][
i
]
!=
0
)
{
if
(
a2
[
j
][
i
]
!=
0
)
{
// the unicode of white circle (there is a player2 disc)
// the unicode of white circle (there is a player2 disc)
...
@@ -30,4 +32,16 @@ public class Console extends Display {
...
@@ -30,4 +32,16 @@ public class Console extends Display {
System
.
out
.
println
();
System
.
out
.
println
();
}
}
}
}
@Override
public
int
[]
getInput
()
{
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
nl
=
scanner
.
nextLine
();
char
[]
f
=
nl
.
toCharArray
();
int
[]
inputs
=
new
int
[
2
];
// scanning the x and y coordinates from user
inputs
[
1
]
=
f
[
0
]
-
'1'
+
1
;
inputs
[
0
]
=
f
[
2
]
-
'A'
+
1
;
return
inputs
;
}
}
}
Display.java
View file @
5ad9f2e8
...
@@ -14,4 +14,9 @@ public class Display {
...
@@ -14,4 +14,9 @@ public class Display {
public
void
display
(
int
[][]
a1
,
int
[][]
a2
){
public
void
display
(
int
[][]
a1
,
int
[][]
a2
){
}
}
public
int
[]
getInput
(){
int
[]
input
=
new
int
[
2
];
return
input
;
}
}
}
Graphic.java
View file @
5ad9f2e8
...
@@ -82,6 +82,9 @@ public class Graphic extends Display {
...
@@ -82,6 +82,9 @@ public class Graphic extends Display {
l1
=
new
JLabel
(
new
ImageIcon
(
"untitled.png"
));
l1
=
new
JLabel
(
new
ImageIcon
(
"untitled.png"
));
f
.
setSize
(
700
,
700
);
f
.
setSize
(
700
,
700
);
f
.
setLayout
(
null
);
f
.
setLayout
(
null
);
if
(
displayType
==
0
)
f
.
setVisible
(
false
);
else
f
.
setVisible
(
true
);
f
.
setVisible
(
true
);
f
.
add
(
b
);
f
.
add
(
b
);
b
.
setBounds
(
300
,
621
,
100
,
40
);
//x axis, y axis, width, height
b
.
setBounds
(
300
,
621
,
100
,
40
);
//x axis, y axis, width, height
...
@@ -327,4 +330,22 @@ public class Graphic extends Display {
...
@@ -327,4 +330,22 @@ public class Graphic extends Display {
}
}
return
null
;
return
null
;
}
}
@Override
public
int
[]
getInput
()
{
int
[]
ints
=
new
int
[
2
];
Iterator
<
JButton
>
buttonIterator
=
buttons
.
iterator
();
while
(
buttonIterator
.
hasNext
())
{
//System.out.println("koft!");
JButton
b1
=
buttonIterator
.
next
();
b1
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
arg0
)
{
ints
[
0
]
=
(
b1
.
getX
()
-
143
)
/
58
+
1
;
ints
[
1
]
=
(
b1
.
getY
()
-
135
)
/
58
+
1
;
}
});
}
return
ints
;
}
}
}
Main.java
View file @
5ad9f2e8
package
com
.
company
;
package
com
.
company
;
import
java.util.Scanner
;
import
java.util.Scanner
;
public
class
Main
{
public
class
Main
{
...
@@ -11,15 +13,15 @@ public class Main {
...
@@ -11,15 +13,15 @@ public class Main {
byte
displayType
=
scanner
.
nextByte
();
byte
displayType
=
scanner
.
nextByte
();
Player1
play1
=
new
Player1
();
Player1
play1
=
new
Player1
();
Player2
play2
=
new
Player2
();
Player2
play2
=
new
Player2
();
if
(
displayType
==
0
)
{
Console
console
=
new
Console
(
displayType
);
Console
console
=
new
Console
(
displayType
);
Graphic
graphic
=
new
Graphic
(
displayType
);
if
(
displayType
==
0
)
{
console
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
console
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
}
}
else
{
else
{
Graphic
graphic
=
new
Graphic
(
displayType
);
graphic
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
graphic
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
}
}
/*
while ((play1.getNumberOfDisks(play1.getArr1()) + play2.getNumberOfDisks(play2.getArr2()) < 64) &&
while
((
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
+
play2
.
getNumberOfDisks
(
play2
.
getArr2
())
<
64
)
&&
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
!=
0
)
&&
(
play2
.
getNumberOfDisks
(
play2
.
getArr2
())
!=
0
))
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
!=
0
)
&&
(
play2
.
getNumberOfDisks
(
play2
.
getArr2
())
!=
0
))
{
{
if
((
play1
.
numberOfPlayerPossibleMoves
(
play2
.
getArr2
(),
play1
.
getArr1
())
==
0
)
&&
if
((
play1
.
numberOfPlayerPossibleMoves
(
play2
.
getArr2
(),
play1
.
getArr1
())
==
0
)
&&
...
@@ -28,6 +30,7 @@ public class Main {
...
@@ -28,6 +30,7 @@ public class Main {
turns
++;
turns
++;
if
(
turns
%
2
==
1
){
if
(
turns
%
2
==
1
){
if
(
play1
.
numberOfPlayerPossibleMoves
(
play2
.
getArr2
(),
play1
.
getArr1
())
!=
0
)
{
if
(
play1
.
numberOfPlayerPossibleMoves
(
play2
.
getArr2
(),
play1
.
getArr1
())
!=
0
)
{
if
()
System
.
out
.
println
(
"Player1, it's your turn!"
);
System
.
out
.
println
(
"Player1, it's your turn!"
);
}
}
else
{
else
{
...
@@ -37,19 +40,26 @@ public class Main {
...
@@ -37,19 +40,26 @@ public class Main {
}
}
}
}
if
(
turns
%
2
==
0
){
if
(
turns
%
2
==
0
){
if (play2.numberOfPlayerPossibleMoves(play1.getArr1(), play2.getArr2()) != 0)
if
(
play2
.
numberOfPlayerPossibleMoves
(
play1
.
getArr1
(),
play2
.
getArr2
())
!=
0
)
{
System.out.println("Player2, it's your turn!");
//System.out.println("Player2, it's your turn!");
}
else
{
else
{
//if there is no possible move prints pass
//if there is no possible move prints pass
System
.
out
.
println
(
"pass"
);
System
.
out
.
println
(
"pass"
);
continue
;
continue
;
}
}
}
}
String nl = scanner.nextLine();
int
[]
inputs
=
new
int
[
2
];
char[] f = nl.toCharArray();
if
(
displayType
==
0
)
{
// scanning the x and y coordinates from user
inputs
=
console
.
getInput
();
int y = f[0] - '1' + 1;
}
int x = f[2] - 'A' + 1;
else
{
inputs
=
graphic
.
getInput
();
}
int
y
=
inputs
[
1
];
int
x
=
inputs
[
0
];
System
.
out
.
println
(
"x = "
+
x
);
System
.
out
.
println
(
"y = "
+
y
);
if
((
x
>=
1
)
&&
(
x
<
9
)
&&
(
y
>=
1
)
&&
(
y
<
9
))
{
if
((
x
>=
1
)
&&
(
x
<
9
)
&&
(
y
>=
1
)
&&
(
y
<
9
))
{
if
((!
play1
.
containsInArray
(
play1
.
getArr1
(),
x
,
y
))
&&
(!
play2
.
containsInArray
(
play2
.
getArr2
(),
x
,
y
))){
if
((!
play1
.
containsInArray
(
play1
.
getArr1
(),
x
,
y
))
&&
(!
play2
.
containsInArray
(
play2
.
getArr2
(),
x
,
y
))){
if
(
turns
%
2
==
1
){
if
(
turns
%
2
==
1
){
...
@@ -71,7 +81,7 @@ public class Main {
...
@@ -71,7 +81,7 @@ public class Main {
if
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
>
play2
.
getNumberOfDisks
(
play2
.
getArr2
()))
if
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
>
play2
.
getNumberOfDisks
(
play2
.
getArr2
()))
System
.
out
.
println
(
"Player1 wins!"
);
System
.
out
.
println
(
"Player1 wins!"
);
else
else
System.out.println("Player2 wins!");
*/
System
.
out
.
println
(
"Player2 wins!"
);
}
}
...
...
Players.java
View file @
5ad9f2e8
...
@@ -32,6 +32,35 @@ public class Players {
...
@@ -32,6 +32,35 @@ public class Players {
return
false
;
return
false
;
}
}
/**
* displays the place of black and white discs and blanks (will be overridden in console and graphic version)
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
*/
public
void
display
(
int
[][]
a1
,
int
[][]
a2
)
{
System
.
out
.
println
(
" A B C D E F G H"
);
for
(
int
i
=
1
;
i
<=
8
;
i
++)
{
System
.
out
.
print
(
i
+
" "
);
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
if
(
a2
[
j
][
i
]
!=
0
)
{
// the unicode of white circle (there is a player2 disc)
System
.
out
.
print
(
'\
u25CB
'
);
}
else
{
if
(
a1
[
j
][
i
]
!=
0
)
{
// the unicode of black circle (there is a player1 disc)
System
.
out
.
print
(
'\
u25CF
'
);
}
else
// the unicode of white square (a blank)
System
.
out
.
print
(
'\
u25A1
'
);
}
System
.
out
.
print
(
" "
);
}
System
.
out
.
println
();
}
}
/**
/**
* this method gets the coordinate of a blank space an checks if there is
* this method gets the coordinate of a blank space an checks if there is
* a opponent disc,and then if exists for each of opponent disks does the equalize method
* a opponent disc,and then if exists for each of opponent disks does the equalize method
...
...
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