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
;
package
com
.
company
;
public
class
Console
extends
Display
{
public
class
Console
{
public
Console
(
byte
displayType
)
{
super
(
displayType
);
}
@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
;
package
com
.
company
;
public
class
Graphic
{
public
class
Graphic
{
}
}
Main.java
View file @
13f1fbcc
...
@@ -6,10 +6,13 @@ public class Main {
...
@@ -6,10 +6,13 @@ public class Main {
public
static
void
main
(
String
[]
args
)
{
public
static
void
main
(
String
[]
args
)
{
int
turns
=
0
;
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
();
Players
players
=
new
Players
();
Player1
play1
=
new
Player1
();
Player1
play1
=
new
Player1
();
Player2
play2
=
new
Player2
();
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
)
&&
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
))
{
{
...
@@ -36,7 +39,6 @@ public class Main {
...
@@ -36,7 +39,6 @@ public class Main {
continue
;
continue
;
}
}
}
}
Scanner
scanner
=
new
Scanner
(
System
.
in
);
String
nl
=
scanner
.
nextLine
();
String
nl
=
scanner
.
nextLine
();
char
[]
f
=
nl
.
toCharArray
();
char
[]
f
=
nl
.
toCharArray
();
// scanning the x and y coordinates from user
// scanning the x and y coordinates from user
...
@@ -52,7 +54,7 @@ public class Main {
...
@@ -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());
//System.out.println("player1: "+play1.getNumberOfDisks1()+" player2:"+play2.getNumberOfDisks2());
}
}
if
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
>
play2
.
getNumberOfDisks
(
play2
.
getArr2
()))
if
(
play1
.
getNumberOfDisks
(
play1
.
getArr1
())
>
play2
.
getNumberOfDisks
(
play2
.
getArr2
()))
...
...
Player1.java
View file @
13f1fbcc
package
com
.
company
;
package
com
.
company
;
public
class
Player1
extends
Players
{
public
class
Player1
extends
Players
{
// the array of the player 1's coordinate
int
[][]
arr1
;
int
[][]
arr1
;
/**
* Creates player1 with an initial deceleration
*/
public
Player1
(){
public
Player1
(){
arr1
=
new
int
[
9
][
9
];
arr1
=
new
int
[
9
][
9
];
arr1
[
4
][
5
]
=
1
;
arr1
[
4
][
5
]
=
1
;
arr1
[
5
][
4
]
=
1
;
arr1
[
5
][
4
]
=
1
;
}
}
/**
* returns the array of player1's coordinates
* @return the array of player1's coordinates
*/
public
int
[][]
getArr1
()
{
public
int
[][]
getArr1
()
{
return
arr1
;
return
arr1
;
}
}
...
...
Player2.java
View file @
13f1fbcc
package
com
.
company
;
package
com
.
company
;
public
class
Player2
extends
Players
{
public
class
Player2
extends
Players
{
// the array of the player 2's coordinate
int
[][]
arr2
;
int
[][]
arr2
;
/**
* Creates player2 with an initial deceleration
*/
public
Player2
(){
public
Player2
(){
arr2
=
new
int
[
9
][
9
];
arr2
=
new
int
[
9
][
9
];
arr2
[
4
][
4
]
=
1
;
arr2
[
4
][
4
]
=
1
;
arr2
[
5
][
5
]
=
1
;
arr2
[
5
][
5
]
=
1
;
}
}
/**
* returns the array of player2's coordinates
* @return the array of player2's coordinates
*/
public
int
[][]
getArr2
()
{
public
int
[][]
getArr2
()
{
return
arr2
;
return
arr2
;
}
}
...
...
Players.java
View file @
13f1fbcc
...
@@ -84,11 +84,15 @@ public class Players {
...
@@ -84,11 +84,15 @@ public class Players {
* displays the place of black and white discs and blanks
* displays the place of black and white discs and blanks
* @param a1 array of the player1's discs
* @param a1 array of the player1's discs
* @param a2 array of the player2's discs
* @param a2 array of the player2's discs
* @param displayType type of display
*/
*/
public
void
display
(
int
[][]
a1
,
int
[][]
a2
){
public
void
display
(
int
[][]
a1
,
int
[][]
a2
,
byte
displayType
){
System
.
out
.
println
(
" A B C D E F G H"
);
if
(
displayType
==
0
)
{
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
+
" "
);
if
(
displayType
==
0
)
System
.
out
.
print
(
i
+
" "
);
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
for
(
int
j
=
1
;
j
<=
8
;
j
++)
{
if
(
containsInArray
(
a2
,
j
,
i
))
{
if
(
containsInArray
(
a2
,
j
,
i
))
{
// the unicode of white circle (there is a player2 disc)
// the unicode of white circle (there is a player2 disc)
...
@@ -166,12 +170,13 @@ public class Players {
...
@@ -166,12 +170,13 @@ public class Players {
}
}
/**
/**
*
* checks the sides of the blank to see if there is an opponent disk or not
* @param arrOpponent
* and then goes to the "checkTheMoveIfPossible" method
* @param arr
* @param arrOpponent the coordinates of opponent's discs
* @param x
* @param arr the coordinates of player's discs
* @param y
* @param x the x coordinate of blank
* @return
* @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
){
public
boolean
checkSides
(
int
[][]
arrOpponent
,
int
[][]
arr
,
int
x
,
int
y
){
if
(
x
!=
1
){
if
(
x
!=
1
){
...
@@ -223,14 +228,14 @@ public class Players {
...
@@ -223,14 +228,14 @@ public class Players {
}
}
/**
/**
*
*
checks the move if possible :))
* @param arrOpponent
* @param arrOpponent
the coordinates of opponent's discs
* @param arr
* @param arr
the coordinates of player's discs
* @param x
* @param x
the x coordinate of blank
* @param y
* @param y
the x coordinate of blank
* @param moveX
* @param moveX
the direction in the x axis (0, 1 or -1)
* @param moveY
* @param moveY
the direction in the x axis (0, 1 or -1)
* @return
* @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
){
public
boolean
checkTheMoveIfPossible
(
int
[][]
arrOpponent
,
int
[][]
arr
,
int
x
,
int
y
,
int
moveX
,
int
moveY
){
int
x1
=
x
;
int
y1
=
y
;
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