Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dotandbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Naba Khan
dotandbox
Commits
9418530d
Commit
9418530d
authored
Jul 28, 2024
by
Will Billingsley
Browse files
Options
Downloads
Patches
Plain Diff
fixed bugs detected by test cases
parent
69cd737b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+7
-2
7 additions, 2 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
src/main/java/dotsandboxes/Main.java
+1
-1
1 addition, 1 deletion
src/main/java/dotsandboxes/Main.java
with
8 additions
and
3 deletions
src/main/java/dotsandboxes/DotsAndBoxesGrid.java
+
7
−
2
View file @
9418530d
...
@@ -109,10 +109,9 @@ public class DotsAndBoxesGrid {
...
@@ -109,10 +109,9 @@ public class DotsAndBoxesGrid {
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
if
(
x
>=
width
-
1
||
x
<
0
||
y
>=
height
-
1
||
y
<
0
)
{
return
false
;
return
false
;
}
}
// A box is complete if the north and south horizontals and the east and west verticals have all been drawn.
// 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).
// FIXME: You'll need to fix this code (after writing a test first).
return
true
;
return
horizontals
[
x
][
y
]
&&
horizontals
[
x
][
y
+
1
]
&&
verticals
[
x
][
y
]
&&
verticals
[
x
+
1
][
y
]
;
}
}
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
/** Tries to claim a box for a player. If the box is complete, sets the ownership and returns true. */
...
@@ -138,6 +137,9 @@ public class DotsAndBoxesGrid {
...
@@ -138,6 +137,9 @@ public class DotsAndBoxesGrid {
if
(
y
>=
height
||
y
<
0
)
{
if
(
y
>=
height
||
y
<
0
)
{
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
));
}
}
if
(
horizontals
[
x
][
y
])
{
throw
new
IllegalStateException
(
"Line has already been drawn"
);
}
// FIXME: You need to throw an exception if the line was already drawn.
// FIXME: You need to throw an exception if the line was already drawn.
...
@@ -169,6 +171,9 @@ public class DotsAndBoxesGrid {
...
@@ -169,6 +171,9 @@ public class DotsAndBoxesGrid {
if
(
y
>=
height
-
1
||
y
<
0
)
{
if
(
y
>=
height
-
1
||
y
<
0
)
{
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
-
1
));
throw
new
IndexOutOfBoundsException
(
String
.
format
(
"y was %d, which is out of range. Range is 0 to %d"
,
y
,
height
-
1
));
}
}
if
(
verticals
[
x
][
y
])
{
throw
new
IllegalStateException
(
"Line has already been drawn"
);
}
// You need to throw an exception if the line was already drawn.
// You need to throw an exception if the line was already drawn.
...
...
This diff is collapsed.
Click to expand it.
src/main/java/dotsandboxes/Main.java
+
1
−
1
View file @
9418530d
...
@@ -12,7 +12,7 @@ public class Main {
...
@@ -12,7 +12,7 @@ public class Main {
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
DotsAndBoxesGrid
grid
=
new
DotsAndBoxesGrid
(
15
,
8
,
2
);
// FIXME: Update this label to show your name and student number
// FIXME: Update this label to show your name and student number
JLabel
label
=
new
JLabel
(
"Name:
(Your name and student number goes here)
"
);
JLabel
label
=
new
JLabel
(
"Name:
NabaZaheerKhan
"
);
JPanel
borderPane
=
new
JPanel
(
new
BorderLayout
());
JPanel
borderPane
=
new
JPanel
(
new
BorderLayout
());
borderPane
.
add
(
label
,
BorderLayout
.
SOUTH
);
borderPane
.
add
(
label
,
BorderLayout
.
SOUTH
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment