Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit eeeaa13

Browse files
Merge pull request #21 from Microsoft/fixMankalaOnresize
Cast body element to HTMLBodyElement for onresize
2 parents e395900 + 5d41ad5 commit eeeaa13

File tree

4 files changed

+21
-18
lines changed

4 files changed

+21
-18
lines changed

mankala/Game.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ module Mankala {
1010
export var NoScore = 31;
1111
export var NoMove = -1;
1212

13+
const bodyId = "body";
14+
const humanScoreId = "humanScore";
15+
const computerScoreId = "computerScore"
16+
1317
export interface IPositionList extends Base.IList {
1418
data: Position;
1519
push(pos: Position);
@@ -32,10 +36,8 @@ module Mankala {
3236
export function testBrowser() {
3337
var game = new Game();
3438
game.interactive();
35-
var bod = document.getElementById("bod");
36-
bod.onresize = function() {
37-
game.resize();
38-
}
39+
var body = <HTMLBodyElement>document.getElementById(bodyId);
40+
body.onresize = () => { game.resize(); };
3941
}
4042

4143
export class Game {
@@ -49,12 +51,12 @@ module Mankala {
4951

5052
private features = new Features();
5153
private nextSeedCounts: number[] = new Array<number>(14);
52-
private bod: Element;
54+
private body: Element;
5355
private boardElm: Element = null;
5456

5557
public resize() {
5658
if (this.boardElm != null) {
57-
this.bod.removeChild(this.boardElm);
59+
this.body.removeChild(this.boardElm);
5860
}
5961
this.showMove();
6062
}
@@ -79,7 +81,7 @@ module Mankala {
7981
if (!this.step()) {
8082
this.finish();
8183
}
82-
this.bod.removeChild(this.boardElm);
84+
this.body.removeChild(this.boardElm);
8385
this.showMove();
8486
}, 1000);
8587
}
@@ -96,15 +98,15 @@ module Mankala {
9698

9799
private auto() {
98100
// initialize
99-
this.bod = document.getElementById("bod");
101+
this.body = document.getElementById(bodyId);
100102
this.showMove();
101103
// run with timeout
102104
this.setStep();
103105
}
104106

105107
private showMove(): void {
106-
var hsc = document.getElementById("humscore");
107-
var csc = document.getElementById("compscore");
108+
var hsc = document.getElementById(humanScoreId);
109+
var csc = document.getElementById(computerScoreId);
108110

109111
var g = this;
110112
if (!this.isInteractive) {
@@ -116,7 +118,7 @@ module Mankala {
116118
((this.position.turn == 0) ? " <-Turn" : "");
117119
csc.innerText = this.position.seedCounts[storeHouses[1]] +
118120
((this.position.turn == 1) ? " <-Turn" : "");
119-
this.bod.appendChild(this.boardElm);
121+
this.body.appendChild(this.boardElm);
120122
}
121123

122124
public humanMove(seed: number) {
@@ -125,7 +127,7 @@ module Mankala {
125127
this.position = new DisplayPosition(this.nextSeedCounts.slice(0), NoMove,
126128
this.features.turnContinues ? this.position.turn : 1 - this.position.turn);
127129
this.position.config = this.prevConfig;
128-
this.bod.removeChild(this.boardElm);
130+
this.body.removeChild(this.boardElm);
129131
this.showMove();
130132
if (this.position.turn == 1) {
131133
this.setStep();
@@ -135,7 +137,7 @@ module Mankala {
135137

136138
public interactive() {
137139
this.isInteractive = true;
138-
this.bod = document.getElementById("bod");
140+
this.body = document.getElementById(bodyId);
139141
this.showMove();
140142
}
141143

mankala/Position.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ module Mankala {
182182

183183
public toCircleSVG(game: Game) {
184184
var seedDivisions = 14;
185-
var bod = document.getElementById("bod");
186185
var board = document.createElementNS(svgNS, "svg");
187186
var w = window.innerWidth - 40;
188187
var h = window.innerHeight - 40;

mankala/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ features of TypeScript are highlighted:
1111

1212

1313
## Running
14+
1415
```
1516
tsc Driver.ts --sourcemap -out game.js
1617
cscript game.js
1718
```
18-
For web execution use play.htm.
19+
20+
For web execution use play.html.
1921

mankala/play.htm renamed to mankala/play.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<script type="text/javascript" src="game.js"></script>
99
<link rel="stylesheet" type="text/css" href="play.css"/>
1010
</head>
11-
<body id="bod" onload="Mankala.testBrowser()">
12-
<div class="hscore">Human: <span id="humscore">0</span></div>
13-
<div class="cscore">Computer: <span id="compscore">0</span></div>
11+
<body id="body" onload="Mankala.testBrowser()">
12+
<div class="hscore">Human: <span id="humanScore">0</span></div>
13+
<div class="cscore">Computer: <span id="computerScore">0</span></div>
1414
</body>
1515
</html>

0 commit comments

Comments
 (0)