Skip to content

Commit 4ea4302

Browse files
committed
Move HTML to standards mode.
1 parent af9e26a commit 4ea4302

File tree

12 files changed

+82
-48
lines changed

12 files changed

+82
-48
lines changed

chain/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Chain Reaction</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="chain.js"></script>
69
<style>
710
#start {
811
border: 1px solid #ccc;
@@ -75,8 +78,6 @@
7578
text-align: center;
7679
}
7780
</style>
78-
<script src="../common/utils.js"></script>
79-
<script src="chain.js"></script>
8081
</head>
8182

8283
<body>

connect/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
@@ -36,6 +37,7 @@
3637
}
3738
</style>
3839
</head>
40+
3941
<body>
4042
<select id="difficulty">
4143
<option value=0>Easy</option>

dino/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Dino</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="dino.js"></script>
69
<style>
710
#start {
811
border: 1px solid #ccc;
@@ -52,8 +55,6 @@
5255
fill: #D02E2B;
5356
}
5457
</style>
55-
<script src="../common/utils.js"></script>
56-
<script src="dino.js"></script>
5758
</head>
5859

5960
<body>

index.html

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games</title>
56
<link rel="stylesheet" href="common/style.css">
7+
<script src="common/utils.js"></script>
8+
<script>
9+
function init() {
10+
fixLinks();
11+
}
12+
window.addEventListener('load', init);
13+
</script>
614
<style>
715
header {
816
text-align: center;
@@ -26,13 +34,6 @@
2634
opacity: 0.8;
2735
}
2836
</style>
29-
<script src="common/utils.js"></script>
30-
<script>
31-
function init() {
32-
fixLinks();
33-
}
34-
window.addEventListener('load', init);
35-
</script>
3637
</head>
3738

3839
<body>

maze/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Maze</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="maze.js"></script>
69
<style>
710
#options {
811
float: right;
@@ -53,8 +56,6 @@
5356
fill: #D02E2B;
5457
}
5558
</style>
56-
<script src="../common/utils.js"></script>
57-
<script src="maze.js"></script>
5859
</head>
5960

6061
<body>

repeat/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Repeat</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="repeat.js"></script>
69
<style>
710
#controls {
811
margin-left:auto;
@@ -103,8 +106,6 @@
103106
text-align: center;
104107
}
105108
</style>
106-
<script src="../common/utils.js"></script>
107-
<script src="repeat.js"></script>
108109
</head>
109110

110111
<body>

shunting/index.html

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Inglenook Shunting</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="shunting.js"></script>
69
<style>
710
#mainTable {
811
margin-left:auto;
@@ -73,20 +76,18 @@
7376
display: none; /* comment out this line to see the paths */
7477
fill: none;
7578
stroke: #00f;
76-
stroke-width: 0.1;
79+
stroke-width: 0.1px;
7780
}
7881
.carNumber {
7982
fill: #fff;
80-
font-size: 5;
83+
font-size: 5px;
8184
user-select: none;
8285
}
8386
#couplerGroup>line {
8487
stroke: #666;
85-
stroke-width: 2;
88+
stroke-width: 2px;
8689
}
8790
</style>
88-
<script src="../common/utils.js"></script>
89-
<script src="shunting.js"></script>
9091
</head>
9192

9293
<body>

shunting/shunting.js

+44-24
Original file line numberDiff line numberDiff line change
@@ -61,31 +61,29 @@ AbstractSegment.prototype.prevSegment = null;
6161
// Reference to the turnout this track segment belongs to (if any).
6262
AbstractSegment.prototype.turnout = null;
6363

