-
Notifications
You must be signed in to change notification settings - Fork 0
/
FRC_Game_Clock(Rapid React).txt
executable file
·82 lines (71 loc) · 2.79 KB
/
FRC_Game_Clock(Rapid React).txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<body style=background: white;">
<!-- Display the countdown timer in an element -->
<div style="top: 50%; position: absolute; left: 40%;">
<p style="font-size: 150px;margin: auto;align-self: center;" id="demo">2:30</p>
<button style="width:100px;height:50px" id='timerControl' onclick="startTimer()">Start</button>
</div>
</body>
<script>
var x; //Interval Variable.
function startTimer() {
// Set the date we're counting down to
document.getElementById("demo").innerHTML = "2:30";
timerButton = document.getElementById('timerControl');
timerButton.setAttribute('onclick','abortGame()');
timerButton.innerText = "Abort";
var startTime = new Date().getTime();
var endTime = new Date(startTime + 150*1000) // Set the End time to Start time plus length of game(165 Seconds)
var countDownDate = new Date("Jan 5, 2024 15:37:25").getTime();
playAudio('./static_audio_start.wav');
// Update the count down every 1 second
x = setInterval(function() {
// Get today's date and time
var now = new Date().getTime();
// Find the distance between now and the count down date
var distance = endTime - now;
//Time calculations for days, hours, minutes and seconds
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
// Display the result in the element with id="demo"
if (seconds < 10) {
document.getElementById("demo").innerHTML = minutes + ":0" + seconds;
}
else {
document.getElementById("demo").innerHTML = minutes + ":" + seconds;
}
//console.log(distance);
//Play End of Autonomous Sound
if (distance < 136000 && distance >= 135000){ //Time to play end of game sound in milliseconds from end of game. Keep a one second gap between these variables.)
console.log("Start Autonomous");
playAudio('./static_audio_resume.wav');
}
if (distance < 31000 && distance >= 30000){
console.log("Start End Game");
playAudio('./static_audio_warning.wav');
}
// If the count down is finished, write some text
if (distance < 0) {
clearInterval(x);
document.getElementById("demo").innerHTML = "0:00";
console.log("End Game");
playAudio('./static_audio_end.wav');
timerButton = document.getElementById('timerControl');
timerButton.setAttribute('onclick','startTimer()');
timerButton.innerText = "Start";
}
}, 1000);
}
function playAudio(url){
new Audio(url).play();
}
function abortGame() {
clearInterval(x);
document.getElementById("demo").innerHTML = "Abort";
timerButton = document.getElementById('timerControl');
timerButton.setAttribute('onclick','startTimer()');
timerButton.innerText = "Start";
playAudio('./static_audio_abort.wav');
}
</script>