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

Commit 723baaf

Browse files
committed
Merge pull request #24 from Microsoft/namespace
Update sample to use namespace for 'internal modules'
2 parents 24a7019 + b0e0a13 commit 723baaf

File tree

5 files changed

+27
-37
lines changed

5 files changed

+27
-37
lines changed

mankala/Base.ts

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
///<reference path="Driver.ts"/>
22

3-
module Base {
4-
export interface IList {
3+
namespace Base {
4+
export interface IList<T> {
55
isHead: boolean;
6-
next: IList;
7-
prev: IList;
8-
insertAfter(entry: IList): IList;
9-
insertBefore(entry: IList): IList;
10-
item();
6+
next: IList<T>;
7+
prev: IList<T>;
8+
data: T;
9+
insertAfter(entry: IList<T>): IList<T>;
10+
insertBefore(entry: IList<T>): IList<T>;
1111
empty(): boolean;
1212
}
1313

14-
export class List implements IList {
15-
next: IList;
16-
prev: IList;
17-
18-
constructor (public isHead: boolean, public data) { }
14+
export class List<T> implements IList<T> {
15+
next: IList<T>;
16+
prev: IList<T>;
1917

20-
item() {
21-
return this.data;
22-
}
18+
constructor(public isHead: boolean, public data: T) { }
2319

2420
empty(): boolean {
2521
return this.next == this;
2622
}
2723

28-
insertAfter(entry: IList): IList {
24+
insertAfter(entry: IList<T>): IList<T> {
2925
entry.next = this.next;
3026
entry.prev = this;
3127
this.next = entry;
3228
entry.next.prev = entry;
3329
return (entry);
3430
}
3531

36-
insertBefore(entry: IList): IList {
32+
insertBefore(entry: IList<T>): IList<T> {
3733
this.prev.next = entry;
3834
entry.next = this;
3935
entry.prev = this.prev;
@@ -42,21 +38,21 @@ module Base {
4238
}
4339
}
4440

45-
export function listMakeEntry(data): IList {
46-
var entry: List = new List(false, data);
41+
export function listMakeEntry<T>(data: T): IList<T> {
42+
var entry: List<T> = new List<T>(false, data);
4743
entry.prev = entry;
4844
entry.next = entry;
4945
return entry;
5046
}
5147

52-
export function listMakeHead(): IList {
53-
var entry: List = new List(true, null);
48+
export function listMakeHead<T>(): IList<T> {
49+
var entry: List<T> = new List(true, null);
5450
entry.prev = entry;
5551
entry.next = entry;
5652
return entry;
5753
}
5854

59-
export function listRemove(entry: IList): IList {
55+
export function listRemove<T>(entry: IList<T>): IList<T> {
6056
if (entry == null) {
6157
return null;
6258
}

mankala/Features.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///<reference path="Driver.ts"/>
22

3-
module Mankala {
3+
namespace Mankala {
44
export class Features {
55
public turnContinues = false;
66
public seedStoredCount = 0;

mankala/Game.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///<reference path="Driver.ts"/>
22

3-
module Mankala {
3+
namespace Mankala {
44
export var NoSpace = -1;
55
export var homeSpaces = [[0, 1, 2, 3, 4, 5],
66
[7, 8, 9, 10, 11, 12]];
@@ -14,18 +14,12 @@ module Mankala {
1414
const humanScoreId = "humanScore";
1515
const computerScoreId = "computerScore"
1616

17-
export interface IPositionList extends Base.IList {
18-
data: Position;
19-
push(pos: Position);
20-
pop(): Position;
21-
}
22-
23-
function pushPosition(pos: Position, l: IPositionList) {
17+
function pushPosition(pos: Position, l: Base.IList<Position>) {
2418
l.insertAfter(Base.listMakeEntry(pos));
2519
}
2620

27-
function popPosition(l: IPositionList) {
28-
var entry: IPositionList = <IPositionList>Base.listRemove(l.next);
21+
function popPosition(l: Base.IList<Position>) {
22+
var entry = Base.listRemove(l.next);
2923
if (entry != null) {
3024
return entry.data;
3125
} else {
@@ -43,7 +37,7 @@ module Mankala {
4337
export class Game {
4438
private position = new DisplayPosition([3, 3, 3, 3, 3, 3, 0, 3, 3, 3, 3, 3, 3, 0], NoMove, 0);
4539
private prevConfig: SeedCoords[][];
46-
private q: IPositionList = null;
40+
private q: Base.IList<Position> = null;
4741
private scores: number[] = null;
4842
private positionCount = 0;
4943
private moveCount = 0;
@@ -165,7 +159,7 @@ module Mankala {
165159

166160
private findMove() {
167161
var timeStart = new Date().getTime();
168-
this.q = <IPositionList>Base.listMakeHead();
162+
this.q = Base.listMakeHead<Position>();
169163
this.scores = [NoScore, NoScore, NoScore, NoScore, NoScore, NoScore];
170164
pushPosition(this.position, this.q);
171165
var deltaTime = 0;

mankala/Position.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///<reference path="Driver.ts"/>
22

3-
module Mankala {
3+
namespace Mankala {
44
export var storeHouses = [6, 13];
55
var svgNS = "http://www.w3.org/2000/svg";
66

mankala/geometry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///<reference path="Driver.ts"/>
22

3-
module Mankala {
3+
namespace Mankala {
44
export class Rectangle {
55

66
constructor (public x: number, public y: number,

0 commit comments

Comments
 (0)