Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Martin Schreiber
COSC220 A2
Commits
5e1e2fb2
Commit
5e1e2fb2
authored
Jul 22, 2021
by
Martin Schreiber
Browse files
fixed issues
parent
a47e1f64
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
View file @
5e1e2fb2
...
...
@@ -110,10 +110,12 @@ public class DotsAndBoxesGrid {
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
return
false
;
}
if
(
getHorizontal
(
x
,
y
)
&&
getHorizontal
(
x
,
y
+
1
)
&&
getVertical
(
x
+
1
,
y
)
&&
getVertical
(
x
,
y
)){
return
true
;
}
else
{
return
false
;
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// FIXME: You'll need to fix this code (after writing a test first).
return
true
;
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
...
@@ -140,21 +142,26 @@ public class DotsAndBoxesGrid {
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
}
// FIXME: You need to throw an exception if the line was already drawn.
if
(
this
.
horizontals
[
x
][
y
]){
throw
new
RuntimeException
(
"Line already drawn."
);
}
else
{
this
.
horizontals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
boolean
claimN
=
claimBox
(
x
,
y
-
1
,
player
);
boolean
claimS
=
claimBox
(
x
,
y
,
player
);
if
(
claimN
||
claimS
)
{
notifyObservers
();
return
true
;
}
else
{
nextPlayer
();
notifyObservers
();
return
false
;
}
}
this
.
horizontals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
boolean
claimN
=
claimBox
(
x
,
y
-
1
,
player
);
boolean
claimS
=
claimBox
(
x
,
y
,
player
);
if
(
claimN
||
claimS
)
{
notifyObservers
();
return
true
;
}
else
{
nextPlayer
();
notifyObservers
();
return
false
;
}
}
/**
...
...
@@ -171,19 +178,23 @@ public class DotsAndBoxesGrid {
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
-
1
));
}
// You need to throw an exception if the line was already drawn.
this
.
verticals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
boolean
claimE
=
claimBox
(
x
,
y
,
player
);
boolean
claimW
=
claimBox
(
x
-
1
,
y
,
player
);
if
(
claimE
||
claimW
)
{
notifyObservers
();
return
true
;
}
else
{
nextPlayer
();
notifyObservers
();
return
false
;
if
(
this
.
verticals
[
x
][
y
]){
throw
new
RuntimeException
(
"Line already drawn."
);
}
else
{
this
.
verticals
[
x
][
y
]
=
true
;
// Try to claim the north or south boxes
boolean
claimN
=
claimBox
(
x
,
y
-
1
,
player
);
boolean
claimS
=
claimBox
(
x
,
y
,
player
);
if
(
claimN
||
claimS
)
{
notifyObservers
();
return
true
;
}
else
{
nextPlayer
();
notifyObservers
();
return
false
;
}
}
}
...
...
Martin Schreiber
@mschreib
mentioned in issue
#1 (closed)
·
Jul 22, 2021
mentioned in issue
#1 (closed)
mentioned in issue #1
Toggle commit list
Write
Preview
Supports
Markdown
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