Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
SWEN20003-2021S1-Wed-Week05
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
Xulin Yang
SWEN20003-2021S1-Wed-Week05
Commits
c7271ec3
Commit
c7271ec3
authored
Mar 31, 2021
by
yangxvlin
Browse files
Options
Downloads
Patches
Plain Diff
finish Q4c
parent
ff9bafec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Q4.java
+12
-0
12 additions, 0 deletions
src/Q4.java
with
12 additions
and
0 deletions
src/Q4.java
+
12
−
0
View file @
c7271ec3
import
bagel.*
;
import
bagel.*
;
import
bagel.util.Point
;
import
bagel.util.Point
;
import
java.text.DecimalFormat
;
/**
/**
* Xulin Yang, 904904
* Xulin Yang, 904904
*
*
...
@@ -44,6 +46,14 @@ public class Q4 extends AbstractGame {
...
@@ -44,6 +46,14 @@ public class Q4 extends AbstractGame {
// add STEP_SIZE * xd to x1;
// add STEP_SIZE * xd to x1;
// add STEP_SIZE * yd to y1;
// add STEP_SIZE * yd to y1;
// (c) After each movement, print to the console the position of the player in the form of
// x-coordinate, y-coordinate
//Keep 2 decimal digits for both x-coordinate and y-coordinate. To do so, you can use the format
//method in java.text.DecimalFormat class, e.g., define a static attribute
private
static
DecimalFormat
df
=
new
DecimalFormat
(
"0.00"
);
//and use it as
// System.out.println(df.format(playerX) +"," + df.format(playerY));
/**
/**
* calculate the direction for the player based on the input point w.r.t. player's location
* calculate the direction for the player based on the input point w.r.t. player's location
* @param Dest destination for the player to move to
* @param Dest destination for the player to move to
...
@@ -71,6 +81,8 @@ public class Q4 extends AbstractGame {
...
@@ -71,6 +81,8 @@ public class Q4 extends AbstractGame {
// (b)
// (b)
playerX
+=
STEP_SIZE
*
this
.
playerDirectionX
;
playerX
+=
STEP_SIZE
*
this
.
playerDirectionX
;
playerY
+=
STEP_SIZE
*
this
.
playerDirectionY
;
playerY
+=
STEP_SIZE
*
this
.
playerDirectionY
;
// (c)
System
.
out
.
println
(
df
.
format
(
playerX
)
+
","
+
df
.
format
(
playerY
));
}
}
if
(
new
Point
(
playerX
,
playerY
).
distanceTo
(
BALL_POSITION
)
<=
SCORE_DISTANCE
)
{
if
(
new
Point
(
playerX
,
playerY
).
distanceTo
(
BALL_POSITION
)
<=
SCORE_DISTANCE
)
{
...
...
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