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
13f1fbcc
Commit
13f1fbcc
authored
Apr 12, 2020
by
amir
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finalized
parent
cac6a3c1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
30 deletions
+46
-30
Console.java
Console.java
+1
-9
Graphic.java
Graphic.java
+2
-1
Main.java
Main.java
+5
-3
Player1.java
Player1.java
+8
-0
Player2.java
Player2.java
+8
-0
Players.java
Players.java
+22
-17
No files found.
Console.java
View file @
13f1fbcc
package
com
.
company
;
public
class
Console
extends
Display
{
public
Console
(
byte
displayType
)
{
super
(
displayType
);
}
public
class
Console
{
@Override
public
void
visualize
()
{
super
.
visualize
();
System
.
out
.
println
(
" A B C D E F G H"
);
}
}
Graphic.java
View file @
13f1fbcc
package
com
.
company
;
public
class
Graphic
{
public
class
Graphic
{
}
Main.java
View file @
13f1fbcc
...
...
@@ -6,10 +6,13 @@ public class Main {
public
static
void
main
(
String
[]
args
)
{
int
turns
=
0
;
System
.
out
.
println
(
"What type of game do you want? 0)console 1)graphic"
);
Scanner
scanner
=
new
Scanner
(
System
.
in
);
byte
displayType
=
scanner
.
nextByte
();
Players
players
=
new
Players
();
Player1
play1
=
new
Player1
();
Player2
play2
=
new
Player2
();
players
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
players
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
()
,
displayType
);
while
((
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
+
play2
.
getNumberOfDisks
(
play2
.
getArr2
())
<
64
)
&&
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
!=
0
)
&&
(
play2
.
getNumberOfDisks
(
play2
.
getArr2
())
!=
0
))
{
...
...
@@ -36,7 +39,6 @@ public class Main {
continue
;
}
}
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
nl
=
scanner
.
nextLine
();
char
[]
f
=
nl
.
toCharArray
();
// scanning the x and y coordinates from user
...
...
@@ -52,7 +54,7 @@ public class Main {
}
}
players
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
());
players
.
display
(
play1
.
getArr1
(),
play2
.
getArr2
()
,
displayType
);
//System.out.println("player1: "+play1.getNumberOfDisks1()+" player2:"+play2.getNumberOfDisks2());
}
if
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
>
play2
.
getNumberOfDisks
(
play2
.
getArr2
()))
...
...
Player1.java
View file @
13f1fbcc
package
com
.
company
;
public
class
Player1
extends
Players
{
// the array of the player 1's coordinate
int
[][]
arr1
;
/**
* Creates player1 with an initial deceleration
*/
public
Player1
(){
arr1
=
new
int
[
9
][
9
];
arr1
[
4
][
5
]
=
1
;
arr1
[
5
][
4
]
=
1
;
}
/**
* returns the array of player1's coordinates
* @return the array of player1's coordinates
*/
public
int
[][]
getArr1
()
{
return
arr1
;
}
...
...
Player2.java
View file @
13f1fbcc
package
com
.
company
;
public
class
Player2
extends
Players
{
// the array of the player 2's coordinate
int
[][]
arr2
;
/**
* Creates player2 with an initial deceleration
*/
public
Player2
(){
arr2
=
new
int
[
9
][
9
];
arr2
[
4
][
4
]
=
1
;
arr2
[
5
][
5
]
=
1
;
}
/**
* returns the array of player2's coordinates
* @return the array of player2's coordinates
*/
public
int
[][]
getArr2
()
{
return
arr2
;
}
...
...
Players.java
View file @
13f1fbcc
...
...
@@ -84,11 +84,15 @@ public class Players {
* displays the place of black and white discs and blanks
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
* @param displayType type of display
*/
public
void
display
(
int
[][]
a1
,
int
[][]
a2
){
System
.
out
.
println
(
" A B C D E F G H"
);
public
void
display
(
int
[][]
a1
,
int
[][]
a2
,
byte
displayType
){
if
(
displayType
==
0
)
{
System
.
out
.
println
(
" A B C D E F G H"
);
}
for
(
int
i
=
1
;
i
<=
8
;
i
++){
System
.
out
.
print
(
i
+
" "
);
if
(
displayType
==
0
)
System
.
out
.
print
(
i
+
" "
);
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
if
(
containsInArray
(
a2
,
j
,
i
))
{
// the unicode of white circle (there is a player2 disc)
...
...
@@ -166,12 +170,13 @@ public class Players {
}
/**
*
* @param arrOpponent
* @param arr
* @param x
* @param y
* @return
* checks the sides of the blank to see if there is an opponent disk or not
* and then goes to the "checkTheMoveIfPossible" method
* @param arrOpponent the coordinates of opponent's discs
* @param arr the coordinates of player's discs
* @param x the x coordinate of blank
* @param y the x coordinate of blank
* @return true if any of sides is allowed and false if none them
*/
public
boolean
checkSides
(
int
[][]
arrOpponent
,
int
[][]
arr
,
int
x
,
int
y
){
if
(
x
!=
1
){
...
...
@@ -223,14 +228,14 @@ public class Players {
}
/**
*
* @param arrOpponent
* @param arr
* @param x
* @param y
* @param moveX
* @param moveY
* @return
*
checks the move if possible :))
* @param arrOpponent
the coordinates of opponent's discs
* @param arr
the coordinates of player's discs
* @param x
the x coordinate of blank
* @param y
the x coordinate of blank
* @param moveX
the direction in the x axis (0, 1 or -1)
* @param moveY
the direction in the x axis (0, 1 or -1)
* @return
if there is a possible move returns true and else returns false
*/
public
boolean
checkTheMoveIfPossible
(
int
[][]
arrOpponent
,
int
[][]
arr
,
int
x
,
int
y
,
int
moveX
,
int
moveY
){
int
x1
=
x
;
int
y1
=
y
;
...
...
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