Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FaultInOurPong
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Group3
FaultInOurPong
Commits
548e8beb
Commit
548e8beb
authored
8 years ago
by
Jie Luo
Browse files
Options
Downloads
Patches
Plain Diff
time variable added
parent
87d31ecf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Game_Code/src/startGame/GameController.java
+45
-4
45 additions, 4 deletions
Game_Code/src/startGame/GameController.java
with
45 additions
and
4 deletions
Game_Code/src/startGame/GameController.java
+
45
−
4
View file @
548e8beb
...
...
@@ -78,8 +78,9 @@ public class GameController{
private
Player
ai
;
private
Timer
t
;
private
Timer
record
;
private
long
startTime
;
private
long
endTime
;
private
double
timeElapsed
;
public
GameController
(
GameView
v
,
GameModel
m
){
this
.
v
=
v
;
...
...
@@ -164,6 +165,13 @@ public class GameController{
gameDisplay
.
setFocusable
(
true
);
gameDisplay
.
setFocusTraversalKeysEnabled
(
false
);
/**
* Initialize the start time and end time for a player
*/
startTime
=
0
;
endTime
=
0
;
timeElapsed
=
0
;
}
/**
...
...
@@ -265,7 +273,11 @@ public class GameController{
mode
.
setVisible
(
false
);
// Start the game with single mode
gameFrame
.
setVisible
(
true
);
t
.
start
();
startTime
=
System
.
currentTimeMillis
();
}
//else if(source==mode.getAdvance()){
//TODO: the obstacle mode
//}
}
}
...
...
@@ -554,19 +566,48 @@ public class GameController{
* @brief checks whether the game ends
* @details check the number of life for both the player and the ai is 0.
*/
p
ublic
void
checkGameOver
(){
p
rivate
void
checkGameOver
(){
/**
* - If the number of life for the ai is 0, the player wins
* - If the number of life for the player is 0, the ai wins.
* - Calculate the time a player has played, if breaks the record, save the record.
*/
if
(
scoreBottom
==
0
){
getElapsedTime
();
v
.
gameOver
(
0
);
}
else
if
(
scoreTop
==
0
){
resetGame
();
}
else
if
(
scoreTop
==
0
){
getElapsedTime
();
v
.
gameOver
(
1
);
resetGame
();
}
//TODO: SAVE RECORD
}
private
void
getElapsedTime
(){
endTime
=
System
.
currentTimeMillis
();
timeElapsed
=
(
endTime
-
startTime
)/
1000.0
;
System
.
out
.
println
(
timeElapsed
);
}
private
void
resetGame
(){
scoreTop
=
0
;
scoreBottom
=
0
;
}
}
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