<repo_name>Ochkalov/squest<file_sep>/js/data/quest.js
export const initialGame = {
  level: 0,
  lives: 3,
  time:0  
};

export const setLives = (game, lives) => {
    if ( lives < 0 ) {
        throw new RangeError(`Can't set negative lives`);
    } 
    game = Object.assign({}, game);
    game.lives = lives;
    return game;
};

export const getLevel = (num, quest) => quest[`level-${num}`];

export const nextLevel = (state, quest) => {
    const next = state.level + 1;
    if (!getLevel(next, quest)) {
        throw new RangeError(`Can't find level ${next}`);
    }
    state = Object.assign({}, state);
    state.level = next;
    return state;
};

const LEFT = `LEFT`;
const RIGHT = `RIGHT`;
const JUMP = `JUMP`;
const ONE = `1`;
const TWO = `2`;
const THREE = `3`;
const FOUR = `4`;

export const Action = {
    LEFT, RIGHT, JUMP, ONE, TWO, THREE, FOUR
};

export const Result = {
    DIE: `die`,
    NOOP: `noop`,
    NEXT: `next`,
    WIN: `win`
};<file_sep>/js/welcome/welcome.js
import {changeView} from '../util';
import WelcomeView from './welcome-view';
import App from '../main';


export default class Welcome {
    constructor() {
        this.view = new WelcomeView();
    }

    init() {
        App.showWelcome();
        changeView(this.view);

        this.view.onStart = () => {
            App.showGame();
        };
    }
}<file_sep>/js/main.js
import {changeView} from './util';
import Game from './game/game';
import Model from './model';
import questAdapter from './data/quest-adapter';
import SplashScreen from './splash-screen/splash-screen';
import Welcome from './welcome/welcome';


const ControllerID = {
    WELCOME: ``,
    GAME: `game`,
    WIN: `die`,
    DIE: `win`,
};


const getControllerIDFromHash = (hash) => hash.replace(`#`, ``);


class App {
    constructor() {
        const preloaderRemove = this.showPreloader();

        this.model = new class extends Model {
            get urlRead() {
                return `https://intensive-ecmascript-server-srmhvdwcks.now.sh/text-quest/quest`;
            }

            get urlWrite() {
                return `true`;
            }
        }();

        this.model.load(questAdapter)
            .then((data) => this.setup(data))
            .then(preloaderRemove)
            .then(() => this.changeController(getControllerIDFromHash(location.hash)))
            .catch(window.console.error);
    }

    setup(data) {
        this.routes = {
            [ControllerID.WELCOME]: new Welcome(),
            [ControllerID.GAME]: new Game(this.model, data)
        };

        window.onhashchange = () => {
            this.changeController(getControllerIDFromHash(location.hash));
        };
    }

    changeController(route = ``) {
        this.routes[route].init();
    }

    showPreloader() {
        const splashScreen = new SplashScreen();
        changeView(splashScreen);
        splashScreen.start();

        return () => splashScreen.hide();
    }

    showWelcome() {
        location.hash = ControllerID.WELCOME;
    }

    showGame() {
        location.hash = ControllerID.GAME;
    }
}

export default new App();
<file_sep>/Readme.md
#  Проект «Квест»
# Для запуска: npm start

