Exemple #1
0
import React from "react";
import BEM from "utils/BEM";

import {MazeStore, MazeActions} from "storage/MazeStore";

var b = BEM.b("maze");

class Maze extends React.Component {
  constructor (pref) {
    super();
    this.state = {
      maze: MazeStore.getMaze(),
      algorithmState : MazeStore.getAlgorithmState()
    };
  }

  onMazeChange () {
    this.setState({
      maze: MazeStore.getMaze(),
      algorithmState : MazeStore.getAlgorithmState()
    });
  }

  componentDidMount () {
    this.unsubscribe = [
      MazeStore.listen(this.onMazeChange.bind(this))
    ]
  }

  componentWillUnmount () {
    this.unsubscribe.map((fn)=> fn());
import {getRandom, isObjInArray} from "utils/utils";
import BEM from "utils/BEM";

var b = BEM.b("magic-hat");
b("cell");

const ELEMENTS_RANGE = {from: 1, to: 4};
const CELLS_IN_LINE = 11;
const GAME_SPEED = 15000;

class MagicHat {
    constructor (container) {
        this.container = container;
        this.model = [
            [3, 1, 2, 2, 2, 1, 1, 1, 2, 2, 3],
            [1, 3, 1, 4, 1, 4, 2, 2, 1, 1, 3],
            [2, 1, 2, 2, 4, 2, 1, 1, 1, 2, 1],
            [1, 3, 4, 2, 2, 3, 3, 4, 1, 3, 1],
            [2, 4, 2, 1, 1, 2, 4, 2, 2, 3, 3],
            [2, 2, 3, 1, 1, 1, 1, 3, 2, 1, 1],
            [4, 1, 2, 1, 2, 3, 1, 1, 3, 1, 4],
            [3, 4, 3, 3, 4, 1, 2, 2, 2, 1, 2],
            [2, 3, 3, 3, 1, 2, 3, 3, 2, 3, 2],
            [2, 4, 1, 1, 2, 4, 3, 3, 1, 4, 4],
            [4, 2, 3, 1, 1, 4, 4, 3, 4, 1, 2]
        ];

        this.activeCells = this.getCellSiblingsAvalanche({x:9, y:2});
        this.hoveredCellEl;

        container.addEventListener("mousemove", this.handleHiglight.bind(this), false);
Exemple #3
0
import BEM from "utils/BEM";
import React from "react";
import Statistics from "Statistics";
import SnakeActions from "Actions/SnakeActions";
var b = BEM.b("snake");

class Snake extends React.Component {
    constructor () {
        //this.container = container;
        this.state = {
            field : [
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, 0, 0],
                [0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, 0, 0],
                [0, 0, 0, 0, 2, 0, 2, 0, 2, 0, 2, 2, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            ],
            snake : [
                {x:6, y:0},
                {x:5, y:0},
                {x:4, y:0},