Skip to content

Instantly share code, notes, and snippets.

View JeremyLikness's full-sized avatar

Jeremy Likness JeremyLikness

View GitHub Profile
<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>
public set(): void {
if (this.cellState === State.None) {
if (this.validTurn) {
this.stateChangeRequested.emit(true);
} else {
this.cellQuote = this.badTurn.getBadTurn();
}
}
}
export class CellComponent implements OnInit, OnChanges {
ngOnChanges() {
if (Math.random() < 0.5) {
this.cellQuote = this.quoteService.getQuote();
}
}
}
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;
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;
}
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);
public stateChange(cell: ICell) {
cell.state = this.matrix.gameState === GameState.XTurn ? State.X : State.O;
this.matrix.advanceBoardState();
this.updateStats();
}
<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>
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;
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) {