Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
brick-breaker
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mkandel2
brick-breaker
Commits
b3b30e37
Commit
b3b30e37
authored
1 year ago
by
Joshua Alejandro
Browse files
Options
Downloads
Patches
Plain Diff
ScoringSystem will now load from highscore text file
parent
3779a59a
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
app/src/main/java/brickbreaker/ScoringSystem.java
+31
-2
31 additions, 2 deletions
app/src/main/java/brickbreaker/ScoringSystem.java
with
31 additions
and
2 deletions
app/src/main/java/brickbreaker/ScoringSystem.java
+
31
−
2
View file @
b3b30e37
import
java.io.BufferedReader
;
import
java.io.FileReader
;
import
java.io.FileWriter
;
import
java.io.IOException
;
public
class
ScoringSystem
{
private
int
score
;
// Current Score
private
int
highScore
;
// Highest Score
private
static
final
int
POINTS
=
1
;
// Point Value
private
static
final
String
HIGHSCORE_FILE
=
"src/main/resources/highscore.txt"
;
public
ScoringSystem
()
{
this
.
score
=
0
;
this
.
highScore
=
0
;
this
.
highScore
=
loadHighScore
();
}
private
int
loadHighScore
()
{
try
(
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
HIGHSCORE_FILE
)))
{
String
line
=
reader
.
readLine
();
if
(
line
!=
null
)
{
return
Integer
.
parseInt
(
line
.
trim
());
}
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Loading Error: "
+
e
.
getMessage
());
}
return
0
;
}
private
void
saveHighScore
(
int
newHighScore
)
{
try
(
FileWriter
writer
=
new
FileWriter
(
HIGHSCORE_FILE
))
{
writer
.
write
(
Integer
.
toString
(
newHighScore
));
}
catch
(
IOException
e
)
{
System
.
err
.
println
(
"Saving Error: "
+
e
.
getMessage
());
}
}
// Add point to each broken brick
...
...
@@ -14,10 +42,11 @@ public class ScoringSystem {
checkForNewHighScore
();
}
// Compare Current Score and
hig
hest
s
core
// Compare Current Score and
Hgi
hest
S
core
private
void
checkForNewHighScore
()
{
if
(
score
>
highScore
)
{
highScore
=
score
;
saveHighScore
(
highScore
);
}
}
...
...
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