This file contains hidden or 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 interface IInventoryAction extends IAction { | |
| type: string; | |
| item: Thing; | |
| room: Room; | |
| } |
This file contains hidden or 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
| 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) { |
This file contains hidden or 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 { 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)]; |
This file contains hidden or 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
| "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; |
This file contains hidden or 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 { 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; |
This file contains hidden or 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 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()); |
This file contains hidden or 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
| <h1> | |
| {{title}} | |
| </h1> | |
| <console [list]="dungeon.console"></console> | |
| <parser *ngIf="!dungeon.won" | |
| (action)="handleAction($event)"></parser> | |
| <map [rooms]="dungeon.rooms" | |
| [currentRoom]="dungeon.currentRoom"></map> |
This file contains hidden or 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 { 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 { |
This file contains hidden or 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
| 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 = { |
This file contains hidden or 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 ParserComponent { | |
| @Output('action') | |
| public action: EventEmitter<string> = new EventEmitter<string>(); | |
| public text: string = ''; | |
| constructor() { } | |
| public parseInput($event: any) { |