This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div [style.font-size]="cellState === 0 ? '1.0em' : '10.0em'" | |
[style.color]="cellState === 1 ? 'red' : 'black'" | |
[style.cursor]="cellState === 0 ? 'pointer' : 'not-allowed'" | |
(mouseover)="backgroundColor='gray'" | |
(mouseout)="backgroundColor='white'" | |
[style.background]="winningCell ? 'green' : backgroundColor || 'white'" | |
(click)="set()"> | |
{{cellText}} | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public set(): void { | |
if (this.cellState === State.None) { | |
if (this.validTurn) { | |
this.stateChangeRequested.emit(true); | |
} else { | |
this.cellQuote = this.badTurn.getBadTurn(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class CellComponent implements OnInit, OnChanges { | |
ngOnChanges() { | |
if (Math.random() < 0.5) { | |
this.cellQuote = this.quoteService.getQuote(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public advanceBoardState(): void { | |
// check for win | |
let won = false, computerState = this.computerTurn === GameState.XTurn ? State.X : State.O; | |
for (let x = 0; !won && x < this.winLines.length; x += 1) { | |
let row = this.winLines[x]; | |
if (this.won(row)) { | |
won = true; | |
for (let y = 0; y < row.length; y += 1) { | |
row[y].winningCell = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
draw = true; | |
for (let x = 0; draw && x < this.winLines.length; x += 1) { | |
draw = this.draw(this.winLines[x]); | |
} | |
if (draw) { | |
this.gameState = GameState.Draw; | |
return; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ICell, IRow, State} from './matrix.service'; | |
export function easyStrategy(rows: IRow[], targetState: State): void { | |
let candidates: ICell[] = [], xRef: {[id: number]: ICell} = {}; | |
for (let x = 0; x < rows.length; x += 1) { | |
let row = rows[x]; | |
for (let y = 0; y < row.length; y += 1) { | |
let cell = row[y], id = cell.row * 3 + cell.col; | |
if (cell.state === State.None && xRef[id] === undefined) { | |
candidates.push(cell); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public stateChange(cell: ICell) { | |
cell.state = this.matrix.gameState === GameState.XTurn ? State.X : State.O; | |
this.matrix.advanceBoardState(); | |
this.updateStats(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div *ngFor="let row of rows"> | |
<cell *ngFor="let col of row" [row]="col.row" | |
[col]="col.col" | |
[cellState]="col.state" | |
[validTurn]="yourTurn" | |
[winningCell]="col.winningCell" | |
(stateChangeRequested)="stateChange(col)"></cell> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Directions } from './directions'; | |
import { Thing } from './thing'; | |
export class Room { | |
public directions: Room[] = [null, null, null, null]; | |
public walls: Directions[] = []; | |
public name: string = ''; | |
public description: string = ''; | |
public idx: number = -1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Room } from './room'; | |
import { Thing } from './thing'; | |
export class Dungeon { | |
rooms: Room[] = []; | |
inventory: Thing[] = []; | |
trophyCount: number = 0; | |
currentRoomIdx: number = -1; | |
public get currentRoom(): Room { | |
if (this.currentRoomIdx < 0 || this.currentRoomIdx >= this.rooms.length) { |