64-
// Starting on this track segment, and the specified 'startDistance' (measured
65-
// from the start of this segment), walk 'delta' (negative is towards the
66-
// headshunt, positive is towards the buffers).
64+
// Measuring from the start of this track segment, walk 'distance'
65+
// (negative is towards the headshunt, positive is towards the buffers).
6766
// Return a location tuple composed of the track segment and distance
6867
// (measured from the start of that segment).
6968
// If the walk exceeds the length of the track (e.g. hitting a buffer), return
70-
// the location of the end of the track.
71-
AbstractSegment.prototype.walk = function(startDistance, delta) {
72-
var endDistance = startDistance + delta;
73-
if (endDistance < 0) {
69+
// the location of the end of the track, as well as the difference between what
70+
// was requested vs what was obtained.
71+
AbstractSegment.prototype.walk = function(distance) {
72+
if (distance < 0) {
7473
if (this.prevSegment) {
75-
return this.prevSegment.walk(
76-
startDistance + this.prevSegment.length, delta);
74+
return this.prevSegment.walk(distance + this.prevSegment.length);
7775
}
78-
// End of track (headshunt or turnout).
79-
return [this, 0];
76+
// End of track (headshunt).
77+
return [this, 0, -distance];
8078
}
81-
if (endDistance > this.length) {
79+
if (distance > this.length) {
8280
if (this.nextSegment) {
83-
return this.nextSegment.walk(startDistance - this.length, delta);
81+
return this.nextSegment.walk(distance - this.length);
8482
}
8583
// End of track (buffer).
86-
return [this, this.length];
84+
return [this, this.length, distance - this.length];
8785
}
88-
return [this, endDistance];
86+
return [this, distance, 0];
8987
};
9088

9189
// Calculate the X/Y SVG coordinates of a point 'distance' down this segment.
@@ -271,14 +269,23 @@ Vehicle.prototype.couple = function(nextVehicle) {
271269
this.coupler.style.visibility = 'visible';
272270
};
273271

272+
// Length from the front of this vehicle to the end of the train.
273+
Vehicle.prototype.lengthToEnd = function() {
274+
var len = this.LENGTH + 2;
275+
if (this.nextVehicle) {
276+
len += this.nextVehicle.lengthToEnd();
277+
}
278+
return len;
279+
};
280+
274281
// Decouple this locomotive or care from another car.
275282
// Ok to call if not already coupled (does nothing).
276283
Vehicle.prototype.uncouple = function() {
277284
if (this.nextVehicle) {
278-
if (nextVehicle.prevVehicle !== this) {
285+
if (this.nextVehicle.prevVehicle !== this) {
279286
throw Error("nextVehicle wasn't connected to us");
280287
}
281-
nextVehicle.prevVehicle = null;
288+
this.nextVehicle.prevVehicle = null;
282289
trains.push(this.nextVehicle);
283290
this.nextVehicle = null;
284291
}
@@ -296,17 +303,30 @@ Vehicle.prototype.moveTo = function(segment, distance) {
296303
// Move this vehicle up (positive) or down (negative) the track by `delta`.
297304
Vehicle.prototype.moveBy = function(delta) {
298305
if (delta >= 0) { // Moving backwards (towards the buffers).
299-
var locBackAxle = this.segment_.walk(this.distance_, delta);
300-
var locFrontAxle = locBackAxle[0].walk(locBackAxle[1], -2 * this.AXLE_DISTANCE);
306+
if (!this.prevVehicle) {
307+
var locTrainEnd = this.segment_.walk(this.distance_ + delta -
308+
this.AXLE_DISTANCE - this.LENGTH / 2 + this.lengthToEnd());
309+
if (locTrainEnd[2] !== 0) {
310+
// Crashed into buffer.
311+
locoActualSpeed = 0;
312+
delta -= locTrainEnd[2];
313+
}
314+
}
315+
var locBackAxle = this.segment_.walk(this.distance_ + delta);
316+
var locFrontAxle = locBackAxle[0].walk(locBackAxle[1] - 2 * this.AXLE_DISTANCE);
301317
} else { // Moving forwards (towards the headshunt).
302-
var locFrontAxle = this.segment_.walk(this.distance_ - 2 * this.AXLE_DISTANCE, delta);
303-
var locBackAxle = locFrontAxle[0].walk(locFrontAxle[1], 2 * this.AXLE_DISTANCE);
318+
var locFrontAxle = this.segment_.walk(this.distance_ - 2 * this.AXLE_DISTANCE + delta);
319+
var locBackAxle = locFrontAxle[0].walk(locFrontAxle[1] + 2 * this.AXLE_DISTANCE);
304320
var backSegment = locBackAxle[0];
305321
if (!this.prevVehicle && backSegment.turnout &&
306322
backSegment.prevSegment.nextSegment !== backSegment) {
307323
// We are a locomotive running through a turnout switched the wrong way.
308324
backSegment.turnout.toggle();
309325
}
326+
if (locFrontAxle[2] !== 0) {
327+
// Crashed into end of headshunt.
328+
locoActualSpeed = 0;
329+
}
310330
}
311331
this.segment_ = locBackAxle[0];
312332
this.distance_ = locBackAxle[1];
@@ -349,13 +369,13 @@ var PATH_SEGMENTS = [
349369
new CurveSegment(48, 71, 180, 45), // 2: Headshunt curve
350370
new StraightSegment(19.716, 42.716, 22.627, -22.628), // 3: Turnout #1 straight
351371
new CurveSegment(70.627, 48.372, 225, 45), // 4: Siding A curve
352-
new StraightSegment(70.627, 8.372, 3 * 16, 0), // 5: Siding A straight
372+
new StraightSegment(70.627, 8.372, 3 * 16 + 3, 0), // 5: Siding A straight
353373
new CurveSegment(48, 71, 225, 45), // 6: Turnout #1 curve
354374
new StraightSegment(48, 31, 2 * 16, 0), // 7: Turnout #2 straight
355-
new StraightSegment(48 + 2 * 16, 31, 3 * 16, 0), // 8: Siding B
375+
new StraightSegment(48 + 2 * 16, 31, 3 * 16 + 3, 0), // 8: Siding B
356376
new CurveSegment(48, 71, 270, 45), // 9: Turnout #2 curve
357377
new CurveSegment(104.568, 14.431, 135, -45), // 10: Siding C curve
358-
new StraightSegment(104.568, 54.431, 16, 0) // 11: Siding C straight
378+
new StraightSegment(104.568, 54.431, 16 + 3, 0) // 11: Siding C straight
359379
];
360380

361381
// On page load, draw the track, initialize event handlers, and reset the game.

snake/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
@@ -142,6 +143,7 @@
142143
}
143144
</style>
144145
</head>
146+
145147
<body>
146148
<div id="options">
147149
<select id="players">

tank/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Tank</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="tank.js"></script>
69
<style>
710
#options {
811
float: right;
@@ -42,8 +45,6 @@
4245
font-size: 24pt;
4346
}
4447
</style>
45-
<script src="../common/utils.js"></script>
46-
<script src="tank.js"></script>
4748
</head>
4849

4950
<body>

tetromino/index.html

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
45
<title>Beaver Games : Tetromino</title>
56
<link rel="stylesheet" href="../common/style.css">
7+
<script src="../common/utils.js"></script>
8+
<script src="tetromino.js"></script>
69
<style>
710
#start {
811
border: 1px solid #ccc;
@@ -80,8 +83,6 @@
8083
padding: 1.5em;
8184
}
8285
</style>
83-
<script src="../common/utils.js"></script>
84-
<script src="tetromino.js"></script>
8586
</head>
8687

8788
<body>

ttt/index.html

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!DOCTYPE html>
12
<html>
23
<head>
34
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
@@ -64,6 +65,7 @@
6465
}
6566
</style>
6667
</head>
68+
6769
<body>
6870
<select id="difficulty">
6971
<option value=1>Normal</option>

0 commit comments

Comments
 (0)