Skip to content

Instantly share code, notes, and snippets.

View JeremyLikness's full-sized avatar

Jeremy Likness JeremyLikness

View GitHub Profile
export interface IInventoryAction extends IAction {
type: string;
item: Thing;
room: Room;
}
const checkGet: (dungeon: Dungeon) => IAction = (dungeon: Dungeon) => {
if (dungeon.currentRoom.things.length < 1) {
return {
type: ACTION_TEXT,
text: 'You get down.'
} as ITextAction;
}
let invCount = dungeon.inventory.length + 1;
if (dungeon.trophyCount === invCount) {
import { Thing } from '../world/thing';
import { IAction, IInventoryAction } from '../actions/createAction';
import { ACTION_GET } from '../actions/ActionList';
export const things = (state: Thing[] = [], action: IAction) => {
if (action.type === ACTION_GET) {
let inventoryAction = action as IInventoryAction;
let idx = state.indexOf(inventoryAction.item);
return [...state.slice(0, idx), ...state.slice(idx+1)];
"use strict";
var ActionList_1 = require('../actions/ActionList');
exports.things = function (state, action) {
if (state === void 0) { state = []; }
if (action.type === ActionList_1.ACTION_GET) {
var inventoryAction = action;
var idx = state.indexOf(inventoryAction.item);
return state.slice(0, idx).concat(state.slice(idx + 1));
}
return state;
import { Thing } from '../world/thing';
import { things } from './reducer.things';
import { Room } from '../world/room';
import { IAction, IInventoryAction, IRoomAction } from '../actions/createAction';
import { ACTION_GET, ACTION_MOVE } from '../actions/ActionList';
export const room = (state: Room = new Room(), action: IAction) => {
let room = new Room();
room.idx = state.idx;
export class ReduxAdventureAppComponent {
private _store: Store<Dungeon>;
public dungeon: Dungeon;
constructor() {
this._store = createStore(mainReducer);
this.dungeon = this._store.getState();
this._store.subscribe(() => this.dungeon = this._store.getState());
<h1>
{{title}}
</h1>
<console [list]="dungeon.console"></console>
<parser *ngIf="!dungeon.won"
(action)="handleAction($event)"></parser>
<map [rooms]="dungeon.rooms"
[currentRoom]="dungeon.currentRoom"></map>
import { Component, Input, ElementRef, OnChanges, ViewChild } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'console',
templateUrl: 'console.component.html',
styleUrls: ['console.component.css']
})
export class ConsoleComponent implements OnChanges {
describe('Component: Console', () => {
it('should create an instance', () => {
let component = new ConsoleComponent();
expect(component).toBeTruthy();
});
it('should set the scrollTop to the scrollHeight on changes', (done) => {
let component = new ConsoleComponent();
let div = {
export class ParserComponent {
@Output('action')
public action: EventEmitter<string> = new EventEmitter<string>();
public text: string = '';
constructor() { }
public parseInput($event: any) {